Skip to content

Commit

Permalink
[scaleUpem] Optimize COLRv1 scale paint
Browse files Browse the repository at this point in the history
  • Loading branch information
behdad committed Aug 18, 2022
1 parent d275207 commit 0c6b67e
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions Lib/fontTools/ttLib/scaleUpem.py
Expand Up @@ -145,21 +145,31 @@ def visit(visitor, varData):

# COLRv1


@ScalerVisitor.register(otTables.BaseGlyphPaintRecord)
def visit(visitor, record):
oldPaint = record.Paint
def _setup_scale_paint(paint, scale):
if -2 <= scale <= 2 - (1 >> 14):
paint.Format = 20 # PaintScaleUniform

This comment has been minimized.

Copy link
@anthrotype

anthrotype Aug 18, 2022

Member

you know there's a otTables.PaintFormat enum (it's an IntEnum to be precise)? You could use that instead of the numbers. e.g. paint.Format = otTables.PaintFormat.PaintScaleUniform

This comment has been minimized.

Copy link
@behdad

behdad Aug 18, 2022

Author Member

Thanks. Will do.

paint.scale = scale
return

transform = otTables.Affine2x3()
transform.populateDefaults()
transform.xy = transform.yx = transform.dx = transform.dy = 0
transform.xx = transform.yy = visitor.scaleFactor
transform.xx = transform.yy = scale

paint.Format = 12 # PaintTransform
paint.Transform = transform


@ScalerVisitor.register(otTables.BaseGlyphPaintRecord)
def visit(visitor, record):
oldPaint = record.Paint

scale = otTables.Paint()
scale.Format = 12 # PaintTransform
scale.Transform = transform
_setup_scale_paint(scale, visitor.scaleFactor)
scale.Paint = oldPaint

record.Paint = scale

return True


Expand All @@ -175,12 +185,7 @@ def visit(visitor, paint):
del paint.Paint
del paint.Glyph

transform = otTables.Affine2x3()
transform.xy = transform.yx = transform.dx = transform.dy = 0
transform.xx = transform.yy = 1 / visitor.scaleFactor

paint.Format = 12 # PaintTransform
paint.Transform = transform
_setup_scale_paint(paint, 1 / visitor.scaleFactor)
paint.Paint = newPaint

visitor.visit(newPaint.Paint)
Expand Down

0 comments on commit 0c6b67e

Please sign in to comment.