[iText-questions] Encoding used by DefaultFontMapper

2002-09-03 Thread Erwin Achermann

Hi iText'ers,

I came across the following problem: printing Unicode with (Graphics2D)g.drawString() 
works fine on screen for all unicodes, but not using PdfGraphics2D class. I figured 
that this is due to the fact that the DefaultFontMapper used in PdfGraphics2D uses the 
font encoding CP1252. No means are provided to set the font encoding explicitly. I 
tried to write my own DefaultFontManager (which had the encoding for the basefonts set 
to IDENTITY_H or IDENTITY_V [what's the difference or reason for the two identities, 
anyhow]) but this leads (run the attached example) to the following exception, 
(encoding in DefaultFontMapper is set to BaseFont.IDENTITY_H) 

ExceptionConverter: com.lowagie.text.DocumentException: Identity-H
at com.lowagie.text.pdf.Type1Font.init(Type1Font.java:252)
at com.lowagie.text.pdf.BaseFont.createFont(BaseFont.java:360)
at com.lowagie.text.pdf.BaseFont.createFont(BaseFont.java:313)
at com.lowagie.text.pdf.DefaultFontMapper.awtToPdf(DefaultFontMapper.java:125)
at com.lowagie.text.pdf.PdfGraphics2D.getCachedBaseFont(PdfGraphics2D.java:514)
at com.lowagie.text.pdf.PdfGraphics2D.setFont(PdfGraphics2D.java:508)
at com.lowagie.text.pdf.PdfGraphics2D.init(PdfGraphics2D.java:140)
at com.lowagie.text.pdf.PdfContentByte.createGraphics(PdfContentByte.java:2168)
at com.lowagie.text.pdf.PdfContentByte.createGraphics(PdfContentByte.java:2157)
at DerivedScreen.init(DerivedScreen.java:50)
at DerivedScreen.main(DerivedScreen.java:72)


This stack trace raises several questions: 
Why is it trying to create a Type1Font? I'm only using arial.ttf, don't I? 
What would be the proposed way to give the user a chance for changing the encoding? 
The best (most convenient for the user) would be, if PdfGraphics2D.drawString() would 
switch encoding (and associated BaseFont) if a Unicode character outside the current 
encoding is encountered. Are there any means for that? 

Thanks for any help and cheers
Erwin








DerivedScreen.java
Description: DerivedScreen.java


[iText-questions] Images in running text

2002-07-02 Thread Erwin Achermann

Hi *, 

