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 Georg Datterl <ge...@geneon.de> on 2008/12/17 17:06:46 UTC

Usage of Font.getWordWidth()

Hi everybody,

Maybe it's too late in the year for my brain to work properly, but I want to call Font.getWordWidth(String) to find out how much space a string will take in the finished PDF, but I can't figure out how I can get the Font object given the values for font-family and font-size (which are the values I later write into the fo-file). 

The fonts are there and registered correctly in my fop.xconf, are used when generating the PDF and generally work fine. I also tried to read through the source code, but came from Font to FontMetrics to FontInfo to CommonFont to CompleteConfusion. 

Second question: When I finally get a result, what unit would that be in?

Regards,
 
Georg Datterl
 
------ Kontakt ------
 
Georg Datterl
 
Geneon media solutions gmbh
Gutenstetter Straße 8a
90449 Nürnberg
 
HRB Nürnberg: 17193
Geschäftsführer: Yong-Harry Steiert 

Tel.: 0911/36 78 88 - 26
Fax: 0911/36 78 88 - 20
 
www.geneon.de
 
Weitere Mitglieder der Willmy MediaGroup:
 
IRS Integrated Realization Services GmbH:    www.irs-nbg.de 
Willmy PrintMedia GmbH:                            www.willmy.de
Willmy Consult & Content GmbH:                 www.willmycc.de 

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


Populate table with blank cells/rows

Posted by "Chakravarty, Abhishek" <Ab...@accidentfund.com>.
Is there a way to populate a table (which overflows onto page 2) with
empty rows/cells until a particular margin(..in this case until the
footer i.e. the region-after section) when the contents have already
been obtained from the xml? 

Sometimes data in the xml can wrap onto the next line in the resulting
pdf (as the column width is smaller in the table specs). So it creates a
problem where just simply counting the number of lines which have been
populated so far doesn't work.

Have tried setting a row height with blank data to make the empty row(s)
but setting a static height to fill is only possible when it is known
how much of the region -body has already been filled, which in this case
won't be possible to know due to the word wrapping issue. 

Regards
Abhishek



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



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



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


RE: table overflow onto page 2 into specific region

Posted by "Chakravarty, Abhishek" <Ab...@accidentfund.com>.
Thanks loads I put my header and footer into the region-before and
region-after of the page and problem solved (for now.)

-----Original Message-----
From: Jeremias Maerki [mailto:dev@jeremias-maerki.ch] 
Sent: Friday, December 19, 2008 3:27 PM
To: fop-users@xmlgraphics.apache.org
Subject: Re: table overflow onto page 2 into specific region

Not sure I've understood exactly what it is you need. But I'll try.

First of all, you simple need fo:table-header [1] and fo:table-footer 
[2] before your fo:table-body. That gives you headers and footers for
the table that is repeated on each page.

[1] http://www.w3.org/TR/xsl11/#fo_table-header
[2] http://www.w3.org/TR/xsl11/#fo_table-footer

An example:
          <fo:table table-layout="fixed" width="100%">
            <fo:table-column number-columns-repeated="2"
column-width="proportional-column-width(1)"/>
            <fo:table-header>
              <fo:table-row>
                <fo:table-cell>
                  <fo:block>header1</fo:block>
                </fo:table-cell>
                <fo:table-cell>
                  <fo:block>header2</fo:block>
                </fo:table-cell>
              </fo:table-row>
            </fo:table-header>
            <fo:table-footer>
              <fo:table-row>
                <fo:table-cell>
                  <fo:block>footer1</fo:block>
                </fo:table-cell>
                <fo:table-cell>
                  <fo:block>footer2</fo:block>
                </fo:table-cell>
              </fo:table-row>
            </fo:table-footer>
            <fo:table-body>
              <fo:table-row>
                <fo:table-cell>
                  <fo:block>cell1</fo:block>
                </fo:table-cell>
                <fo:table-cell>
                  <fo:block>cell2</fo:block>
                </fo:table-cell>
              </fo:table-row>
              <fo:table-row>
                <fo:table-cell>
                  <fo:block>cell3</fo:block>
                </fo:table-cell>
                <fo:table-cell>
                  <fo:block>cell4</fo:block>
                </fo:table-cell>
              </fo:table-row>
            </fo:table-body>
          </fo:table>

