Skip to content

Commit

Permalink
finish
Browse files Browse the repository at this point in the history
  • Loading branch information
raino_tx committed Sep 7, 2024
1 parent 9a65f15 commit 47ccd0d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
14 changes: 12 additions & 2 deletions fontparser/ContourExtractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def setChar(self, input_char):

def bbox(self):
if len(self._contours) == 0:
return
raise Exception("it just work!!!")
minX = maxX = self._contours[0][0][0]
minY = maxY = self._contours[0][0][1]
for contour in self._contours:
Expand Down Expand Up @@ -82,10 +82,20 @@ def wh(self):
:return wh:左下角坐标和宽高
:type wh:(minx, miny, width, height)
"""
if self.is_lowercase(): return (986, 1106)
if self._char.isdigit(): return (897, 1582)
if self.is_uppercase(): return (1265, 1549)
if self.is_chinese(): return (2000, 1968)
return (1265, 1549)

def rectange(self):
"""alias of wh()"""
minX, minY, maxX, maxY = self.bbox()

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 (2000, 1968)
if self.is_chinese(): return (2000, 1968)
return (1265, 1549)

def is_chinese(self):
Expand Down
12 changes: 6 additions & 6 deletions fontparser/CoordinateConverter.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ def __init__(self, base_position, width, gap):
self.base_x, self.base_y = base_position
self.new_width = width
self.gap = gap
self._current_x = self.base_x

def transform(self, contourExtractor:ContourExtractor, i):
def transform(self, contourExtractor:ContourExtractor, index):
"""
变换contour坐标:
"""
Expand All @@ -45,18 +46,17 @@ def transform(self, contourExtractor:ContourExtractor, i):
width, height = contourExtractor.wh()

# 计算缩放因子
scale_x = self.new_width / height
scale_x = self.new_width / width
scale_y = scale_x # 保持宽高比

contours = contourExtractor.coords()

# 平移之后的坐标
pin_base_x = self.base_x + (self.new_width + self.gap) * i
pin_base_x = self.base_x + (self.new_width + self.gap) * index

pin_base_y = self.base_y + minY * scale_y # 处理基线,类似g,j之类的字母
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之类的字母


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

0 comments on commit 47ccd0d

Please sign in to comment.