xmlgraphics-batik-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 46374] Fonts not found for SVG texts (when not in C:\WINNT\Fonts)
Date Fri, 15 May 2009 01:40:26 GMT
https://issues.apache.org/bugzilla/show_bug.cgi?id=46374


Cameron McCormack <cam@apache.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |NEEDINFO




--- Comment #5 from Cameron McCormack <cam@apache.org>  2009-05-14 18:40:23 PST ---
Hi Alexis.

(In reply to comment #4)
> In svggen.SVGFont.java:
> 
> ############
> private static Font createCommonSizeFont(Font font) {
>    Map attributes = new HashMap(font.getAttributes());
>    attributes.put(TextAttribute.SIZE, new Float(COMMON_FONT_SIZE));
>    // Remove Transform from font otherwise it will be applied twice.
>    attributes.remove(TextAttribute.TRANSFORM);
>    return new Font(attributes);
> }
> ############
> 
> The last line that is calling the Font constructor actually fails silently if
> the "font" object is not a system font. This is called when creating the map of
> which characters are used by which font, so the String used to store the font
> family and weight correspond to the Dialog font used as a fallback.

Makes sense.

> A simple way to solve this problem would be to use the deriveFont method
> instead:
> 
> ############
> private static Font createCommonSizeFont(Font font) {
>    Map attributes = new HashMap(font.getAttributes());
>    attributes.put(TextAttribute.SIZE, new Float(COMMON_FONT_SIZE));
>    // Remove Transform from font otherwise it will be applied twice.
>    attributes.remove(TextAttribute.TRANSFORM);
>    return font.deriveFont(attributes);
> }
> ############
> 
> (or maybe just a 
> ############
> private static Font createCommonSizeFont(Font font) {
>    return font.deriveFont(new Float(COMMON_FONT_SIZE));
> }
> ############
> but I am not sure about the transform you are removing)

When using deriveFont(), all of the existing attributes are kept from the
original Font, and only those present in the passed-in Map are overwritten.  So
to remove the TRANSFORM attribute, you need to provide a map with a [TRANSFORM,
null] entry in it:

  private static Font createCommonSizeFont(Font font) {
      Map attributes = new HashMap();
      attributes.put(TextAttribute.SIZE, new Float(COMMON_FONT_SIZE));
      attributes.put(TextAttribute.TRANSFORM, null);
      return font.deriveFont(attributes);
  }

> Since any generated SVG file contains the non-system font name and family, but
> uses the default shapes (see the previous attachment), I guess the fonts are
> stored in a different place, but the toSVG method is calling anyway
> createCommonSizeFont before generating the glyphs.
> 
> Why I am not commiting a patch is because I have not found yet where the
> xmlwriter is calling the toSVG method of SVGFont that is actually writing the
> glyph shapes. I am wondering when the method is actually called (non system
> fonts might be destroyed between the drawString call and the stream call).

The glyph shapes are extracted with the

  gv.getGlyphOutline(0)

calls that are in SVGFont.toSVG().  Since they are called on a GlyphVector that
was obtained from the common size font, that'd be why the wrong shapes were
written out in the SVG.


I've just committed the above change as r774981 ( https://svn.apache.org/viewcvs.cgi?view=rev&rev=774981
).  It makes your test case work,
Alexis.


M.H., are you able to test if this allows FOP to work with other fonts?

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-dev-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-dev-help@xmlgraphics.apache.org


Mime
View raw message