Only now, it's getting tricky. You say you need changing content in the
header and footer. That's what table-markers [3][4] from XSL 1.1 are
for.
But unfortunately, this hasn't been implemented, yet. So the only thing
you can try is putting your header and footer content in the
region-before and the region-after of the page. There you can work with
fo:retrieve-marker [5] to access content you specify in fo:marker [6]
elements.

[3] http://www.w3.org/TR/xsl11/#fo_retrieve-table-marker
[4] http://www.w3.org/TR/xsl11/#d0e14681
[5] http://www.w3.org/TR/xsl11/#fo_retrieve-marker
[6] http://www.w3.org/TR/xsl11/#fo_marker

HTH

On 18.12.2008 16:24:11 Chakravarty, Abhishek wrote:
> Hi
> 
> Is there a way to ensure in my stylesheet that a table overflows into
> second page into the area which is prespecified for it only?
> 
> As in I have the page setup as the header followed by a table followed
> by footer. But if the table overflows then is it possible to have it
> onto the second page in the same region so that my second page would
now
> look like header followed by table (the content of which is from the
> previous page table overflow) and then the footer.
> 
> Also none of the info is static i.e. headers and footers can change
> depending on the content being pulled in from the xml (but the table
> layout remains the same).
> 
> Regards
> Abhishek




Jeremias Maerki


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



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


Re: table overflow onto page 2 into specific region

Posted by Jeremias Maerki <de...@jeremias-maerki.ch>.
Not sure I've understood exactly what it is you need. But I'll try.

First of all, you simple need fo:table-header [1] and fo:table-footer 
[2] before your fo:table-body. That gives you headers and footers for
the table that is repeated on each page.

[1] http://www.w3.org/TR/xsl11/#fo_table-header
[2] http://www.w3.org/TR/xsl11/#fo_table-footer

An example:
          <fo:table table-layout="fixed" width="100%">
            <fo:table-column number-columns-repeated="2" column-width="proportional-column-width(1)"/>
            <fo:table-header>
              <fo:table-row>
                <fo:table-cell>
                  <fo:block>header1</fo:block>
                </fo:table-cell>
                <fo:table-cell>
                  <fo:block>header2</fo:block>
                </fo:table-cell>
              </fo:table-row>
            </fo:table-header>
            <fo:table-footer>
              <fo:table-row>
                <fo:table-cell>
                  <fo:block>footer1</fo:block>
                </fo:table-cell>
                <fo:table-cell>
                  <fo:block>footer2</fo:block>
                </fo:table-cell>
              </fo:table-row>
            </fo:table-footer>
            <fo:table-body>
              <fo:table-row>
                <fo:table-cell>
                  <fo:block>cell1</fo:block>
                </fo:table-cell>
                <fo:table-cell>
                  <fo:block>cell2</fo:block>
                </fo:table-cell>
              </fo:table-row>
              <fo:table-row>
                <fo:table-cell>
                  <fo:block>cell3</fo:block>
                </fo:table-cell>
                <fo:table-cell>
                  <fo:block>cell4</fo:block>
                </fo:table-cell>
              </fo:table-row>
            </fo:table-body>
          </fo:table>

Only now, it's getting tricky. You say you need changing content in the
header and footer. That's what table-markers [3][4] from XSL 1.1 are for.
But unfortunately, this hasn't been implemented, yet. So the only thing
you can try is putting your header and footer content in the
region-before and the region-after of the page. There you can work with
fo:retrieve-marker [5] to access content you specify in fo:marker [6]
elements.

[3] http://www.w3.org/TR/xsl11/#fo_retrieve-table-marker
[4] http://www.w3.org/TR/xsl11/#d0e14681
[5] http://www.w3.org/TR/xsl11/#fo_retrieve-marker
[6] http://www.w3.org/TR/xsl11/#fo_marker

HTH

On 18.12.2008 16:24:11 Chakravarty, Abhishek wrote:
> Hi
> 
> Is there a way to ensure in my stylesheet that a table overflows into
> second page into the area which is prespecified for it only?
> 
> As in I have the page setup as the header followed by a table followed
> by footer. But if the table overflows then is it possible to have it
> onto the second page in the same region so that my second page would now
> look like header followed by table (the content of which is from the
> previous page table overflow) and then the footer.
> 
> Also none of the info is static i.e. headers and footers can change
> depending on the content being pulled in from the xml (but the table
> layout remains the same).
> 
> Regards
> Abhishek




