Skip to content

Commit

Permalink
[OpenType] CircleDotOutlinesPainter 优化画圆算法
Browse files Browse the repository at this point in the history
  • Loading branch information
TakWolf committed Jan 22, 2025
1 parent ab977d7 commit bad7ffc
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/pixel_font_builder/opentype/pen.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import math
from abc import abstractmethod
from typing import Protocol, runtime_checkable

Expand Down Expand Up @@ -211,14 +212,15 @@ def __init__(self, radius: float = 0.4):

def draw_outlines(self, glyph: Glyph, pen: OutlinesPen, px_to_units: int):
radius = self.radius * px_to_units
c = radius * 4 / 3 * (math.sqrt(2) - 1)
for y, bitmap_row in enumerate(glyph.bitmap):
y = (glyph.height + glyph.horizontal_origin_y - y - 0.5) * px_to_units
for x, color in enumerate(bitmap_row):
x = (x + glyph.horizontal_origin_x + 0.5) * px_to_units
if color != 0:
pen.move_to((x, y + radius))
pen.quadratic_curve_to((x + radius, y + radius), (x + radius, y))
pen.quadratic_curve_to((x + radius, y - radius), (x, y - radius))
pen.quadratic_curve_to((x - radius, y - radius), (x - radius, y))
pen.quadratic_curve_to((x - radius, y + radius), (x, y + radius))
pen.compat_cubic_curve_to((x + c, y + radius), (x + radius, y + c), (x + radius, y))
pen.compat_cubic_curve_to((x + radius, y - c), (x + c, y - radius), (x, y - radius))
pen.compat_cubic_curve_to((x - c, y - radius), (x - radius, y - c), (x - radius, y))
pen.compat_cubic_curve_to((x - radius, y + c), (x - c, y + radius), (x, y + radius))
pen.close_path()

0 comments on commit bad7ffc

Please sign in to comment.