You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-users@xmlgraphics.apache.org by Sam Fuqua <sa...@gmail.com> on 2009/06/20 22:23:21 UTC
Font registration in a static method
Hi,
I have a FopFactory being declared in a static method. I have no control
over changing the method to non-static.
When the FopFacotry is created, I try to load a configuration that
auto-detects the fonts. Unfortunately, before I even load the
configuration, the FopFactory seems to be created with an existing FontCache
with all of my fonts in the failedFontMap. When I load the configuration,
nothing changes and I am unable to use any of my fonts in the XSL. I am
using 0.94.
Is this affected by the fact that it is declared inside of a static method?
Is there anyway to clear the FontCache and still have it reloaded with
auto-detect? I have been able to clear out the FontCache, but it doesn't
reload with the auto-detected fonts, so I am still unable to use my fonts.
--
Sam Fuqua
ΣΝ ΘΗ 454
Re: Font registration in a static method
Posted by Andreas Delmelle <an...@telenet.be>.
On 24 Jun 2009, at 19:19, Sam Fuqua wrote:
Hi Sam
> I took your advice and have gotten some error output. It doesn't
> print this every time, but it has printed for every font I have
> installed something to the effect of "Failed to load font file
> ___ . Could not load InputStream". If it could find the files
> itself, then I know that it wasn't me putting in a bad URL, but why
> would it be that it can't load any of them? I'm trying to use
> a .ttf font.
Went digging a bit, and in FOP Trunk, the message in question comes
from within o.a.fop.fonts.FontLoader.openFontURI(). I haven't yet
located the code in question in 0.95 or earlier, but from what I can
tell, it looks a bit like someone has been abusing the JAXP
StreamSource object to open simple binary streams which are in no way
related to XML... If it were used to load font-metrics XML, that I can
dig, but in case of plain byte streams, using the JAXP pattern does
not seem appropriate.
Try to follow:
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/FontLoader.java?revision=746664
First we try to obtain a Source object, via the FontResolver that is
passed in. The minimal resolver that is generated by the default
FontManager uses the StreamSource(String) constructor. It only passes
in the URI to the resource, which the JAXP API docs tell us leaves the
InputStream unset. I think (but am far from certain) that a JAXP-
compliant parser may even choose to ignore setting the systemId if the
content is not valid XML... which is one possible cause for the cited
message. Another one is that the URL is actually not valid according
to URI syntax.
Can you show us a few of those URLs?
>
> I also tried loading the font manually by creating a FontTriplet and
> EmbedFontInfo and adding it to the FopFactory FontCache, which gave
> no error except for the usual "Substituting with 'any'". Any ideas?
Was this after clearing the cache? It's a file called 'fop-
fonts.cache', normally residing in the user's home directory, in a
subdir named '.fop'. I would try deleting that to make sure the cache
is reconstituted from scratch. Activating DEBUG-level output will show
more info about what happens when the fonts are initially loaded.
Regards
Andreas
---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org
Re: Font registration in a static method
Posted by Sam Fuqua <sa...@gmail.com>.
Andreas,
I took your advice and have gotten some error output. It doesn't print this
every time, but it has printed for every font I have installed something to
the effect of "Failed to load font file ___ . Could not load InputStream".
If it could find the files itself, then I know that it wasn't me putting in
a bad URL, but why would it be that it can't load any of them? I'm trying
to use a .ttf font.
I also tried loading the font manually by creating a FontTriplet and
EmbedFontInfo and adding it to the FopFactory FontCache, which gave no error
except for the usual "Substituting with 'any'". Any ideas?
Sam
On Mon, Jun 22, 2009 at 2:57 PM, Andreas Delmelle <
andreas.delmelle@telenet.be> wrote:
> On 20 Jun 2009, at 22:23, Sam Fuqua wrote:
>
> Hi Sam
>
> I have a FopFactory being declared in a static method. I have no control
>> over changing the method to non-static.
>> When the FopFacotry is created, I try to load a configuration that
>> auto-detects the fonts. Unfortunately, before I even load the
>> configuration, the FopFactory seems to be created with an existing FontCache
>> with all of my fonts in the failedFontMap. When I load the configuration,
>> nothing changes and I am unable to use any of my fonts in the XSL. I am
>> using 0.94.
>>
>
> Just so I get the setup correctly: do the font-locations vary with each
> rendering run? If not, and they always remain the same, it's better practice
> (will yield better performance, in general) to share the FopFactory between
> multiple sessions. You could then include its configuration in the same
> code-block where you instantiate the factory.
>
> Is this affected by the fact that it is declared inside of a static
>> method?
>>
>
> I see a possibility that this could indeed have an influence: static code
> can be compiled, inlined and executed as soon as the class is loaded. If the
> FopFactory is not configured to use auto-detection, the font-triplets
> referenced in the eventual target process will not be found in the cache,
> and FOP will fall back on a value of 'any'.
>
> Is there anyway to clear the FontCache and still have it reloaded with
>> auto-detect? I have been able to clear out the FontCache, but it doesn't
>> reload with the auto-detected fonts, so I am still unable to use my fonts.
>>
>
> See above. I think all you need to do, is make sure that right after you
> instantiate the FopFactory, it is properly configured to auto-detect OS
> installed fonts. If that still doesn't work, you'll have to activate
> debug-output, to check whether the referenced font was properly loaded.
>
>
> HTH!
>
> Regards,
>
> Andreas Delmelle
> mailto:andreas.delmelle.AT.telenet.be
> jabber: mandreas@jabber.org
> skype: adlm0608
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org
>
>
--
Sam Fuqua
ΣΝ ΘΗ 454
Re: Font registration in a static method
Posted by Andreas Delmelle <an...@telenet.be>.
On 20 Jun 2009, at 22:23, Sam Fuqua wrote:
Hi Sam
> I have a FopFactory being declared in a static method. I have no
> control over changing the method to non-static.
> When the FopFacotry is created, I try to load a configuration that
> auto-detects the fonts. Unfortunately, before I even load the
> configuration, the FopFactory seems to be created with an existing
> FontCache with all of my fonts in the failedFontMap. When I load
> the configuration, nothing changes and I am unable to use any of my
> fonts in the XSL. I am using 0.94.
Just so I get the setup correctly: do the font-locations vary with
each rendering run? If not, and they always remain the same, it's
better practice (will yield better performance, in general) to share
the FopFactory between multiple sessions. You could then include its
configuration in the same code-block where you instantiate the factory.
> Is this affected by the fact that it is declared inside of a static
> method?
I see a possibility that this could indeed have an influence: static
code can be compiled, inlined and executed as soon as the class is
loaded. If the FopFactory is not configured to use auto-detection, the
font-triplets referenced in the eventual target process will not be
found in the cache, and FOP will fall back on a value of 'any'.
> Is there anyway to clear the FontCache and still have it reloaded
> with auto-detect? I have been able to clear out the FontCache, but
> it doesn't reload with the auto-detected fonts, so I am still unable
> to use my fonts.
See above. I think all you need to do, is make sure that right after
you instantiate the FopFactory, it is properly configured to auto-
detect OS installed fonts. If that still doesn't work, you'll have to
activate debug-output, to check whether the referenced font was
properly loaded.
HTH!
Regards,
Andreas Delmelle
mailto:andreas.delmelle.AT.telenet.be
jabber: mandreas@jabber.org
skype: adlm0608
---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org