I'm trying to put little icons into running text, they sometimes are higher than the 
font, and they sometimes hang lower then the lowest character. Can somebody verify 
that such images, wrapped in chunks (new Chunk(img, 0,0) and added to one long lasting 
Paragraph, clash with the preceding and following lines of text? Maybe I have broken 
something, but I cannot find the place where the maximal height of a line is computed 
(and the 'leading of the current line' is adjusted). Put the other way, how can I 
ensure that such an 'Image in a Chunk' doesn't clash with other lines of text? 

Thanks for any hint, Cheers
Erwin 


---
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
___
iText-questions mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/itext-questions



RE: [iText-questions] Current CVS

2002-06-24 Thread Erwin Achermann

Hi, i proposed this change when implementing the table-in-colspanned cells feature. 
This method is so 'internal' that no one outside the iText package should need to call 
it. It should be ensured that iText calls it when necessary internally. If the writers 
beeing in sub-packages cannot access it, then i missunderstood the term 'package 
protected' and it is indeed a bug then, however my pdfwriter accesses it correctly... 
and besides, i don't even know wether this particular change is due to my proposals :) 

Cheers
Erwin

 -Original Message-
 From: Mark Hall [mailto:[EMAIL PROTECTED]]
 Sent: Saturday, June 22, 2002 9:18 AM
 To: Bruno
 Cc: itext-questions
 Subject: [iText-questions] Current CVS
 
 
 -BEGIN PGP SIGNED MESSAGE-
 Hash: SHA1
 
 Hi
 
 I've got a problem with the current CVS version. The table object used
 to have a public void complete() method. In the current version this
 method is specified as void complete(). Unfortunately all Writers
 depend on this method being public, because they call it before
 processing Tables.
 I'm not sure whether there's been a design change here or if this is
 just a bug.
 
 Greetings,
 Mark
 - --
 The cause of the problem is:
 Webmasters kidnapped by evil cult.
 
 My GPG key is available at:
 http://www.edu.uni-klu.ac.at/~mhall/files/MarkHall.asc
 -BEGIN PGP SIGNATURE-
 Version: GnuPG v1.0.7 (GNU/Linux)
 Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
 
 iQEVAwUBPRQkmkks8txBCICQAQIsWwgAjbsBki1LZ25MWEYPQmKNTVpH0uQdh5OB
 zedK2Ptu9xNFZSPc9HARN0xMDpNwm4Y+KEF225iToaOoaTf1XBQ6km8299zQrHl4
 LzTrKf1TkslnhNvlYR3NaifxuI5qwiDI4EavLoBieQibjSBbrR8ETFXi1woJp1Kb
 DzNqdqvPtV4oNlAcmTYPfY6jcTeYAt/XWBGOuY35LMcz1Q+Aseqmr7ZVWCyihNvR
 pCwSo9sYWdoSFb5lDy6WWXzNspoqLs51G+qPoM4idLV2QqffR5EqIm20rXLrxU2r
 HhG7jYjhxDK5MSLw64+gzj26bBZT+KJOFPX7K7N1pJu99WU1tHSJDA==
 =X4Ag
 -END PGP SIGNATURE-
 
 
 
 ---
 Sponsored by:
 ThinkGeek at http://www.ThinkGeek.com/
 ___
 iText-questions mailing list
 [EMAIL PROTECTED]
 https://lists.sourceforge.net/lists/listinfo/itext-questions
 


---
Sponsored by:
ThinkGeek at http://www.ThinkGeek.com/
___
iText-questions mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/itext-questions



[iText-questions] DefaultFontMapper.insertDirectory is (too) slow

2002-06-14 Thread Erwin Achermann

Hi Bruno,

we are facing the problem, that inserDirectory processes 250 font files, consuming 
more time than acceptable (8 seconds). I was browsing to code and observed that for 
each font file a basefont is created. This includes loading mapping tables (which is 
what we need in the first place) but this also include construction of kerning tables, 
and numerous other datastructure: 

TrueTypeFont.process() 
...
fontName = getBaseFont();
fullName = getNames(4); //full name
familyName = getNames(1); //family name
fillTables();
readGlyphWidths();
readCMaps();
readKerning();
...

I would propose that these font information are only loaded when the font is actually 
needed in the document, and thus speeding up the insertDirectory-call. A lazy Font 
construction, if you wish. Is this problem recognized, planned to be solved or am I 
completely mistaken here? 

Cheers
Erwin


___

Don't miss the 2002 Sprint PCS Application Developer's Conference
August 25-28 in Las Vegas - 
http://devcon.sprintpcs.com/adp/index.cfm?source=osdntextlink

___
iText-questions mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/itext-questions



RE: [iText-questions] DefaultFontMapper.insertDirectory is (too) slow

2002-06-14 Thread Erwin Achermann

The problem with this is that the file ist completly read in to generate a new 
basefont. 
Because the FontFactory.createFont(...) calls 
new TrueTypeFont(filename, ...) and similar for other file types, only to get the 
names of the font 
String names[][] = bf.getFullFontName(); 
and then bf=null; again. 

I would hope that a  FontMapper.getFullFontName(filename) could be implemented without 
really building a new basefont, but only by peeking into the file. 

How difficult would that be? 

Cheers
Erwin



 -Original Message-
 From: Paulo Soares [mailto:[EMAIL PROTECTED]]
 Sent: Friday, June 14, 2002 12:34 PM
 To: Erwin Achermann; iText ML (E-Mail)
 Subject: RE: [iText-questions] DefaultFontMapper.insertDirectory is
 (too) slow
 
 
 If you just need a couple of fonts use this class (untested):
 
 import com.lowagie.text.pdf.*;
 
 public class SpeedFontMapper extends DefaultFontMapper {
 
 /** Inserts a single font into the map. The encoding
  * will be CODEBaseFont.CP1252/CODE but can be
  * changed later.
  * @param file the font file name
  * @return CODEtrue/CODE if the font was inserted
  */
 public boolean insertSingleFont(String file) {
 String name = file.toLowerCase();
 BaseFont bf = null;
 try {
 if (name.endsWith(.ttf) || name.endsWith(.afm)) {
 bf = BaseFont.createFont(file, BaseFont.CP1252, false,
 BaseFont.NOT_CACHED, null, null);
 String names[][] = bf.getFullFontName();
 bf = null;
 insertNames(names, file);
 }
 else if (name.endsWith(.ttc)) {
 String ttcs[] = BaseFont.enumerateTTCNames(file);
 for (int j = 0; j  ttcs.length; ++j) {
 String nt = file + , + (j + 1);
 bf = BaseFont.createFont(nt, 
 BaseFont.CP1252, false,
 BaseFont.NOT_CACHED, null, null);
 String names[][] = bf.getFullFontName();
 bf = null;
 insertNames(names, nt);
 }
 }
 }
 catch (Exception e) {
 return false;
 }
 return true;
 }
 }
 
 Best Regards,
 Paulo Soares
 
  -Original Message-
  From:   Erwin Achermann [SMTP:[EMAIL PROTECTED]]
  Sent:   Friday, June 14, 2002 11:05
  To: iText ML (E-Mail)
  Subject:RE: [iText-questions] 
 DefaultFontMapper.insertDirectory is
  (too) slow
  
  Paulo, 
  it was (is) my first attempt to remedy for the problem by 
 making one only
  instance of the DefaultFontMapper in our application. And 
 every thread
  uses this one. But still it takes too long for the 
 DefaultFontMapper to
  read in our font directory. We cannot afford the time on 
 app startup, and
  even less on the first 'toPdf'-action. All I'd expect from 
 the FontMapper
  is to build a table mapping font-name and -attributes to 
 the appropriate
  font-file, so that the fontfactory later will know which 
 file to load
  (avoiding a scan of the font directory in each
  FontFactory.getFont()-call). But the DefaultFontMapper does 
 way more than
  that, apparently it instantiates each possible font... and 
 then throws
  most of each instantiated font away again. 
  
  Cheers
  Erwin
  
   -Original Message-
   From: Paulo Soares [mailto:[EMAIL PROTECTED]]
   Sent: Friday, June 14, 2002 11:28 AM
   To: Erwin Achermann; iText ML (E-Mail)
   Subject: RE: [iText-questions] 
 DefaultFontMapper.insertDirectory is
   (too) slow
   
   
   There's no problem here. First of all the class 
 DefaultFontMapper is a
   generic class that may not be suitable for all the cases. You 
   can sub-class
   it or create a new one if special capabilities are needed.
   You only have to create an instance of it once and then use 
   it everywhere in
   other threads; I don't think the load time is that important 
   in this case.
   Lazy evaluation would require scanning the directory and 
   reading all the
   files to find the font, saving no time in the process.
   
   Best Regards,
   Paulo Soares
   
-Original Message-
From:   Erwin Achermann [SMTP:[EMAIL PROTECTED]]
Sent:   Friday, June 14, 2002 10:08
To: iText ML (E-Mail)
Subject:[iText-questions] 
   DefaultFontMapper.insertDirectory is (too)
slow

Hi Bruno,

we are facing the problem, that inserDirectory processes 
   250 font files,
consuming more time than acceptable (8 seconds). I was 
   browsing to code
and observed that for each font file a basefont is created. 
   This includes
loading mapping tables (which is what we need in the first 
   place) but this
also include construction of kerning tables, and numerous other
datastructure: 

TrueTypeFont.process() 
...
fontName = getBaseFont();
fullName = getNames(4); //full name

RE: [iText-questions] doc.close() closing OutputStream

2002-05-28 Thread Erwin Achermann

The rule is actually very simple: 
if the user opened the stream and passed it to the library, then its the _users_ 
responsibility to close that stream, and analogously, if the library opened the stream 
i would expect it to close it as well. Any unbalance open-close-stream calls disturb 
my feelings ;) 