Jeremias Maerki


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


table overflow onto page 2 into specific region

Posted by "Chakravarty, Abhishek" <Ab...@accidentfund.com>.
Hi

Is there a way to ensure in my stylesheet that a table overflows into
second page into the area which is prespecified for it only?

As in I have the page setup as the header followed by a table followed
by footer. But if the table overflows then is it possible to have it
onto the second page in the same region so that my second page would now
look like header followed by table (the content of which is from the
previous page table overflow) and then the footer.

Also none of the info is static i.e. headers and footers can change
depending on the content being pulled in from the xml (but the table
layout remains the same).

Regards
Abhishek

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


AW: AW: AW: Usage of Font.getWordWidth()

Posted by Georg Datterl <ge...@geneon.de>.
Hi Jeremias,

Now the result seems quite correct for Helvetica. But not for my unicode font. I guess, the values from the xml are used but further details next year. I wish everybody on this list Merry Christmas and a Happy New Year!

Regards,
 
Georg Datterl
 
------ Kontakt ------
 
Georg Datterl
 
Geneon media solutions gmbh
Gutenstetter Straße 8a
90449 Nürnberg
 
HRB Nürnberg: 17193
Geschäftsführer: Yong-Harry Steiert 

Tel.: 0911/36 78 88 - 26
Fax: 0911/36 78 88 - 20
 
www.geneon.de
 
Weitere Mitglieder der Willmy MediaGroup:
 
IRS Integrated Realization Services GmbH:    www.irs-nbg.de 
Willmy PrintMedia GmbH:                            www.willmy.de
Willmy Consult & Content GmbH:                 www.willmycc.de 
-----Ursprüngliche Nachricht-----
Von: Jeremias Maerki [mailto:dev@jeremias-maerki.ch] 
Gesendet: Donnerstag, 18. Dezember 2008 14:20
An: fop-users@xmlgraphics.apache.org
Betreff: Re: AW: AW: Usage of Font.getWordWidth()

FOP's internal unit is millipoints. Set fontSize in millipoints and the results will be more useful.

On 18.12.2008 13:21:39 Georg Datterl wrote:
> Hi Jeremias,
> 
> I now have this code: 
> 
> FopFactory fopFactory = FopFactory.newInstance(); 
> fopFactory.setUserConfig(new File("fonts/fop.xconf")); FOUserAgent 
> foUserAgent = fopFactory.newFOUserAgent(); RendererFactory rf = new 
> RendererFactory(); Renderer r = rf.createRenderer(foUserAgent, 
> "application/pdf"); PDFRenderer pr = (PDFRenderer)r; 
> PDFRendererConfigurator prc = new 
> PDFRendererConfigurator(foUserAgent);
> prc.configure(r);
> pr.setupFontInfo(new FontInfo());
> FontInfo info = pr.getFontInfo();
> FontSetup.setup(info);
> //// object before this line can be cached, I assume /////////////// 
> FontTriplet fontTriplet = info.createFontKey(fontName, 
> org.apache.fop.fonts.Font.STYLE_NORMAL, 
> org.apache.fop.fonts.Font.WEIGHT_NORMAL ); org.apache.fop.fonts.Font f 
> = info.getFontInstance(fontTriplet, fontSize); 
> f.getWordWidth("myText");
> 
> But: 
> f.getWordWidth("aaaaa") and f.getWordWidth("kkkkk") give the same result (15) although the k's take more space (7 k's = 8 a's).
> 
> Regards,
>  
> Georg Datterl
>  



Jeremias Maerki


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


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


Re: AW: AW: Usage of Font.getWordWidth()

Posted by Jeremias Maerki <de...@jeremias-maerki.ch>.
FOP's internal unit is millipoints. Set fontSize in millipoints and the
results will be more useful.

