Skip to content

Commit

Permalink
调整字符宽度
Browse files Browse the repository at this point in the history
  • Loading branch information
raino_tx committed Sep 7, 2024
1 parent f226651 commit e1bcdcf
Show file tree
Hide file tree
Showing 5 changed files with 8,455 additions and 71 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,8 @@ pyrcc5 resources.qrc -o resources.py
# 编译 ui 文件
pyuic5 ui/main_ui.ui -o ui/main_ui.py
```

# attention

- 卸载插件之前先备份,尤其是在开发过程(卸载插件会删代码目录)🎃
- 目前只适配`微软雅黑`字体
3 changes: 2 additions & 1 deletion font_outline.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def run(self):
result = self.dlg.exec_() # Run the dialog event loop

if result :
input_str = self.dlg.lineEdit.text()
input_str = self.dlg.lineEdit.text().strip()
if input_str is "" or input_str is None:
return self.iface.messageBar().pushMessage("warning", f"输入文本为空,生成失败。", level=Qgis.Warning, duration=5)
# return self.iface.messageBar().pushWarning("warning", "输入文本为空,生成失败。")
Expand All @@ -185,6 +185,7 @@ def run(self):

def _save2file(self, input_str, location_text, save_path):
fontparse = FontParser(os.path.join(self.plugin_dir,"assets", "msyahei.ttf"))
# fontparse = FontParser(os.path.join(self.plugin_dir,"assets", "SourceCodePro-Regular.ttf"))
fontparse.parse(input_str, location_text, save_path)

self.iface.messageBar().pushMessage("success", f"成功生成 geojson 文件。", level=Qgis.Info, duration=5)
Expand Down
14 changes: 11 additions & 3 deletions fontparser/ContourExtractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ def setChar(self, input_char):
self._char = input_char

def bbox(self):
if len(self._contours) == 0:
return
minX = maxX = self._contours[0][0][0]
minY = maxY = self._contours[0][0][1]
for contour in self._contours:
Expand All @@ -64,6 +66,10 @@ def wh(self):
input_char: x
ori_width 986
ori_height 1106
==input_char: w
w unicode编码为: 119
==ori_width 1567
==ori_height 1106
- 大写字母
input_char: X
ori_width 1265
Expand All @@ -76,24 +82,26 @@ def wh(self):
:return wh:左下角坐标和宽高
:type wh:(minx, miny, width, height)
"""
if self.is_lowercase(): return (986, 1106)
if self.is_lowercase(): return (1265, 1106)
if self._char.isdigit(): return (897, 1582)
if self.is_uppercase(): return (1265, 1549)
if self.is_chinese(): return (1994, 1968)
if self.is_chinese(): return (2000, 1968)
return (1265, 1549)

def is_chinese(self):
# 中文字符 Unicode 范围
print("chinese char")
return '\u4e00' <= self._char <= '\u9fff'

def is_uppercase(self):
# 判断是否是大写英文字母
print("english uppercase char")
return 'A' <= self._char <= 'Z'

def is_lowercase(self):
# 判断是否是小写英文字母
print("english lowercase char")
return 'a' <= self._char <= 'z'



def parse(self, parsefunc=None):
Expand Down
3 changes: 2 additions & 1 deletion fontparser/CoordinateConverter.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ def transform(self, contourExtractor:ContourExtractor, i):
if contourExtractor.is_chinese():
pin_base_y = self.base_y # 中文不处理
else:
pin_base_y = self.base_y + minY * scale_y # 处理下基线,类似g,j之类的字母
pin_base_y = self.base_y + minY * scale_y # 处理基线,类似g,j之类的字母
pin_base_y = self.base_y + minY * scale_y # 处理基线,类似g,j之类的字母


for i, contour in enumerate(contours):
Expand Down
Loading

0 comments on commit e1bcdcf

Please sign in to comment.