mirror of
https://github.com/googlefonts/noto-emoji.git
synced 2025-06-07 23:37:58 +00:00
respond to comments on r1a10391d3f73
This commit is contained in:
parent
1a9a94525b
commit
6254dd6602
1 changed files with 43 additions and 28 deletions
|
@ -114,37 +114,50 @@ class SvgBuilder(object):
|
||||||
|
|
||||||
# We're going to assume default values for preserveAspectRatio for now,
|
# We're going to assume default values for preserveAspectRatio for now,
|
||||||
# this preserves aspect ratio and centers in the viewport.
|
# this preserves aspect ratio and centers in the viewport.
|
||||||
# First scale to the viewport, which is 1000x1000. compute the scaled
|
#
|
||||||
# extent and translations that center it in the viewport. We won't try
|
# The viewport is 0,0 1000x1000. First compute the scaled extent and
|
||||||
# to optimize this, it's clearer what we're doing this way.
|
# translations that center the image rect in the viewport, then scale and
|
||||||
if w > h:
|
# translate the result to fit our true 'viewport', which has an origin at
|
||||||
s2vp = 1000.0/w
|
# 0,-ascent and an extent of advance (if defined) x font_height. We won't
|
||||||
sh = s2vp * h
|
# try to optimize this, it's clearer what we're doing this way.
|
||||||
sty = (1000 - sh) / 2
|
|
||||||
sw = 1000.0
|
|
||||||
stx = 0.0
|
|
||||||
else:
|
|
||||||
s2vp = 1000.0/h
|
|
||||||
sh = 1000.0
|
|
||||||
sty = 0.0
|
|
||||||
sw = s2vp * w
|
|
||||||
stx = (1000 - sw) / 2
|
|
||||||
|
|
||||||
# now, compute the scale. we scale to the height, unless we have
|
# Since the viewport is square, we can just compare w and h to determine
|
||||||
# to fit an advance, in which case we scale to the width
|
# which to fit to the viewport extent. Get our position and extent in
|
||||||
scale = self.font_height / sh
|
# the viewport.
|
||||||
|
if w > h:
|
||||||
|
scale_to_viewport = 1000.0 / w
|
||||||
|
h_in_viewport = scale_to_viewport * h
|
||||||
|
y_in_viewport = (1000 - h_in_viewport) / 2
|
||||||
|
w_in_viewport = 1000.0
|
||||||
|
x_in_viewport = 0.0
|
||||||
|
else:
|
||||||
|
scale_to_viewport = 1000.0 / h
|
||||||
|
h_in_viewport = 1000.0
|
||||||
|
y_in_viewport = 0.0
|
||||||
|
w_in_viewport = scale_to_viewport * w
|
||||||
|
x_in_viewport = (1000 - w_in_viewport) / 2
|
||||||
|
|
||||||
|
# Now, compute the scale and translations that fit this rectangle to our
|
||||||
|
# true 'viewport'. The true viewport is not square so we need to choose the
|
||||||
|
# smaller of the scales that fit its height or width. We start with height,
|
||||||
|
# if there's no advance then we're done, otherwise we might have to fit the
|
||||||
|
# advance.
|
||||||
|
scale = self.font_height / h_in_viewport
|
||||||
fit_height = True
|
fit_height = True
|
||||||
if advance and scale * sw > advance:
|
if advance and scale * w_in_viewport > advance:
|
||||||
scale = advance / sw
|
scale = advance / w_in_viewport
|
||||||
fit_height = False
|
fit_height = False
|
||||||
|
|
||||||
ty = -self.font_ascent - scale * sty
|
# Compute transforms that put the top left of the image where we want it.
|
||||||
tx = scale * stx
|
ty = -self.font_ascent - scale * y_in_viewport
|
||||||
|
tx = -scale * x_in_viewport
|
||||||
|
|
||||||
|
# Adjust them to center the image horizontally if we fit the full height,
|
||||||
|
# vertically otherwise.
|
||||||
if fit_height and advance:
|
if fit_height and advance:
|
||||||
tx += (advance - scale * sw) / 2
|
tx += (advance - scale * w_in_viewport) / 2
|
||||||
else:
|
else:
|
||||||
ty += (self.font_height - scale * sh) / 2
|
ty += (self.font_height - scale * h_in_viewport) / 2
|
||||||
|
|
||||||
cleaner.clean_tree(tree)
|
cleaner.clean_tree(tree)
|
||||||
|
|
||||||
|
@ -167,14 +180,16 @@ class SvgBuilder(object):
|
||||||
<path d="M%g %gh%gv%gh%gz"/></clipPath></g>""" % (clip_id, clip_id, x, y, w, h, -w)
|
<path d="M%g %gh%gv%gh%gz"/></clipPath></g>""" % (clip_id, clip_id, x, y, w, h, -w)
|
||||||
clip_tree = cleaner.tree_from_text(clip_text)
|
clip_tree = cleaner.tree_from_text(clip_text)
|
||||||
clip_tree.contents.extend(tree.contents)
|
clip_tree.contents.extend(tree.contents)
|
||||||
tree.contents = [clip_tree];
|
tree.contents = [clip_tree]
|
||||||
|
|
||||||
svgdoc = cleaner.tree_to_text(tree)
|
svgdoc = cleaner.tree_to_text(tree)
|
||||||
|
|
||||||
hmetrics = None
|
hmetrics = None
|
||||||
if not exists:
|
if not exists:
|
||||||
# horiz advance and lsb
|
# There was no advance to fit, so no horizontal centering. The image advance is
|
||||||
advance = scale * sw
|
# all there is.
|
||||||
|
# hmetrics is horiz advance and lsb
|
||||||
|
advance = scale * w_in_viewport
|
||||||
hmetrics = [int(round(advance)), 0]
|
hmetrics = [int(round(advance)), 0]
|
||||||
|
|
||||||
fbuilder.add_svg(svgdoc, hmetrics, name, index)
|
fbuilder.add_svg(svgdoc, hmetrics, name, index)
|
||||||
|
|
Loading…
Add table
Reference in a new issue