From faba377c286ba0ea00f4f3bbd0e0cd05c42fd006 Mon Sep 17 00:00:00 2001 From: Nicholas Walczak Date: Tue, 7 Aug 2018 17:18:13 -0500 Subject: [PATCH] Fix system font kerning (#21) * Changed position variables from ints to floats * Get float values from GlyphMetrics --- .../java/com/kitfox/svg/MissingGlyph.java | 32 +++++++++---------- .../java/com/kitfox/svg/util/FontSystem.java | 4 +-- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/svg-core/src/main/java/com/kitfox/svg/MissingGlyph.java b/svg-core/src/main/java/com/kitfox/svg/MissingGlyph.java index b3c1b14..5d3fb90 100644 --- a/svg-core/src/main/java/com/kitfox/svg/MissingGlyph.java +++ b/svg-core/src/main/java/com/kitfox/svg/MissingGlyph.java @@ -60,10 +60,10 @@ public class MissingGlyph extends ShapeElement //We may define a path private Shape path = null; //Alternately, we may have child graphical elements - private int horizAdvX = -1; //Inherits font's value if not set - private int vertOriginX = -1; //Inherits font's value if not set - private int vertOriginY = -1; //Inherits font's value if not set - private int vertAdvY = -1; //Inherits font's value if not set + private float horizAdvX = -1; //Inherits font's value if not set + private float vertOriginX = -1; //Inherits font's value if not set + private float vertOriginY = -1; //Inherits font's value if not set + private float vertAdvY = -1; //Inherits font's value if not set /** * Creates a new instance of Font @@ -131,22 +131,22 @@ protected void build() throws SVGException //Read glyph spacing info if (getPres(sty.setName("horiz-adv-x"))) { - horizAdvX = sty.getIntValue(); + horizAdvX = sty.getFloatValue(); } if (getPres(sty.setName("vert-origin-x"))) { - vertOriginX = sty.getIntValue(); + vertOriginX = sty.getFloatValue(); } if (getPres(sty.setName("vert-origin-y"))) { - vertOriginY = sty.getIntValue(); + vertOriginY = sty.getFloatValue(); } if (getPres(sty.setName("vert-adv-y"))) { - vertAdvY = sty.getIntValue(); + vertAdvY = sty.getFloatValue(); } } @@ -178,7 +178,7 @@ public void render(Graphics2D g) throws SVGException //Do not push or pop stack } - public int getHorizAdvX() + public float getHorizAdvX() { if (horizAdvX == -1) { @@ -187,7 +187,7 @@ public int getHorizAdvX() return horizAdvX; } - public int getVertOriginX() + public float getVertOriginX() { if (vertOriginX == -1) { @@ -196,7 +196,7 @@ public int getVertOriginX() return vertOriginX; } - public int getVertOriginY() + public float getVertOriginY() { if (vertOriginY == -1) { @@ -205,7 +205,7 @@ public int getVertOriginY() return vertOriginY; } - public int getVertAdvY() + public float getVertAdvY() { if (vertAdvY == -1) { @@ -260,7 +260,7 @@ public void setPath(Shape path) /** * @param horizAdvX the horizAdvX to set */ - public void setHorizAdvX(int horizAdvX) + public void setHorizAdvX(float horizAdvX) { this.horizAdvX = horizAdvX; } @@ -268,7 +268,7 @@ public void setHorizAdvX(int horizAdvX) /** * @param vertOriginX the vertOriginX to set */ - public void setVertOriginX(int vertOriginX) + public void setVertOriginX(float vertOriginX) { this.vertOriginX = vertOriginX; } @@ -276,7 +276,7 @@ public void setVertOriginX(int vertOriginX) /** * @param vertOriginY the vertOriginY to set */ - public void setVertOriginY(int vertOriginY) + public void setVertOriginY(float vertOriginY) { this.vertOriginY = vertOriginY; } @@ -284,7 +284,7 @@ public void setVertOriginY(int vertOriginY) /** * @param vertAdvY the vertAdvY to set */ - public void setVertAdvY(int vertAdvY) + public void setVertAdvY(float vertAdvY) { this.vertAdvY = vertAdvY; } diff --git a/svg-core/src/main/java/com/kitfox/svg/util/FontSystem.java b/svg-core/src/main/java/com/kitfox/svg/util/FontSystem.java index 7d11f36..5c4ebf2 100644 --- a/svg-core/src/main/java/com/kitfox/svg/util/FontSystem.java +++ b/svg-core/src/main/java/com/kitfox/svg/util/FontSystem.java @@ -140,8 +140,8 @@ public MissingGlyph getGlyph(String unicode) glyph.setPath(vec.getGlyphOutline(0)); GlyphMetrics gm = vec.getGlyphMetrics(0); - glyph.setHorizAdvX((int)gm.getAdvanceX()); - glyph.setVertAdvY((int)gm.getAdvanceY()); + glyph.setHorizAdvX(gm.getAdvanceX()); + glyph.setVertAdvY(gm.getAdvanceY()); glyph.setVertOriginX(0); glyph.setVertOriginY(0);