On 18.12.2008 13:21:39 Georg Datterl wrote:
> Hi Jeremias,
> 
> I now have this code: 
> 
> FopFactory fopFactory = FopFactory.newInstance();
> fopFactory.setUserConfig(new File("fonts/fop.xconf"));
> FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
> RendererFactory rf = new RendererFactory();
> Renderer r = rf.createRenderer(foUserAgent, "application/pdf");
> PDFRenderer pr = (PDFRenderer)r;
> PDFRendererConfigurator prc = new PDFRendererConfigurator(foUserAgent);
> prc.configure(r);
> pr.setupFontInfo(new FontInfo());
> FontInfo info = pr.getFontInfo();
> FontSetup.setup(info);
> //// object before this line can be cached, I assume ///////////////
> FontTriplet fontTriplet = info.createFontKey(fontName, org.apache.fop.fonts.Font.STYLE_NORMAL, org.apache.fop.fonts.Font.WEIGHT_NORMAL );
> org.apache.fop.fonts.Font f = info.getFontInstance(fontTriplet, fontSize); 
> f.getWordWidth("myText");
> 
> But: 
> f.getWordWidth("aaaaa") and f.getWordWidth("kkkkk") give the same result (15) although the k's take more space (7 k's = 8 a's).
> 
> Regards,
>  
> Georg Datterl
>  



Jeremias Maerki


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


AW: AW: Usage of Font.getWordWidth()

Posted by Georg Datterl <ge...@geneon.de>.
> f.getWordWidth("aaaaa") and f.getWordWidth("kkkkk") give the same result (15) although the k's take more space (7 k's = 8 a's). 

And the reason is:

org.apache.fop.fonts.Font.getWidth(int charnum) {
	return (metric.getWidth(charnum, fontSize) / 1000);
}
metric.getWidth gives a quite fine value (for Helvetica): 3000 for k, 3336 for a. And then this method kills the interesting last three digits and returns 3 in any case. Is this really necessary? And is this still the correct mailing list? And why is Outlook killing the line breaks? I'd not bother to read this stuff if it were not my own.

Regards,
 
Georg Datterl
 
------ Kontakt ------
 
Georg Datterl
 
Geneon media solutions gmbh
Gutenstetter Straße 8a
90449 Nürnberg
 
HRB Nürnberg: 17193
Geschäftsführer: Yong-Harry Steiert 

Tel.: 0911/36 78 88 - 26
Fax: 0911/36 78 88 - 20
 
www.geneon.de
 
Weitere Mitglieder der Willmy MediaGroup:
 
IRS Integrated Realization Services GmbH:    www.irs-nbg.de 
Willmy PrintMedia GmbH:                            www.willmy.de
Willmy Consult & Content GmbH:                 www.willmycc.de 
-----Ursprüngliche Nachricht-----
Von: Georg Datterl [mailto:georg.datterl@geneon.de] 
Gesendet: Donnerstag, 18. Dezember 2008 13:22
An: fop-users@xmlgraphics.apache.org
Betreff: AW: AW: Usage of Font.getWordWidth()

Hi Jeremias,

I now have this code: 

FopFactory fopFactory = FopFactory.newInstance(); fopFactory.setUserConfig(new File("fonts/fop.xconf")); FOUserAgent foUserAgent = fopFactory.newFOUserAgent(); RendererFactory rf = new RendererFactory(); Renderer r = rf.createRenderer(foUserAgent, "application/pdf"); PDFRenderer pr = (PDFRenderer)r; PDFRendererConfigurator prc = new PDFRendererConfigurator(foUserAgent);
prc.configure(r);
pr.setupFontInfo(new FontInfo());
FontInfo info = pr.getFontInfo();
FontSetup.setup(info);
//// object before this line can be cached, I assume /////////////// FontTriplet fontTriplet = info.createFontKey(fontName, org.apache.fop.fonts.Font.STYLE_NORMAL, org.apache.fop.fonts.Font.WEIGHT_NORMAL ); org.apache.fop.fonts.Font f = info.getFontInstance(fontTriplet, fontSize); f.getWordWidth("myText");

But: 
f.getWordWidth("aaaaa") and f.getWordWidth("kkkkk") give the same result (15) although the k's take more space (7 k's = 8 a's).

Regards,
 
Georg Datterl
 
------ Kontakt ------
 
Georg Datterl
 
Geneon media solutions gmbh
Gutenstetter Straße 8a
90449 Nürnberg
 
HRB Nürnberg: 17193
Geschäftsführer: Yong-Harry Steiert 

Tel.: 0911/36 78 88 - 26
Fax: 0911/36 78 88 - 20
 
www.geneon.de
 
Weitere Mitglieder der Willmy MediaGroup:
 