Cheers
Erwin

 -Original Message-
 From: Bruno Lowagie [mailto:[EMAIL PROTECTED]]
 Sent: Tuesday, May 28, 2002 4:20 PM
 To: [EMAIL PROTECTED]
 Subject: RE: [iText-questions] doc.close() closing OutputStream
 
 
 Quoting Roman Novichenok [EMAIL PROTECTED]:
 
  Thought it would be useful to have the option of not 
 closing the stream
  within iText library.
 
 In some cases, it would be useful. You are right about that.
 You were also right that changing the original method is not
 a good solution: it would break the functionality for all other
 iText users and applications.
 
 Your question to add a new method was justified, but since there
 is a simple way to solve the problem outside the library, adding
 a new method is no priority. For the moment I am working on other
 projects, so I leave iText development to Paulo and some other
 developers for a while.
 
 I am saving all kind of mails and remarks though, and I will
 take them into account once I decide to take the iText work up
 again (but I really need to do other projects now in order to
 learn about new tools, technologies, programming standards,...).
 
 Bruno
 
 ___
 
 Don't miss the 2002 Sprint PCS Application Developer's Conference
 August 25-28 in Las Vegas -- http://devcon.sprintpcs.com/adp/index.cfm
 
 ___
 iText-questions mailing list
 [EMAIL PROTECTED]
 https://lists.sourceforge.net/lists/listinfo/itext-questions
 

