diff options
25 files changed, 707 insertions, 76 deletions
diff --git a/Data/Resources/Font/default_font.ttf b/Data/Resources/Font/default_font.ttf Binary files differnew file mode 100644 index 0000000..06aafc0 --- /dev/null +++ b/Data/Resources/Font/default_font.ttf diff --git a/Data/Resources/Font/latin.txt b/Data/Resources/Font/latin.txt new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Data/Resources/Font/latin.txt diff --git a/Data/Resources/Font/zh3500.txt b/Data/Resources/Font/zh3500.txt new file mode 100644 index 0000000..154917c --- /dev/null +++ b/Data/Resources/Font/zh3500.txt @@ -0,0 +1 @@ +啊阿埃挨哎唉哀皑癌蔼矮艾碍爱隘鞍氨安俺按暗岸胺案肮昂盎凹敖熬翱袄傲奥懊澳芭捌扒叭吧笆八疤巴拔跋靶把耙坝霸罢爸白柏百摆佰败拜稗斑班搬扳般颁板版扮拌伴瓣半办绊邦帮梆榜膀绑棒磅蚌镑傍谤苞胞包褒剥薄雹保堡饱宝抱报暴豹鲍爆杯碑悲卑北辈背贝钡倍狈备惫焙被奔苯本笨崩绷甭泵蹦迸逼鼻比鄙笔彼碧蓖蔽毕毙毖币庇痹闭敝弊必辟壁臂避陛鞭边编贬扁便变卞辨辩辫遍标彪膘表鳖憋别瘪彬斌濒滨宾摈兵冰柄丙秉饼炳病并玻菠播拨钵波博勃搏铂箔伯帛舶脖膊渤泊驳捕卜哺补埠不布步簿部怖擦猜裁材才财睬踩采彩菜蔡餐参蚕残惭惨灿苍舱仓沧藏操糙槽曹草厕策侧册测层蹭插叉茬茶查碴搽察岔差诧拆柴豺搀掺蝉馋谗缠铲产阐颤昌猖场尝常长偿肠厂敞畅唱倡超抄钞朝嘲潮巢吵炒车扯撤掣彻澈郴臣辰尘晨忱沉陈趁衬撑称城橙成呈乘程惩澄诚承逞骋秤吃痴持匙池迟弛驰耻齿侈尺赤翅斥炽充冲虫崇宠抽酬畴踌稠愁筹仇绸瞅丑臭初出橱厨躇锄雏滁除楚础储矗搐触处揣川穿椽传船喘串疮窗幢床闯创吹炊捶锤垂春椿醇唇淳纯蠢戳绰疵茨磁雌辞慈瓷词此刺赐次聪葱囱匆从丛凑粗醋簇促蹿篡窜摧崔催脆瘁粹淬翠村存寸磋撮搓措挫错搭达答瘩打大呆歹傣戴带殆代贷袋待逮怠耽担丹单郸掸胆旦氮但惮淡诞弹蛋当挡党荡档刀捣蹈倒岛祷导到稻悼道盗德得的蹬灯登等瞪凳邓堤低滴迪敌笛狄涤翟嫡抵底地蒂第帝弟递缔颠掂滇碘点典靛垫电佃甸店惦奠淀殿碉叼雕凋刁掉吊钓调跌爹碟蝶迭谍叠丁盯叮钉顶鼎锭定订丢东冬董懂动栋侗恫冻洞兜抖斗陡豆逗痘都督毒犊独读堵睹赌杜镀肚度渡妒端短锻段断缎堆兑队对墩吨蹲敦顿囤钝盾遁掇哆多夺垛躲朵跺舵剁惰堕蛾峨鹅俄额讹娥恶厄扼遏鄂饿恩而儿耳尔饵洱二贰发罚筏伐乏阀法珐藩帆番翻樊矾钒繁凡烦反返范贩犯饭泛坊芳方肪房防妨仿访纺放菲非啡飞肥匪诽吠肺废沸费芬酚吩氛分纷坟焚汾粉奋份忿愤粪丰封枫蜂峰锋风疯烽逢冯缝讽奉凤佛否夫敷肤孵扶拂辐幅氟符伏俘服浮涪福袱弗甫抚辅俯釜斧脯腑府腐赴副覆赋复傅付阜父腹负富讣附妇缚咐噶嘎该改概钙盖溉干甘杆柑竿肝赶感秆敢赣冈刚钢缸肛纲岗港杠篙皋高膏羔糕搞镐稿告哥歌搁戈鸽胳疙割革葛格蛤阁隔铬个各给根跟耕更庚羹埂耿梗工攻功恭龚供躬公宫弓巩汞拱贡共钩勾沟苟狗垢构购够辜菇咕箍估沽孤姑鼓古蛊骨谷股故顾固雇刮瓜剐寡挂褂乖拐怪棺关官冠观管馆罐惯灌贯光广逛瑰规圭硅归龟闺轨鬼诡癸桂柜跪贵刽辊滚棍锅郭国果裹过哈骸孩海氦亥害骇酣憨邯韩含涵寒函喊罕翰撼捍旱憾悍焊汗汉夯杭航壕嚎豪毫郝好耗号浩呵喝荷菏核禾和何合盒貉阂河涸赫褐鹤贺嘿黑痕很狠恨哼亨横衡恒轰哄烘虹鸿洪宏弘红喉侯猴吼厚候后呼乎忽瑚壶葫胡蝴狐糊湖弧虎唬护互沪户花哗华猾滑画划化话槐徊怀淮坏欢环桓还缓换患唤痪豢焕涣宦幻荒慌黄磺蝗簧皇凰惶煌晃幌恍谎灰挥辉徽恢蛔回毁悔慧卉惠晦贿秽会烩汇讳诲绘荤昏婚魂浑混豁活伙火获或惑霍货祸击圾基机畸稽积箕肌饥迹激讥鸡姬绩缉吉极棘辑籍集及急疾汲即嫉级挤几脊己蓟技冀季伎祭剂悸济寄寂计记既忌际妓继纪嘉枷夹佳家加荚颊贾甲钾假稼价架驾嫁歼监坚尖笺间煎兼肩艰奸缄茧检柬碱碱拣捡简俭剪减荐槛鉴践贱见键箭件健舰剑饯渐溅涧建僵姜将浆江疆蒋桨奖讲匠酱降蕉椒礁焦胶交郊浇骄娇嚼搅铰矫侥脚狡角饺缴绞剿教酵轿较叫窖揭接皆秸街阶截劫节桔杰捷睫竭洁结解姐戒藉芥界借介疥诫届巾筋斤金今津襟紧锦仅谨进靳晋禁近烬浸尽劲荆兢茎睛晶鲸京惊精粳经井警景颈静境敬镜径痉靖竟竞净炯窘揪究纠玖韭久灸九酒厩救旧臼舅咎就疚鞠拘狙疽居驹菊局咀矩举沮聚拒据巨具距踞锯俱句惧炬剧捐鹃娟倦眷卷绢撅攫抉掘倔爵觉决诀绝均菌钧军君峻俊竣浚郡骏喀咖卡咯开揩楷凯慨刊堪勘坎砍看康慷糠扛抗亢炕考拷烤靠坷苛柯棵磕颗科壳咳可渴克刻客课肯啃垦恳坑吭空恐孔控抠口扣寇枯哭窟苦酷库裤夸垮挎跨胯块筷侩快宽款匡筐狂框矿眶旷况亏盔岿窥葵奎魁傀馈愧溃坤昆捆困括扩廓阔垃拉喇蜡腊辣啦莱来赖蓝婪栏拦篮阑兰澜谰揽览懒缆烂滥琅榔狼廊郎朗浪捞劳牢老佬姥酪烙涝勒乐雷镭蕾磊累儡垒擂肋类泪棱楞冷厘梨犁黎篱狸离漓理李里鲤礼莉荔吏栗丽厉励砾历利僳例俐痢立粒沥隶力璃哩俩联莲连镰廉怜涟帘敛脸链恋炼练粮凉梁粱良两辆量晾亮谅撩聊僚疗燎寥辽潦了撂镣廖料列裂烈劣猎琳林磷霖临邻鳞淋凛赁吝拎玲菱零龄铃伶羚凌灵陵岭领另令溜琉榴硫馏留刘瘤流柳六龙聋咙笼窿隆垄拢陇楼娄搂篓漏陋芦卢颅庐炉掳卤虏鲁麓碌露路赂鹿潞禄录陆戮驴吕铝侣旅履屡缕虑氯律率滤绿峦挛孪滦卵乱掠略抡轮伦仑沦纶论萝螺罗逻锣箩骡裸落洛骆络妈麻玛码蚂马骂嘛吗埋买麦卖迈脉瞒馒蛮满蔓曼慢漫谩芒茫盲氓忙莽猫茅锚毛矛铆卯茂冒帽貌贸么玫枚梅酶霉煤没眉媒镁每美昧寐妹媚门闷们萌蒙檬盟锰猛梦孟眯醚靡糜迷谜弥米秘觅泌蜜密幂棉眠绵冕免勉娩缅面苗描瞄藐秒渺庙妙蔑灭民抿皿敏悯闽明螟鸣铭名命谬摸摹蘑模膜磨摩魔抹末莫墨默沫漠寞陌谋牟某拇牡亩姆母墓暮幕募慕木目睦牧穆拿哪呐钠那娜纳氖乃奶耐奈南男难囊挠脑恼闹淖呢馁内嫩能妮霓倪泥尼拟你匿腻逆溺蔫拈年碾撵捻念娘酿鸟尿捏聂孽啮镊镍涅您柠狞凝宁拧泞牛扭钮纽脓浓农弄奴努怒女暖虐疟挪懦糯诺哦欧鸥殴藕呕偶沤啪趴爬帕怕琶拍排牌徘湃派攀潘盘磐盼畔判叛乓庞旁耪胖抛咆刨炮袍跑泡呸胚培裴赔陪配佩沛喷盆砰抨烹澎彭蓬棚硼篷膨朋鹏捧碰坯砒霹批披劈琵毗啤脾疲皮匹痞僻屁譬篇偏片骗飘漂瓢票撇瞥拼频贫品聘乒坪苹萍平凭瓶评屏坡泼颇婆破魄迫粕剖扑铺仆莆葡菩蒲埔朴圃普浦谱曝瀑期欺栖戚妻七凄漆柒沏其棋奇歧畦崎脐齐旗祈祁骑起岂乞企启契砌器气迄弃汽泣讫掐洽牵扦钎铅千迁签仟谦乾黔钱钳前潜遣浅谴堑嵌欠歉枪呛腔羌墙蔷强抢橇锹敲悄桥瞧乔侨巧鞘撬翘峭俏窍切茄且怯窃钦侵亲秦琴勤芹擒禽寝沁青轻氢倾卿清擎晴氰情顷请庆琼穷秋丘邱球求囚酋泅趋区蛆曲躯屈驱渠取娶龋趣去圈颧权醛泉全痊拳犬券劝缺炔瘸却鹊榷确雀裙群然燃冉染瓤壤攘嚷让饶扰绕惹热壬仁人忍韧任认刃妊纫扔仍日戎茸蓉荣融熔溶容绒冗揉柔肉茹蠕儒孺如辱乳汝入褥软阮蕊瑞锐闰润若弱撒洒萨腮鳃塞赛三叁伞散桑嗓丧搔骚扫嫂瑟色涩森僧莎砂杀刹沙纱傻啥煞筛晒珊苫杉山删煽衫闪陕擅赡膳善汕扇缮墒伤商赏晌上尚裳梢捎稍烧芍勺韶少哨邵绍奢赊蛇舌舍赦摄射慑涉社设砷申呻伸身深娠绅神沈审婶甚肾慎渗声生甥牲升绳省盛剩胜圣师失狮施湿诗尸虱十石拾时什食蚀实识史矢使屎驶始式示士世柿事拭誓逝势是嗜噬适仕侍释饰氏市恃室视试收手首守寿授售受瘦兽蔬枢梳殊抒输叔舒淑疏书赎孰熟薯暑曙署蜀黍鼠属术述树束戍竖墅庶数漱恕刷耍摔衰甩帅栓拴霜双爽谁水睡税吮瞬顺舜说硕朔烁斯撕嘶思私司丝死肆寺嗣四伺似饲巳松耸怂颂送宋讼诵搜艘擞嗽苏酥俗素速粟僳塑溯宿诉肃酸蒜算虽隋随绥髓碎岁穗遂隧祟孙损笋蓑梭唆缩琐索锁所塌他它她塔獭挞蹋踏胎苔抬台泰酞太态汰坍摊贪瘫滩坛檀痰潭谭谈坦毯袒碳探叹炭汤塘搪堂棠膛唐糖倘躺淌趟烫掏涛滔绦萄桃逃淘陶讨套特藤腾疼誊梯剔踢锑提题蹄啼体替嚏惕涕剃屉天添填田甜恬舔腆挑条迢眺跳贴铁帖厅听烃汀廷停亭庭艇通桐酮瞳同铜彤童桶捅筒统痛偷投头透凸秃突图徒途涂屠土吐兔湍团推颓腿蜕褪退吞屯臀拖托脱鸵陀驮驼椭妥拓唾挖哇蛙洼娃瓦袜歪外豌弯湾玩顽丸烷完碗挽晚皖惋宛婉万腕汪王亡枉网往旺望忘妄威巍微危韦违桅围唯惟为潍维苇萎委伟伪尾纬未蔚味畏胃喂魏位渭谓尉慰卫瘟温蚊文闻纹吻稳紊问嗡翁瓮挝蜗涡窝我斡卧握沃巫呜钨乌污诬屋无芜梧吾吴毋武五捂午舞伍侮坞戊雾晤物勿务悟误昔熙析西硒矽晰嘻吸锡牺稀息希悉膝夕惜熄烯溪汐犀檄袭席习媳喜铣洗系隙戏细瞎虾匣霞辖暇峡侠狭下厦夏吓掀锨先仙鲜纤咸贤衔舷闲涎弦嫌显险现献县腺馅羡宪陷限线相厢镶香箱襄湘乡翔祥详想响享项巷橡像向象萧硝霄削哮嚣销消宵淆晓小孝校肖啸笑效楔些歇蝎鞋协挟携邪斜胁谐写械卸蟹懈泄泻谢屑薪芯锌欣辛新忻心信衅星腥猩惺兴刑型形邢行醒幸杏性姓兄凶胸匈汹雄熊休修羞朽嗅锈秀袖绣墟戌需虚嘘须徐许蓄酗叙旭序畜恤絮婿绪续轩喧宣悬旋玄选癣眩绚靴薛学穴雪血勋熏循旬询寻驯巡殉汛训讯逊迅压押鸦鸭呀丫芽牙蚜崖衙涯雅哑亚讶焉咽阉烟淹盐严研蜒岩延言颜阎炎沿奄掩眼衍演艳堰燕厌砚雁唁彦焰宴谚验殃央鸯秧杨扬佯疡羊洋阳氧仰痒养样漾邀腰妖瑶摇尧遥窑谣姚咬舀药要耀椰噎耶爷野冶也页掖业叶曳腋夜液一壹医揖铱依伊衣颐夷遗移仪胰疑沂宜姨彝椅蚁倚已乙矣以艺抑易邑屹亿役臆逸肄疫亦裔意毅忆义益溢诣议谊译异翼翌绎茵荫因殷音阴姻吟银淫寅饮尹引隐印英樱婴鹰应缨莹萤营荧蝇迎赢盈影颖硬映哟拥佣臃痈庸雍踊蛹咏泳涌永恿勇用幽优悠忧尤由邮铀犹油游酉有友右佑釉诱又幼迂淤于盂榆虞愚舆余俞逾鱼愉渝渔隅予娱雨与屿禹宇语羽玉域芋郁吁遇喻峪御愈欲狱育誉浴寓裕预豫驭鸳渊冤元垣袁原援辕园员圆猿源缘远苑愿怨院曰约越跃钥岳粤月悦阅耘云郧匀陨允运蕴酝晕韵孕匝砸杂栽哉灾宰载再在咱攒暂赞赃脏葬遭糟凿藻枣早澡蚤躁噪造皂灶燥责择则泽贼怎增憎曾赠扎喳渣札轧铡闸眨栅榨咋乍炸诈摘斋宅窄债寨瞻毡詹粘沾盏斩辗崭展蘸栈占战站湛绽樟章彰漳张掌涨杖丈帐账仗胀瘴障招昭找沼赵照罩兆肇召遮折哲蛰辙者锗蔗这浙珍斟真甄砧臻贞针侦枕疹诊震振镇阵蒸挣睁征狰争怔整拯正政帧症郑证芝枝支吱蜘知肢脂汁之织职直植殖执值侄址指止趾只旨纸志挚掷至致置帜峙制智秩稚质炙痔滞治窒中盅忠钟衷终种肿重仲众舟周州洲诌粥轴肘帚咒皱宙昼骤珠株蛛朱猪诸诛逐竹烛煮拄瞩嘱主著柱助蛀贮铸筑住注祝驻抓爪拽专砖转撰赚篆桩庄装妆撞壮状椎锥追赘坠缀谆准捉拙卓桌琢茁酌啄着灼浊兹咨资姿滋淄孜紫仔籽滓子自渍字鬃棕踪宗综总纵邹走奏揍租足卒族祖诅阻组钻纂嘴醉最罪尊遵昨左佐柞做作坐座
\ No newline at end of file diff --git a/Data/Scripts/EditorApplication.lua b/Data/Scripts/EditorApplication.lua index 00b72b5..eb3c7d8 100644 --- a/Data/Scripts/EditorApplication.lua +++ b/Data/Scripts/EditorApplication.lua @@ -113,8 +113,12 @@ local fsh = [[ BeforeMainLoop() -_G["default_font"] = - +local font = Engine.GUI.Font.New("./Resources/Font/deng.ttf", {256, 256}, 5, 5) +_G["default_font"] = font +font:GetCharacters([[ +UTF-8是Unicode的一种实现,是一种变长字节编码方式。对于某一个字符的UTF-8编码,如果只有一个字节则其最高二进制位为0;如果是多字节,其第一个字节从最高位开始,连续的二进制位值为1的个数决定了其编码的位数,其余各字节均以10开头。UTF-8最多可用到6个字节。 +]], 12) + while true do app:OnStep() diff --git a/Documents/编码.xlsx b/Documents/编码.xlsx Binary files differnew file mode 100644 index 0000000..c8cf6e0 --- /dev/null +++ b/Documents/编码.xlsx diff --git a/Editor/EditorMain.cpp b/Editor/EditorMain.cpp index a74a0b2..3c6b893 100644 --- a/Editor/EditorMain.cpp +++ b/Editor/EditorMain.cpp @@ -20,14 +20,6 @@ void ErrorHandle(cc8* msg) void TestFont()
{
- //TextGeneratingSettings setting;
- //setting.margin = 5;
- //setting.padding = 5;
- //setting.atlasSize = Internal::Vector2(512, 512);
-
- //Font::Instance()->Setup(setting);
- //auto content = L"abcdfӼ Ӽ: ֻǼļ㹤,Щ;߱㹦,Щ;߱һ湦,һֻܴ洢ݡ߱Ӵܡƹ,";
- // Font::Instance()->RenderCharacters((character::Codepoint*)content, wcslen(content), 14);
}
int BeforeMainLoop(lua_State* L)
diff --git a/Projects/VisualStudio/Editor/Editor.vcxproj b/Projects/VisualStudio/Editor/Editor.vcxproj index 8e3b015..54aba66 100644 --- a/Projects/VisualStudio/Editor/Editor.vcxproj +++ b/Projects/VisualStudio/Editor/Editor.vcxproj @@ -200,6 +200,9 @@ <ClCompile Include="..\..\..\Runtime\Graphics\VertexAttribute.cpp" />
<ClCompile Include="..\..\..\Runtime\Graphics\VertexBuffer.cpp" />
<ClCompile Include="..\..\..\Runtime\GUI\Font.cpp" />
+ <ClCompile Include="..\..\..\Runtime\GUI\TextMesh.cpp" />
+ <ClCompile Include="..\..\..\Runtime\GUI\TextMeshGenerator.cpp" />
+ <ClCompile Include="..\..\..\Runtime\GUI\utf8.cpp" />
<ClCompile Include="..\..\..\Runtime\Lua\LuaBind\LuaBindCFunctions.cpp" />
<ClCompile Include="..\..\..\Runtime\Lua\LuaBind\LuaBindClass.cpp" />
<ClCompile Include="..\..\..\Runtime\Lua\LuaBind\LuaBindEnum.cpp" />
@@ -287,6 +290,9 @@ <ClInclude Include="..\..\..\Runtime\Graphics\VertexBuffer.h" />
<ClInclude Include="..\..\..\Runtime\GUI\freetype.h" />
<ClInclude Include="..\..\..\Runtime\GUI\Font.h" />
+ <ClInclude Include="..\..\..\Runtime\GUI\TextMesh.h" />
+ <ClInclude Include="..\..\..\Runtime\GUI\TextMeshGenerator.h" />
+ <ClInclude Include="..\..\..\Runtime\GUI\utf8.h" />
<ClInclude Include="..\..\..\Runtime\Lua\LuaBind\LuaBind.h" />
<ClInclude Include="..\..\..\Runtime\Lua\LuaBind\LuaBindCFunctions.h" />
<ClInclude Include="..\..\..\Runtime\Lua\LuaBind\LuaBindClass.hpp" />
@@ -330,7 +336,7 @@ <ClInclude Include="..\..\..\Runtime\Utilities\Callback.h" />
<ClInclude Include="..\..\..\Runtime\Utilities\DynamicArray.h" />
<ClInclude Include="..\..\..\Runtime\Utilities\Exception.h" />
- <ClInclude Include="..\..\..\Runtime\Utilities\IncrementalTask.h" />
+ <ClInclude Include="..\..\..\Runtime\Utilities\IIncrementalTask.h" />
<ClInclude Include="..\..\..\Runtime\Utilities\NonCopyable.h" />
<ClInclude Include="..\..\..\Runtime\Utilities\Singleton.h" />
<ClInclude Include="..\..\..\Runtime\Utilities\StaticInitiator.h" />
diff --git a/Projects/VisualStudio/Editor/Editor.vcxproj.filters b/Projects/VisualStudio/Editor/Editor.vcxproj.filters index 4963b95..90f759a 100644 --- a/Projects/VisualStudio/Editor/Editor.vcxproj.filters +++ b/Projects/VisualStudio/Editor/Editor.vcxproj.filters @@ -402,6 +402,15 @@ <ClCompile Include="..\..\..\Runtime\Scripting\GUI\GUI.bind.cpp">
<Filter>Runtime\Scripting\GUI</Filter>
</ClCompile>
+ <ClCompile Include="..\..\..\Runtime\GUI\utf8.cpp">
+ <Filter>Runtime\GUI</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\Runtime\GUI\TextMesh.cpp">
+ <Filter>Runtime\GUI</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\Runtime\GUI\TextMeshGenerator.cpp">
+ <Filter>Runtime\GUI</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\..\Editor\GUI\Dock.h">
@@ -656,9 +665,6 @@ <ClInclude Include="..\..\..\Runtime\Math\Vector4.h">
<Filter>Runtime\Math</Filter>
</ClInclude>
- <ClInclude Include="..\..\..\Runtime\Utilities\IncrementalTask.h">
- <Filter>Runtime\Utilities</Filter>
- </ClInclude>
<ClInclude Include="..\..\..\Runtime\Utilities\Callback.h">
<Filter>Runtime\Utilities</Filter>
</ClInclude>
@@ -692,6 +698,18 @@ <ClInclude Include="..\..\..\Runtime\GUI\Font.h">
<Filter>Runtime\GUI</Filter>
</ClInclude>
+ <ClInclude Include="..\..\..\Runtime\GUI\utf8.h">
+ <Filter>Runtime\GUI</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\..\Runtime\GUI\TextMesh.h">
+ <Filter>Runtime\GUI</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\..\Runtime\GUI\TextMeshGenerator.h">
+ <Filter>Runtime\GUI</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\..\Runtime\Utilities\IIncrementalTask.h">
+ <Filter>Runtime\Utilities</Filter>
+ </ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="..\..\..\Runtime\Lua\LuaBind\LuaBindClass.inc">
diff --git a/Runtime/GUI/Font.cpp b/Runtime/GUI/Font.cpp index 67a2e3b..e5444f1 100644 --- a/Runtime/GUI/Font.cpp +++ b/Runtime/GUI/Font.cpp @@ -75,7 +75,7 @@ Font::Font(DataBuffer* db, TextGeneratingSettings settings) } } -Font::Font(DataBuffer* db, LuaBind::VM* vm, std::string path, TextGeneratingSettings settings) +Font::Font(LuaBind::VM* vm, DataBuffer* db, TextGeneratingSettings settings) : LuaBind::NativeClass<Font>(vm) { m_AtlasMargin = settings.margin; @@ -124,6 +124,15 @@ void Font::RenderCharacters(character::Codepoint* codepoint, int n, int pixelSiz } } +void Font::RenderCharacters(std::vector<character::Codepoint>& codepoint, int pixelSize) +{ + int n = codepoint.size(); + for (int i = 0; i < n; ++i) + { + RenderCharacter(codepoint[i], pixelSize); + } +} + void Font::RenderCharacter(character::Codepoint codepoint, int pixelSize) { character::Hash hash = GetHash(codepoint, pixelSize); diff --git a/Runtime/GUI/Font.h b/Runtime/GUI/Font.h index 242bd19..344cc00 100644 --- a/Runtime/GUI/Font.h +++ b/Runtime/GUI/Font.h @@ -5,24 +5,29 @@ #include "freetype.h" #include "Runtime/Lua/LuaHelper.h" #include "Runtime/Common/DataBuffer.h" +#include "Runtime/Math/Math.h" #include <string> #include <unordered_map> #include <exception> #include <vector> -//https://learnopengl.com/In-Practice/Text-Rendering +//https://github.com/kaienfr/Font struct Character { unsigned int atlas; // atlas - Internal::Rect position; // altasλ - Internal::Vector2 bearing; // Ͻԭƫ + Rect position; // altasλ + Vector2 bearing; // Ͻԭƫ unsigned int advance; // ܿ˼ }; namespace character { +#if GAMELAB_WIN typedef unsigned short Codepoint; // unicode CodepointBMPU+0000U+FFFF) +#else + typedef unsigned int Codepoint; // unicode CodepointBMPU+0000U+FFFF) +#endif union Hash { unsigned int hashCode; @@ -55,13 +60,13 @@ struct GlyphAtals Texture* altas; // ͼ int width, height; // ߴ - Internal::Vector2 cursor; // α꣬Ͻǣ0,0ʼ + Vector2 cursor; // α꣬Ͻǣ0,0ʼ int rowHeight; // ǰеĸ߶ }; struct TextGeneratingSettings { - Internal::Vector2 atlasSize; // atlasijߴ + Vector2 atlasSize; // atlasijߴ int margin; // atlası߽ int padding; // glyph֮ļֹ࣬ʱԽ }; @@ -89,20 +94,21 @@ public: Font(std::string path, TextGeneratingSettings setting)/*throw FontException*/; Font(LuaBind::VM* vm, std::string path, TextGeneratingSettings setting)/*throw FontException*/; Font(DataBuffer* db, TextGeneratingSettings setting)/*throw FontException*/; - Font(DataBuffer* db, LuaBind::VM* vm, std::string path, TextGeneratingSettings setting)/*throw FontException*/; + Font(LuaBind::VM* vm, DataBuffer* db, TextGeneratingSettings setting)/*throw FontException*/; const Character* GetCharacter(character::Codepoint codepoint, int pixelSize); const GlyphAtals* GetGlyphAtlas(int index); // pre-bake void RenderCharacter(character::Codepoint codepoint, int pixelSize); - void RenderCharacters(character::Codepoint* codepoint, int n, int pixelSize); + void RenderCharacters(character::Codepoint* codepoint, int n, int pixelSize); + void RenderCharacters(std::vector<character::Codepoint>& codepoint, int pixelSize); private: Texture* CreateAtlas(); - GlyphAtals* RequestAtlas(int pixelSize, Internal::Vector2 preferSize); - Internal::Rect GetRenderChartAndMove(GlyphAtals* atlas, Internal::Vector2 preferSize); - bool HasEnoughSpace(GlyphAtals* atlas, Internal::Vector2 preferSize); + GlyphAtals* RequestAtlas(int pixelSize, Vector2 preferSize); + Rect GetRenderChartAndMove(GlyphAtals* atlas, Vector2 preferSize); + bool HasEnoughSpace(GlyphAtals* atlas, Vector2 preferSize); character::Hash GetHash(character::Codepoint Codepoint, int pixelSize); //------------------------------------------------------------------------- @@ -114,9 +120,9 @@ private: bool m_IsEnabled; - Internal::Vector2 m_AtlasSize; - int m_AtlasMargin; - int m_GlyphPadding; + Vector2 m_AtlasSize; + int m_AtlasMargin; + int m_GlyphPadding; FT_Library m_FTLibrary; FT_Face m_FTFace; @@ -132,8 +138,6 @@ private: }; -//#define g_TextGenerator (*Font::Instance()) - namespace TextHelper { diff --git a/Runtime/GUI/TextMesh.cpp b/Runtime/GUI/TextMesh.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Runtime/GUI/TextMesh.cpp diff --git a/Runtime/GUI/TextMesh.h b/Runtime/GUI/TextMesh.h new file mode 100644 index 0000000..7f37e5e --- /dev/null +++ b/Runtime/GUI/TextMesh.h @@ -0,0 +1,24 @@ +#pragma once
+
+enum ETextAnchor
+{
+ TextAnchor_UpperLeft, + TextAnchor_UpperCenter, + TextAnchor_UpperRight, + TextAnchor_MiddleLeft, + TextAnchor_MiddleCenter, + TextAnchor_MiddleRight, + TextAnchor_LowerLeft, + TextAnchor_LowerCenter, + TextAnchor_LowerRight, + TextAnchor_DontCare
+};
+
+enum ETextAlignment { + TextAlignment_Left, + TextAlignment_Center, + TextAlignment_Right, + TextAlignment_Auto, +}; + + diff --git a/Runtime/GUI/TextMeshGenerator.cpp b/Runtime/GUI/TextMeshGenerator.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Runtime/GUI/TextMeshGenerator.cpp diff --git a/Runtime/GUI/TextMeshGenerator.h b/Runtime/GUI/TextMeshGenerator.h new file mode 100644 index 0000000..c5992bd --- /dev/null +++ b/Runtime/GUI/TextMeshGenerator.h @@ -0,0 +1,20 @@ +#pragma once
+
+#include "Runtime/Utilities/IIncrementalTask.h"
+
+// ճûбʹõtext mesh
+class GraduallyReleaseTextMesh : public IIncrementalTask
+{
+public:
+ void Execute() override
+ {
+
+ }
+
+ bool IsDone() override
+ {
+
+ }
+
+};
+
diff --git a/Runtime/GUI/utf8.cpp b/Runtime/GUI/utf8.cpp new file mode 100644 index 0000000..8a3a086 --- /dev/null +++ b/Runtime/GUI/utf8.cpp @@ -0,0 +1,415 @@ +/* + * Description: UTF-8 字符串的解码和编码函数 + * unicode 字符处理函数 + * History: yang@haipo.me, 2013/05/29, create + * + * This code is in the public domain. + * You may use this code any way you wish, private, educational, + * or commercial. It's free. + */ + +# include <stdint.h> +# include <stddef.h> + +# include "utf8.h" + +namespace utf8 +{ + + ucs4_t getu8c(char **src, int *illegal) + { + static char umap[256] = { 0 }; + static int umap_init_flag = 0; + + if (umap_init_flag == 0) + { + int i; + + for (i = 0; i < 0x100; ++i) + { + if (i < 0x80) + { + umap[i] = 1; + } + else if (i >= 0xc0 && i < 0xe0) + { + umap[i] = 2; + } + else if (i >= 0xe0 && i < 0xf0) + { + umap[i] = 3; + } + else if (i >= 0xf0 && i < 0xf8) + { + umap[i] = 4; + } + else if (i >= 0xf8 && i < 0xfc) + { + umap[i] = 5; + } + else if (i >= 0xfc && i < 0xfe) + { + umap[i] = 6; + } + else + { + umap[i] = 0; + } + } + + umap_init_flag = 1; + } + + uint8_t *s = (uint8_t *)(*src); + int r_illegal = 0; + + while (umap[*s] == 0) + { + ++s; + ++r_illegal; + } + + uint8_t *t; + int byte_num; + uint32_t uc; + int i; + + repeat_label: + t = s; + byte_num = umap[*s]; + uc = *s++ & (0xff >> byte_num); + + for (i = 1; i < byte_num; ++i) + { + if (umap[*s]) + { + r_illegal += s - t; + goto repeat_label; + } + else + { + uc = (uc << 6) + (*s & 0x3f); + s += 1; + } + } + + *src = (char *)s; + if (illegal) + { + *illegal = r_illegal; + } + + return uc; + } + + size_t u8decode(char const *str, ucs4_t *des, size_t n, int *illegal) + { + if (n == 0) + return 0; + + char *s = (char *)str; + size_t i = 0; + ucs4_t uc = 0; + int r_illegal_all = 0, r_illegal; + + while ((uc = getu8c(&s, &r_illegal))) + { + if (i < (n - 1)) + { + des[i++] = uc; + r_illegal_all += r_illegal; + } + else + { + break; + } + } + + des[i] = 0; + if (illegal) + { + *illegal = r_illegal_all + r_illegal; + } + + return i; + } + +# define IF_CAN_HOLD(left, n) do { \ + size_t m = (size_t)(n); \ + if ((size_t)(left) < (m + 1)) return -2; \ + (left) -= m; \ +} while (0) + + int putu8c(ucs4_t uc, char **des, size_t *left) + { + if (uc < 0) + return -1; + + if (uc < (0x1 << 7)) + { + IF_CAN_HOLD(*left, 1); + + **des = (char)uc; + *des += 1; + **des = 0; + + return 1; + } + + int byte_num; + + if (uc < (0x1 << 11)) + { + byte_num = 2; + } + else if (uc < (0x1 << 16)) + { + byte_num = 3; + } + else if (uc < (0x1 << 21)) + { + byte_num = 4; + } + else if (uc < (0x1 << 26)) + { + byte_num = 5; + } + else + { + byte_num = 6; + } + + IF_CAN_HOLD(*left, byte_num); + + int i; + for (i = byte_num - 1; i > 0; --i) + { + *(uint8_t *)(*des + i) = (uc & 0x3f) | 0x80; + uc >>= 6; + } + + *(uint8_t *)(*des) = uc | (0xff << (8 - byte_num)); + + *des += byte_num; + **des = 0; + + return byte_num; + } + + size_t u8encode(ucs4_t *us, char *des, size_t n, int *illegal) + { + if (n == 0) + return 0; + + char *s = des; + size_t left = n; + size_t len = 0; + int r_illegal = 0; + + *s = 0; + while (*us) + { + int ret = putu8c(*us, &s, &left); + if (ret > 0) + { + len += ret; + } + else if (ret == -1) + { + r_illegal += 1; + } + else + { + break; + } + + ++us; + } + + if (illegal) + { + *illegal = r_illegal; + } + + return len; + } + + /* 全角字符 */ + int isufullwidth(ucs4_t uc) + { + if (uc == 0x3000) + return 1; + + if (uc >= 0xff01 && uc <= 0xff5e) + return 1; + + return 0; + } + + /* 全角字母 */ + int isufullwidthalpha(ucs4_t uc) + { + if (uc >= 0xff21 && uc <= 0xff3a) + return 1; + + if (uc >= 0xff41 && uc <= 0xff5a) + return 2; + + return 0; + } + + /* 全角数字 */ + int isufullwidthdigit(ucs4_t uc) + { + if (uc >= 0xff10 && uc <= 0xff19) + return 1; + + return 0; + } + + /* 全角转半角 */ + ucs4_t ufull2half(ucs4_t uc) + { + if (uc == 0x3000) + return ' '; + + if (uc >= 0xff01 && uc <= 0xff5e) + return uc - 0xfee0; + + return uc; + } + + /* 半角转全角 */ + ucs4_t uhalf2full(ucs4_t uc) + { + if (uc == ' ') + return 0x3000; + + if (uc >= 0x21 && uc <= 0x7e) + return uc + 0xfee0; + + return uc; + } + + /* 中日韩越统一表意文字 */ + int isuchiness(ucs4_t uc) + { + /* 最初期统一汉字 */ + if (uc >= 0x4e00 && uc <= 0x9fcc) + return 1; + + /* 扩展 A 区 */ + if (uc >= 0x3400 && uc <= 0x4db5) + return 2; + + /* 扩展 B 区 */ + if (uc >= 0x20000 && uc <= 0x2a6d6) + return 3; + + /* 扩展 C 区 */ + if (uc >= 0x2a700 && uc <= 0x2b734) + return 4; + + /* 扩展 D 区 */ + if (uc >= 0x2b740 && uc <= 0x2b81f) + return 5; + + /* 扩展 E 区 */ + if (uc >= 0x2b820 && uc <= 0x2f7ff) + return 6; + + /* 台湾兼容汉字 */ + if (uc >= 0x2f800 && uc <= 0x2fa1d) + return 7; + + /* 北朝鲜兼容汉字 */ + if (uc >= 0xfa70 && uc <= 0xfad9) + return 8; + + /* 兼容汉字 */ + if (uc >= 0xf900 && uc <= 0xfa2d) + return 9; + + /* 兼容汉字 */ + if (uc >= 0xfa30 && uc <= 0xfa6d) + return 10; + + return 0; + } + + /* 中文标点 */ + int isuzhpunct(ucs4_t uc) + { + if (uc >= 0x3001 && uc <= 0x3002) + return 1; + + if (uc >= 0x3008 && uc <= 0x300f) + return 1; + + if (uc >= 0xff01 && uc <= 0xff0f) + return 1; + + if (uc >= 0xff1a && uc <= 0xff20) + return 1; + + if (uc >= 0xff3b && uc <= 0xff40) + return 1; + + if (uc >= 0xff5b && uc <= 0xff5e) + return 1; + + if (uc >= 0x2012 && uc <= 0x201f) + return 1; + + if (uc >= 0xfe41 && uc <= 0xfe44) + return 1; + + if (uc >= 0xfe49 && uc <= 0xfe4f) + return 1; + + if (uc >= 0x3010 && uc <= 0x3017) + return 1; + + return 0; + } + + /* 日文平假名 */ + int isuhiragana(ucs4_t uc) + { + if (uc >= 0x3040 && uc <= 0x309f) + return 1; + + return 0; + } + + /* 日文片假名 */ + int isukatakana(ucs4_t uc) + { + if (uc >= 0x30a0 && uc <= 0x30ff) + return 1; + + if (uc >= 0x31f0 && uc <= 0x31ff) + return 2; + + return 0; + } + + /* 韩文 */ + int isukorean(ucs4_t uc) + { + /* 韩文拼音 */ + if (uc >= 0xac00 && uc <= 0xd7af) + return 1; + + /* 韩文字母 */ + if (uc >= 0x1100 && uc <= 0x11ff) + return 2; + + /* 韩文兼容字母 */ + if (uc >= 0x3130 && uc <= 0x318f) + return 3; + + return 0; + } + +} diff --git a/Runtime/GUI/utf8.h b/Runtime/GUI/utf8.h new file mode 100644 index 0000000..b561b44 --- /dev/null +++ b/Runtime/GUI/utf8.h @@ -0,0 +1,113 @@ +/* + * Description: UTF-8 字符串的解码和编码函数 + * unicode 字符处理函数 + * History: yang@haipo.me, 2013/05/29, create + * + * This code is in the public domain. + * You may use this code any way you wish, private, educational, + * or commercial. It's free. + */ + +# pragma once + +# include <stdint.h> +# include <stddef.h> + +namespace utf8 +{ + + + /* + * 标准 C 并没有规定 wchar_t 的位数。但 GNU C Lib 保证 wchar_t 是 32 位的, + * 所以可以用 wchar.h 中定义的函数来像 wchar_t 一样操纵 ucs4_t. + * http://www.gnu.org/software/libc/manual/html_node/Extended-Char-Intro.html + */ + typedef int32_t ucs4_t; + + /* + * 从 UTF-8 编码的字符串 *src 中读取一个 unicode 字符,并更新 *src 的值。 + * + * 如果遇到非法 UTF-8 编码,则跳过非法部分。 + * 如果 illegal 参数不为 NULL, 则 *illegal 表示非法 UTF-8 编码字节数。 + */ + ucs4_t getu8c(char **src, int *illegal); + + /* + * 将 src 指向的 UTF-8 编码字符串解码为 unicode,放在长度为 n 的数组 des 中, + * 并在末尾添加 0. 如果 des 不足以存放所有的字符,则最多保存 n - 1 个 unicode + * 字符并补 0. + * + * 如果遇到非法 UTF-8 编码,则跳过非法部分。 + * 如果 illegal 不为 NULL, 则 *illegal 表示非法 UTF-8 编码的字节数。 + */ + size_t u8decode(char const *str, ucs4_t *des, size_t n, int *illegal); + + /* + * 将 unicode 字符 uc 编码为 UTF-8 编码,放到长度为 *left 的字符串 *des 中。 + * + * 如果 *des 不足以存放 uc 对应的 UTF-8 字符串,返回一个负值。 + * 如果成功,更新 *des 和 *left 的值。 + */ + int putu8c(ucs4_t uc, char **des, size_t *left); + + /* + * 将以 0 结尾的 unicode 数组 us 编码为 UTF-8 字符串,放到长度为 n 的字符串 des 中。 + * + * 负数为非法的 unicode 字符。 + * 如果 illegal 不为 NULL,则 *illegal 表示非法的 unicode 字符数。 + */ + size_t u8encode(ucs4_t *us, char *des, size_t n, int *illegal); + + /* + * 判断是否为全角字符 + */ + int isufullwidth(ucs4_t uc); + + /* + * 判断是否为全角字母 + */ + int isufullwidthalpha(ucs4_t uc); + + /* + * 判断是否为全角数字 + */ + int isufullwidthdigit(ucs4_t uc); + + /* + * 全角字符转半角字符。 + * 如果 uc 为全角字符,则返回对应的半角字符,否则返回 uc 本身。 + */ + ucs4_t ufull2half(ucs4_t uc); + + /* + * 半角字符转全角字符 + * 如果 uc 为半角字符,则返回对应的全角字符,否则返回 uc 本身。 + */ + ucs4_t uhalf2full(ucs4_t uc); + + /* + * 判断是否为汉字字符(中日韩越统一表意文字) + */ + int isuchiness(ucs4_t uc); + + /* + * 判断是否为中文标点 + */ + int isuzhpunct(ucs4_t uc); + + /* + * 判断是否为日文平假名字符 + */ + int isuhiragana(ucs4_t uc); + + /* + * 判断是否为日文片假名字符 + */ + int isukatakana(ucs4_t uc); + + /* + * 判断是否为韩文字符 + */ + int isukorean(ucs4_t uc); + +} diff --git a/Runtime/Graphics/DynamicVertexBuffer.h b/Runtime/Graphics/DynamicVertexBuffer.h index b520d1b..12aa48c 100644 --- a/Runtime/Graphics/DynamicVertexBuffer.h +++ b/Runtime/Graphics/DynamicVertexBuffer.h @@ -46,8 +46,8 @@ private: EPrimitive m_CurPrimitive; - uint m_CurAttrMask; // default layout - uint m_CurStride; // default layout + uint m_CurAttrMask; // default layout only + uint m_CurStride; // default layout only uint m_CurVertexCount; uint m_CurIndexCount; diff --git a/Runtime/Graphics/VertexBuffer.h b/Runtime/Graphics/VertexBuffer.h index e6fd9ee..b03df3b 100644 --- a/Runtime/Graphics/VertexBuffer.h +++ b/Runtime/Graphics/VertexBuffer.h @@ -34,4 +34,6 @@ private: GPU::DataBuffer* m_VB; GPU::DataBuffer* m_IB; + EPrimitive m_Primitive; + }; diff --git a/Runtime/Lua/LuaBind/LuaBindClass.hpp b/Runtime/Lua/LuaBind/LuaBindClass.hpp index aed4741..dff4d30 100644 --- a/Runtime/Lua/LuaBind/LuaBindClass.hpp +++ b/Runtime/Lua/LuaBind/LuaBindClass.hpp @@ -102,7 +102,6 @@ namespace LuaBind friend class State; static void RegisterClassShared(State& state); - static void RegisterNativeClass(State& state); static void SetClassTableRef(State& state, int idx); static void PushClassTable(State& state); @@ -122,7 +121,6 @@ namespace LuaBind // static int __gc (lua_State*); - static int _GetRefTable (lua_State*); //--------------------------------------------------------------------------------// @@ -179,18 +177,6 @@ namespace LuaBind state.RegisterMethods(regTable); } - // ijԱעclass table - template<class TYPE, class BASE> - void NativeClass<TYPE, BASE>::RegisterNativeClass(State& state) - { - luaL_Reg regTable[] = { - { "GetRefTable", _GetRefTable }, - { NULL, NULL } - }; - - state.RegisterMethods(regTable); - } - template<class TYPE, class BASE> void NativeClass<TYPE, BASE>::SetClassTableRef(State& state, int idx) { @@ -560,17 +546,6 @@ namespace LuaBind return 1; } - template<class TYPE, class BASE> - int NativeClass<TYPE, BASE>::_GetRefTable(lua_State* L) - { - LUA_BIND_STATE(L); - TYPE* self = state.GetUserdata<TYPE>(1); - bool success = self->PushRefTable(state); - if (!success) - lua_pushnil(L); - return 1; - } - } #endif
\ No newline at end of file diff --git a/Runtime/Lua/LuaBind/LuaBindState.h b/Runtime/Lua/LuaBind/LuaBindState.h index 528c81a..21cde0d 100644 --- a/Runtime/Lua/LuaBind/LuaBindState.h +++ b/Runtime/Lua/LuaBind/LuaBindState.h @@ -273,8 +273,7 @@ namespace LuaBind lua_newtable(L); int clsIdx = lua_gettop(L); TYPE::RegisterClassShared(state); - TYPE::RegisterNativeClass(state); - TYPE::RegisterClass(state); + TYPE::RegisterClass_(state); // Զע if (onRegisterNativeClass) diff --git a/Runtime/Lua/LuaBind/LuaBindUtility.h b/Runtime/Lua/LuaBind/LuaBindUtility.h index b890b57..bf138e4 100644 --- a/Runtime/Lua/LuaBind/LuaBindUtility.h +++ b/Runtime/Lua/LuaBind/LuaBindUtility.h @@ -5,19 +5,15 @@ // RegisterClass עķͳԱö١ȵclass table GetNativeClassName ù // ͬʱעʱעΪsingletonͨʱ +// RegisterClasswin32ĺͻԼӸ» #define LUA_BIND_DECL_CLASS(type, ...) \ friend class LuaBind::State; \ friend class LuaBind::NativeClass<type,##__VA_ARGS__>; \ - static void RegisterClass(LuaBind::State&); \ + static void RegisterClass_(LuaBind::State&); \ static void RegisterPostprocess(LuaBind::State&); \ static const char* GetNativeClassName() { return #type; }; //static const char* GetClassName() { return #type; }; -// Ϊijʹô˺꣬עһڣעắеãעЩ -#define LUA_BIND_DECL_ABSTRACT_CLASS() \ - static void RegisterClass(::State&);\ - static void RegisterPostprocess(::State&) - #define LUA_BIND_DECL_METHOD(mtd) static int mtd(lua_State* L) #define LUA_BIND_DECL_ENUM(e, under_line_index) @@ -26,7 +22,7 @@ #define LUA_BIND_IMPL_METHOD(type, f) int type::f(lua_State* L) // Ӧóʵֵӿڡһstate -#define LUA_BIND_REGISTRY(type) void type::RegisterClass(LuaBind::State& state) +#define LUA_BIND_REGISTRY(type) void type::RegisterClass_(LuaBind::State& state) #define LUA_BIND_POSTPROCESS(type) void type::RegisterPostprocess(LuaBind::State& state) // עĺꡣ֮ǰÿɱ꣬ûluaclastable refûעԡ @@ -53,8 +49,6 @@ return 0;\ } -#define LUA_BIND_INHERIT(state, type) type::RegisterClass(state) - #define luaxport private #endif
\ No newline at end of file diff --git a/Runtime/Math/Math.h b/Runtime/Math/Math.h index 7f61544..aaeb264 100644 --- a/Runtime/Math/Math.h +++ b/Runtime/Math/Math.h @@ -9,3 +9,9 @@ #define max(a, b)\ (a)>(b)?(a):(b) + +typedef Internal::Vector2 Vector2; +typedef Internal::Vector3 Vector3; +typedef Internal::Vector4 Vector4; +typedef Internal::Matrix44 Matrix44; +typedef Internal::Rect Rect; diff --git a/Runtime/Scripting/GUI/Font.bind.cpp b/Runtime/Scripting/GUI/Font.bind.cpp index 73fb7e6..8259a60 100644 --- a/Runtime/Scripting/GUI/Font.bind.cpp +++ b/Runtime/Scripting/GUI/Font.bind.cpp @@ -3,12 +3,21 @@ #include "Runtime/Debug/Log.h" #include "Runtime/Graphics/GfxDevice.h" #include "Runtime/Common/DataBuffer.h"
+#include "Runtime/GUI/utf8.h"
+#include "Runtime/Utilities/StaticInitiator.h"
+
+static std::vector<character::Codepoint>* s_Codepoints;
+
+InitializeStaticVariables([](){
+ s_Codepoints = new std::vector<character::Codepoint>();
+});
LUA_BIND_REGISTRY(Font) { LUA_BIND_REGISTER_METHODS(state, { "New", _New }, { "GetCharacter", _GetCharacter }, + { "GetCharacters", _GetCharacters }, { "GetGlyphAtlas", _GetGlyphAtlas } ); } @@ -33,7 +42,7 @@ LUA_BIND_IMPL_METHOD(Font, _New) setting.margin = state.GetValue<int>(3, 0);
setting.padding = state.GetValue<int>(4, 0);
try {
- font = new Font(path, setting);
+ font = new Font(state.GetVM(), path, setting);
}
catch (FontException& e)
{
@@ -56,7 +65,7 @@ LUA_BIND_IMPL_METHOD(Font, _New) setting.margin = state.GetValue<int>(3, 0);
setting.padding = state.GetValue<int>(4, 0);
try {
- font = new Font(buffer, setting);
+ font = new Font(state.GetVM(), buffer, setting);
}
catch (FontException& e)
{
@@ -75,7 +84,6 @@ LUA_BIND_IMPL_METHOD(Font, _New) LUA_BIND_IMPL_METHOD(Font, _GetCharacter) {
LUA_BIND_PREPARE(L, Font);
-// Character character = self->GetCharacter(character);
return 1;
}
@@ -83,8 +91,43 @@ LUA_BIND_IMPL_METHOD(Font, _GetCharacter) LUA_BIND_IMPL_METHOD(Font, _GetCharacters) {
LUA_BIND_PREPARE(L, Font);
-// Character character = self->GetCharacter(character);
- return 1;
+ LUA_BIND_CHECK(L, "USN*");
+
+ char* buf = (char*)state.GetValue<const char*>(2, "");
+ int size = state.GetValue<int>(3, 12);
+ int encoding = state.GetValue<int>(4, EEncoding::Encoding_UTF8);
+
+ s_Codepoints->clear();
+ if (encoding == EEncoding::Encoding_UTF8)
+ {
+ while (*buf != 0) {
+ int err;
+ s_Codepoints->push_back(utf8::getu8c(&buf, &err));
+ if (err != 0)
+ {
+ log_warning("Illegal utf8 bytes %d", err);
+ }
+ }
+ }
+ else if (encoding == EEncoding::Encoding_UTF16)
+ {
+ while (*buf != 0) {
+ unsigned short* s = (unsigned short*)(buf);
+ s_Codepoints->push_back(*s);
+ buf += 2;
+ }
+ }
+ else if (encoding == EEncoding::Encoding_ASCII)
+ {
+ while (*buf != 0) {
+ s_Codepoints->push_back(*buf);
+ buf += 1;
+ }
+ }
+
+ self->RenderCharacters(*s_Codepoints, size);
+
+ return 0;
}
// font:GetAtlas(i)
diff --git a/Runtime/Scripting/GUI/GUI.bind.cpp b/Runtime/Scripting/GUI/GUI.bind.cpp index 4f6ed7a..fcc2848 100644 --- a/Runtime/Scripting/GUI/GUI.bind.cpp +++ b/Runtime/Scripting/GUI/GUI.bind.cpp @@ -20,5 +20,11 @@ int luaopen_GameLab_Engine_GUI(lua_State* L) state.RegisterNativeClass<Font>(); + LUA_BIND_REGISTER_ENUM(state, "EEncoding", + { "ASCII", EEncoding::Encoding_ASCII }, + { "UTF8", EEncoding::Encoding_UTF8 }, + { "UTF16", EEncoding::Encoding_UTF16 } + ); + return 1; }
\ No newline at end of file diff --git a/Runtime/Utilities/IncrementalTask.h b/Runtime/Utilities/IIncrementalTask.h index 741e55a..3762430 100644 --- a/Runtime/Utilities/IncrementalTask.h +++ b/Runtime/Utilities/IIncrementalTask.h @@ -1,11 +1,11 @@ #pragma once
// ʽ
-class IncrementalTask
+class IIncrementalTask
{
public:
- IncrementalTask() {};
- virtual ~IncrementalTask() {};
+ IIncrementalTask() {};
+ virtual ~IIncrementalTask() {};
virtual void Execute() = 0;
virtual bool IsDone() = 0;
|