IRS Integrated Realization Services GmbH:    www.irs-nbg.de 
Willmy PrintMedia GmbH:                            www.willmy.de
Willmy Consult & Content GmbH:                 www.willmycc.de 

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


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


AW: AW: Usage of Font.getWordWidth()

Posted by Georg Datterl <ge...@geneon.de>.
Hi Jeremias,

I now have this code: 

FopFactory fopFactory = FopFactory.newInstance();
fopFactory.setUserConfig(new File("fonts/fop.xconf"));
FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
RendererFactory rf = new RendererFactory();
Renderer r = rf.createRenderer(foUserAgent, "application/pdf");
PDFRenderer pr = (PDFRenderer)r;
PDFRendererConfigurator prc = new PDFRendererConfigurator(foUserAgent);
prc.configure(r);
pr.setupFontInfo(new FontInfo());
FontInfo info = pr.getFontInfo();
FontSetup.setup(info);
//// object before this line can be cached, I assume ///////////////
FontTriplet fontTriplet = info.createFontKey(fontName, org.apache.fop.fonts.Font.STYLE_NORMAL, org.apache.fop.fonts.Font.WEIGHT_NORMAL );
org.apache.fop.fonts.Font f = info.getFontInstance(fontTriplet, fontSize); 
f.getWordWidth("myText");

But: 
f.getWordWidth("aaaaa") and f.getWordWidth("kkkkk") give the same result (15) although the k's take more space (7 k's = 8 a's).

Regards,
 
Georg Datterl
 
------ Kontakt ------
 
Georg Datterl
 
Geneon media solutions gmbh
Gutenstetter Straße 8a
90449 Nürnberg
 
HRB Nürnberg: 17193
Geschäftsführer: Yong-Harry Steiert 

Tel.: 0911/36 78 88 - 26
Fax: 0911/36 78 88 - 20
 
www.geneon.de
 
Weitere Mitglieder der Willmy MediaGroup:
 
IRS Integrated Realization Services GmbH:    www.irs-nbg.de 
Willmy PrintMedia GmbH:                            www.willmy.de
Willmy Consult & Content GmbH:                 www.willmycc.de 

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


Re: AW: Usage of Font.getWordWidth()