___

Don't miss the 2002 Sprint PCS Application Developer's Conference
August 25-28 in Las Vegas -- http://devcon.sprintpcs.com/adp/index.cfm

___
iText-questions mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/itext-questions



[iText-questions] FontMapper and FontFactory

2002-05-27 Thread Erwin Achermann

Dear iTexters,

I was using the Fontmapper in conjunction with PdfGraphics2D. In an initialization I 
registered all system fonts to the Fontmapper and henceforth could use all my locally 
installed fonts. Worked like a charm! 

DefaultFontMapper fm = new DefaultFontMapper();
fm.insertDirectory(sun.awt.font.NativeFontWrapper.getFontPath(true));
java.awt.Graphics2D g = pdfWriter.getDirectContent().createGraphics2D(width, 
height, fm);

Nice job. 
But now I come to the situation where I want to translate an XML file into Pdf. The 
XML contains a tag like font family=Arial bold=true size=13 italic=false ... 
   this should boil down to adding a chunk(,attributes) which loads the arialbf.ttf 
font. Is there a way to use font mapper for easing this, too? 

Thanks and Cheers
Erwin

___

Don't miss the 2002 Sprint PCS Application Developer's Conference
August 25-28 in Las Vegas -- http://devcon.sprintpcs.com/adp/index.cfm

___
iText-questions mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/itext-questions



[iText-questions] PdfGraphics2D: how to get the text width

2002-04-26 Thread Erwin Achermann

Hi all, 

I am using PdfGraphics2D in place of an old PrinterGraphics2D. In my code I have the 
following snippet:

 width = g2d.getFontMetrics().getStringBounds(txt, flushIndex, flushIndex + flushLen, 
g2d).getWidth();

to compute the horizontal extension of some string. This seems to be the culprit in my 
case. It seems as if this sequence used on PdfGraphics2D is not yielding the correct 
width. Can you affirm this observation? Is there a more elegant way to find out the 
exact width of some rendered text? As a workaround I extended my own PdfGraphics2D by 
the method:

public double getWidthPoint(java.lang.String s) {
return (double)baseFont.getWidthPoint(s,fontSize);
}

and my code snipped reads, now: 

// width = g2d.getFontMetrics().getStringBounds(txt, flushIndex, flushIndex + 
flushLen, g2d).getWidth();
java.lang.String tmp = new java.lang.String(txt,flushIndex, flushLen);
PdfGraphics2D pg = (PdfGraphics2D)g2d;
width = pg.getWidthPoint(tmp);