Posted by Jeremias Maerki <de...@jeremias-maerki.ch>.
On 17.12.2008 18:14:21 Georg Datterl wrote:
> Hi Jeremias,
> 
> > Uhm, why would you want to do such a thing in an XSL-FO environment?
> 
> Because I have a table with a variable number of columns and want to
> implement vertical splitting by calculating the width of all cell
> entries, get max width per column and see how much I can fit on the
> page. The other columns move to a new table below. Since I'm quite greedy with
> space, I need a result as close to the real print result as possible.
> java FontMetrics is not good enough (and 

ah, ok. Java Font Metrics are usually pretty close if you use the right
ones (there are low-resolution (pixel-oriented) and high-resolution
metrics). But they are still not quite good enough for doing
high-quality layout.

> > Anyway, you need access to the FontInfo object that is attached to
> > the PDFRenderer (somehow). If you set up the PDFRenderer yourself 
> > and set it using FOUserAgent.setRendererOverride(), that could 
> > work. From there, you can get a FontTriplet using FontInfo.fontLookup(). 
> > With a FontTriplet you can get a Font object using FontInfo.getFontInstance().
> 
> Well, I do have a FopFactory. But PDFRenderer has a default constructor.
> So has FontInfo. But I'm quite sure I'm thinking myself into
> incorrectly initialized territory here. 
> 
> I tried 
> 
> FontInfo info = new FontInfo();
> FontSetup.setup(info);
> FontTriplet unicode = info.createFontKey("arial unicode ms", org.apache.fop.fonts.Font.STYLE_NORMAL, org.apache.fop.fonts.Font.WEIGHT_NORMAL );
> org.apache.fop.fonts.Font funicode = info.getFontInstance(unicode, fontSize);

That won't work. You'll only have default base 14 fonts. The "Arial
Unicode MS" will certainly be replaced with "Helvetica" so you might not
have the right metrics.

> That gives me a nice looking FontTriplet, and the FontInfo object has
> internal Fonts set, but only default fonts, no fonts from fop.xconf.
> Are these fonts somewhere in PDFRenderer? 

Yes, PDFRenderer's FontInfo object gets configured through the
PDFRendererConfigurator. See RendererFactory, too. In the end, you can
get the FontInfo object using pdfRenderer.getFontInfo(). But the
configuration most probably has to occur on the PDFRenderer instance
you have to pass in through the renderer override I mentioned before.

> > The units from the Font object will most likely be millipoints 
> > (a 1000th of a point, our internal unit). You can use UnitConv to convert
> > those.
> 
> No problem, I work in pt anyway.
> 
> Mit freundlichen Grüßen
>  
> Georg Datterl
>  
> ------ Kontakt ------
>  
> Georg Datterl
>  
> Geneon media solutions gmbh
> Gutenstetter Straße 8a
> 90449 Nürnberg
>  
> HRB Nürnberg: 17193
> Geschäftsführer: Yong-Harry Steiert 
> 
> Tel.: 0911/36 78 88 - 26
> Fax: 0911/36 78 88 - 20
>  
> www.geneon.de
>  
> Weitere Mitglieder der Willmy MediaGroup:
>  
> IRS Integrated Realization Services GmbH:    www.irs-nbg.de 
> Willmy PrintMedia GmbH:                            www.willmy.de
> Willmy Consult & Content GmbH:                 www.willmycc.de 
> -----Ursprüngliche Nachricht-----
> Von: Jeremias Maerki [mailto:dev@jeremias-maerki.ch] 
> Gesendet: Mittwoch, 17. Dezember 2008 17:32
> An: fop-users@xmlgraphics.apache.org
> Betreff: Re: Usage of Font.getWordWidth()
> 
> Uhm, why would you want to do such a thing in an XSL-FO environment?
> 
> Anyway, you need access to the FontInfo object that is attached to the PDFRenderer (somehow). If you set up the PDFRenderer yourself and set it using FOUserAgent.setRendererOverride(), that could work. From there, you can get a FontTriplet using FontInfo.fontLookup(). With a FontTriplet you can get a Font object using FontInfo.getFontInstance().
> The units from the Font object will most likely be millipoints (a 1000th of a point, our internal unit). You can use UnitConv to convert those.
> Sorry, I don't have a recipe ready at hand. I've never had to do something like that from outside FOP.
> 
> On 17.12.2008 17:06:46 Georg Datterl wrote:
> > Hi everybody,
> > 
> > Maybe it's too late in the year for my brain to work properly, but I 
> > want to call Font.getWordWidth(String) to find out how much space a 
> > string will take in the finished PDF, but I can't figure out how I can 
> > get the Font object given the values for font-family and font-size 
> > (which are the values I later write into the fo-file).
> > 
> > The fonts are there and registered correctly in my fop.xconf, are used 
> > when generating the PDF and generally work fine. I also tried to read 
> > through the source code, but came from Font to FontMetrics to FontInfo 
> > to CommonFont to CompleteConfusion.
> > 
> > Second question: When I finally get a result, what unit would that be in?
> > 
> > Regards,
> >  
> > Georg Datterl
> >  




Jeremias Maerki


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


AW: Usage of Font.getWordWidth()

Posted by Georg Datterl <ge...@geneon.de>.
Hi Jeremias,

> Uhm, why would you want to do such a thing in an XSL-FO environment?

Because I have a table with a variable number of columns and want to implement vertical splitting by calculating the width of all cell entries, get max width per column and see how much I can fit on the page. The other columns move to a new table below. Since I'm quite greedy with space, I need a result as close to the real print result as possible. java FontMetrics is not good enough (and 

> Anyway, you need access to the FontInfo object that is attached to
> the PDFRenderer (somehow). If you set up the PDFRenderer yourself 
> and set it using FOUserAgent.setRendererOverride(), that could 
> work. From there, you can get a FontTriplet using FontInfo.fontLookup(). 
> With a FontTriplet you can get a Font object using FontInfo.getFontInstance().

Well, I do have a FopFactory. But PDFRenderer has a default constructor. So has FontInfo. But I'm quite sure I'm thinking myself into incorrectly initialized territory here. 

I tried 

FontInfo info = new FontInfo();
FontSetup.setup(info);
FontTriplet unicode = info.createFontKey("arial unicode ms", org.apache.fop.fonts.Font.STYLE_NORMAL, org.apache.fop.fonts.Font.WEIGHT_NORMAL );
org.apache.fop.fonts.Font funicode = info.getFontInstance(unicode, fontSize);

That gives me a nice looking FontTriplet, and the FontInfo object has internal Fonts set, but only default fonts, no fonts from fop.xconf. Are these fonts somewhere in PDFRenderer? 

> The units from the Font object will most likely be millipoints 
> (a 1000th of a point, our internal unit). You can use UnitConv to convert
> those.

No problem, I work in pt anyway.

Mit freundlichen Grüßen
 
Georg Datterl
 
------ Kontakt ------
 
Georg Datterl
 
Geneon media solutions gmbh
Gutenstetter Straße 8a
90449 Nürnberg
 
HRB Nürnberg: 17193
Geschäftsführer: Yong-Harry Steiert 

Tel.: 0911/36 78 88 - 26
Fax: 0911/36 78 88 - 20
 
www.geneon.de
 
Weitere Mitglieder der Willmy MediaGroup:
 
IRS Integrated Realization Services GmbH:    www.irs-nbg.de 
Willmy PrintMedia GmbH:                            www.willmy.de
Willmy Consult & Content GmbH:                 www.willmycc.de 
-----Ursprüngliche Nachricht-----
Von: Jeremias Maerki [mailto:dev@jeremias-maerki.ch] 
Gesendet: Mittwoch, 17. Dezember 2008 17:32
An: fop-users@xmlgraphics.apache.org
Betreff: Re: Usage of Font.getWordWidth()

Uhm, why would you want to do such a thing in an XSL-FO environment?

Anyway, you need access to the FontInfo object that is attached to the PDFRenderer (somehow). If you set up the PDFRenderer yourself and set it using FOUserAgent.setRendererOverride(), that could work. From there, you can get a FontTriplet using FontInfo.fontLookup(). With a FontTriplet you can get a Font object using FontInfo.getFontInstance().
The units from the Font object will most likely be millipoints (a 1000th of a point, our internal unit). You can use UnitConv to convert those.
Sorry, I don't have a recipe ready at hand. I've never had to do something like that from outside FOP.

On 17.12.2008 17:06:46 Georg Datterl wrote:
> Hi everybody,
> 
> Maybe it's too late in the year for my brain to work properly, but I 
> want to call Font.getWordWidth(String) to find out how much space a 
> string will take in the finished PDF, but I can't figure out how I can 
> get the Font object given the values for font-family and font-size 
> (which are the values I later write into the fo-file).
> 
> The fonts are there and registered correctly in my fop.xconf, are used 
> when generating the PDF and generally work fine. I also tried to read 
> through the source code, but came from Font to FontMetrics to FontInfo 
> to CommonFont to CompleteConfusion.
> 
> Second question: When I finally get a result, what unit would that be in?
> 
> Regards,
>  
> Georg Datterl
>  



Jeremias Maerki


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


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


Re: Usage of Font.getWordWidth()

Posted by Jeremias Maerki <de...@jeremias-maerki.ch>.
Uhm, why would you want to do such a thing in an XSL-FO environment?

Anyway, you need access to the FontInfo object that is attached to the
PDFRenderer (somehow). If you set up the PDFRenderer yourself and set it
using FOUserAgent.setRendererOverride(), that could work. From there,
you can get a FontTriplet using FontInfo.fontLookup(). With a
FontTriplet you can get a Font object using FontInfo.getFontInstance().
The units from the Font object will most likely be millipoints (a 1000th
of a point, our internal unit). You can use UnitConv to convert those.
Sorry, I don't have a recipe ready at hand. I've never had to do
something like that from outside FOP.

On 17.12.2008 17:06:46 Georg Datterl wrote:
> Hi everybody,
> 
> Maybe it's too late in the year for my brain to work properly, but I
> want to call Font.getWordWidth(String) to find out how much space a
> string will take in the finished PDF, but I can't figure out how I can
> get the Font object given the values for font-family and font-size
> (which are the values I later write into the fo-file). 
> 
> The fonts are there and registered correctly in my fop.xconf, are used
> when generating the PDF and generally work fine. I also tried to read
> through the source code, but came from Font to FontMetrics to FontInfo
> to CommonFont to CompleteConfusion. 
> 
> Second question: When I finally get a result, what unit would that be in?
> 
> Regards,
>  
> Georg Datterl
>  



Jeremias Maerki


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