In my cases this fixes the problem. But I'm not totally calm, because the idea of 
PdfGraphics2D was to have be able to use it as any other Graphics2D Object given 
this situation, that goal is not attained :( Also my PdfGraphics2D.getWidthPoint(s) is 
not taking into consideration that the font itself may carry an AffineTransform 
different from identity, which will of course affect the resulting width. Any better 
solutions?

Thanks and Cheers
Erwin

___
iText-questions mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/itext-questions



RE: [iText-questions] PdfGraphics2D: unbalanced save/Restore Exception

2002-04-24 Thread Erwin Achermann

Thanks Paulo, 
for pointing me gently enough to my own error. I fixed it and it works nicely now. 

;) 

Cheers
Erwin

 -Original Message-
 From: Paulo Soares [mailto:[EMAIL PROTECTED]]
 Subject: RE: [iText-questions] PdfGraphics2D: unbalanced save/Restore
 Exception
 
 
 Last g to be created is not used or disposed.
 
 Best Regards,
 Paulo Soares
 

___
iText-questions mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/itext-questions



[iText-questions] PdfGraphics2D: unbalanced save/Restore Exception

2002-04-22 Thread Erwin Achermann

Hi iTexters, 

during the last week I was doing exactly a PdfGraphics class as you seem to have done. 
I was only implementing the features which we currently are using. Especially I was 
cheating with the FontMetrics. Now I realized this morning that you have done a more 
complete implementation in the PdfGraphics2D, reason enough for me to abandom my 
implementation and switch to the far more complete one of iText. But the problem I'm 
observing is show in the following code: 

/**
 * codecreatePdf/code prints a set of pages into the PDF
 * file.
 */
public void createPdf() {
// make an instance of a PdfGraphics Object for the document
DefaultFontMapper fm = new DefaultFontMapper();
java.awt.Graphics2D g = null;

// don't do anything if pageable is null
if (pageable != null) {
// read all fonts recognized be iText in system font path

fm.insertDirectory(sun.awt.font.NativeFontWrapper.getFontPath(true));
   
   
System.out.println(PdfJob.createPdf:  started);
int pages = pageable.getNumberOfPages();
System.out.println(PdfJob.createPdf:  pages to print: 
+pages+\n);

// set pageSize of first page before the document opens!!
float width = 
(float)pageable.getPageFormat(0).getPaper().getWidth();
float height = 
(float)pageable.getPageFormat(0).getPaper().getHeight();
theDocument.setPageSize(new Rectangle(width, height));

// g.setPageSize(pageable.getPageFormat(0));
  theDocument.open();
g = pdfWriter.getDirectContent().createGraphics(width, height, 
fm);

for (int  p = 0;  p  pages ; ++p) {
Printable thePage = pageable.getPrintable(p);
try {
// print! 
thePage.print(g, pageable.getPageFormat(p), p);
System.out.println(PdfJob.createPdf:  page  
+ p +  printed);
if (p  pages-1) {
// next page, please! on its proper 
PageSize 
width = 
(float)pageable.getPageFormat(p+1).getPaper().getWidth();
height = 
(float)pageable.getPageFormat(p+1).getPaper().getHeight();
theDocument.setPageSize(new 
Rectangle(width, height));
} // end of if (p  pages-1)
theDocument.newPage();


// iText-Error!? 
// g.dispose(); // use of dispose leads to a
// unbalanced save/restore exception not 
using
// g.dispose() is producing erroneous PDF:
// Acrobat Reader complains about unmatched
// save/restore commands if the document 
consist
// of Portrait and Landscape format. Acrobat 
Reader
// show one empty additional page if the 
document
// is only one page format

/
g = 
pdfWriter.getDirectContent().createGraphics(width, height, fm);
} catch ( PrinterException e) {
e.printStackTrace();
}
catch(DocumentException de) {
de.printStackTrace();
}
} // end of for (int p = 0; p  pages; p++)
// write the document and clear all references
end();  // = theDocument.close()
} // end of if (pageable) 
} // end createPdf


___
iText-questions mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/itext-questions