Letter-spacing / kerning between words in PDFRenderer

2003-03-12 Thread Joop Vriend
Hi,
To begin with: we use FOP 0.20.4, and this mail is about a partly fix 
for missing letter-spacing/kerning between words in PDF's.

In PDF's produced with FOP compared to PDF's from other an other source, 
we noticed that FOP doesn't apply kerning (letter-spacing) to spaces 
between words, most obviously at the end of sentences. I.e., no kerning 
is applied to the character pairs

word-characterspace  (for example, . ) and
spaceword-character  (for example,  V).
The cause, or in any case, the place where it can (partly?) be fixed, 
can be found in the method renderWordArea(WordArea area) in 
PDFRenderer.java.

The latter case (spaceword-character) I could easily fix. All I 
had to do was move the lines

String s;
if (area.getPageNumberID()
!= null) {// this text is a page number, so resolve it
s = idReferences.getPageNumber(area.getPageNumberID());
if (s == null) {
s = ;
}
} else {
s = area.getText();
}
int l = s.length();
up a few lines so they precede 'if (!textOpen || bl != prevWordY)',
and add the following lines in the else-part of
'if (!textOpen || bl != prevWordY)':
if (kerningAvailable  l  0) {
addKerning(pdf, (new Integer((int) ' ')),
 (new Integer((int) area.getFontState().mapChar(s.charAt(0,
   kerning, startText, endText);
}
I've attached the complete code of the method renderWordArea separately.
But..., that's only half of the solution! The first case 
(word-characterspace) is more difficult. I think that in 
renderWordArea we can not be sure that a space is following the word we 
just rendered - or can we? And we don't have the last character of the 
previous word available. Anyone has any ideas?

Regards, Joop Vriend.
/**
 * render inline area to PDF
 *
 * @param area  inline area to render
 */
public void renderWordArea(WordArea area) {
synchronized (_wordAreaPDF) {
StringBuffer pdf = _wordAreaPDF;
pdf.setLength(0);

Hashtable kerning = null;
boolean kerningAvailable = false;

kerning = area.getFontState().getKerning();
if (kerning != null  !kerning.isEmpty()) {
kerningAvailable = true;
}

String name = area.getFontState().getFontName();
int size = area.getFontState().getFontSize();

// This assumes that *all* CIDFonts use a /ToUnicode mapping
boolean useMultiByte = false;
Font f = (Font) area.getFontState().
getFontInfo().getFonts().get(name);
if (f instanceof LazyFont) {
if (((LazyFont) f).getRealFont() instanceof CIDFont) {
useMultiByte = true;
}
} else if (f instanceof CIDFont) {
useMultiByte = true;
}
// String startText = useMultiByte ? FEFF : (;
String startText = useMultiByte ?  : (;
String endText = useMultiByte ?   : ) ;

if ((!name.equals(this.currentFontName))
|| (size != this.currentFontSize)) {
closeText();

this.currentFontName = name;
this.currentFontSize = size;
pdf = pdf.append(/ + name +   + ((float)size / 1000) +  Tf\n);
}

//Do letter spacing (must be outside of [..] TJ)
float letterspacing =
((float) area.getFontState().getLetterSpacing()) / 1000;
if (letterspacing != this.currentLetterSpacing) {
this.currentLetterSpacing = letterspacing;
closeText();
pdf.append(letterspacing).append( Tc\n);
}

PDFColor areaColor = null;
if (this.currentFill instanceof PDFColor) {
areaColor = (PDFColor) this.currentFill;
}

if (areaColor == null || areaColor.red() != (double) area.getRed()
|| areaColor.green() != (double) area.getGreen()
|| areaColor.blue() != (double) area.getBlue()) {

areaColor = new PDFColor((double) area.getRed(),
(double) area.getGreen(),
(double) area.getBlue());

closeText();
this.currentFill = areaColor;
pdf.append(this.currentFill.getColorSpaceOut(true));
}

int rx = this.currentXPosition;
int bl = this.currentYPosition;

addWordLines(area, rx, bl, size, areaColor);

String s;
if (area.getPageNumberID() != null) {// this text is a page number, so 
resolve it
s = idReferences.getPageNumber(area.getPageNumberID());
if (s == null) {
s = ;
}
} else {
s = area.getText();
}

int l = s.length();

if (!textOpen || bl != prevWordY) {
closeText();

pdf.append(1 0 0 1  + (rx / 1000f) +   + (bl / 1000f)
+  Tm [ + startText);
prevWordY = bl;
textOpen = true;
} else {
// express the space between words in thousandths of an em

Re: Letter-spacing / kerning between words in PDFRenderer

2003-03-12 Thread J.Pietschmann
Joop Vriend wrote:
To begin with: we use FOP 0.20.4, and this mail is about a partly fix 
for missing letter-spacing/kerning between words in PDF's.
Well, thanks for the effort but this patch wont make it into FOP
soon, mainly because the layout core doesn't take kerning into
account at all, which needs to be fixed first.
Also, if I understand you correctly, kerning should also be applied
for the case (emDiff  -33000), and text decoration position as well
as the rx and word width should be compensated for the kerning.
But..., that's only half of the solution! The first case 
(word-characterspace) is more difficult.
Not really: keep the text of the last rendered word in lastWord
or something and add the kerning correction to the current rx
respective the space. The lastWord must be cleared if something
special like an image is rendered in between.
J.Pietschmann
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Letter Spacing

2002-11-08 Thread Balajee Chandrasekaran
Hi All,
I want to increase the letter spacing within words in order to shrink or expand 
the word to fit into a specific width.
Is it possible in fop 0.20.4???

thanks in advance.

regards
Balajee Chandrasekaran

Software Engineer
Majesco Software Inc.
Phone : 91-22-5695  Extn No 7911


Change 
Everybody wants to do something to help, But nobody wants to be the first.
Pearl Bailey (1918-1990), American Vocalist




MASTEK
Investing in relationships
In the US, we're called MAJESCO

~~
Opinions expressed in this e-mail are those of the individual and not that of 
Mastek Limited, unless specifically indicated to that effect. Mastek Limited 
does not accept any responsibility or liability for it. This e-mail and 
attachments (if any) transmitted with it are confidential and/or privileged and 
solely for the use of the intended person or entity to which it is addressed. 
Any review, re-transmission, dissemination or other use of or taking of any 
action in reliance upon this information by persons or entities other than the 
intended recipient is prohibited. This e-mail and its attachments have been 
scanned for the presence of computer viruses. It is the responsibility of the 
recipient to run the virus check on e-mails and attachments before opening 
them. If you have received this e-mail in error, kindly delete this e-mail from 
all computers.
~~



RE: Letter Spacing

2002-11-08 Thread Balajee Chandrasekaran
Hi,
I made changes as specified in the example, But I was only able to increase or 
decrease the space between words and not between Characters,
If i have to increase or decrease space between characters what do i need to 
do??

-Original Message-
From: Christian Geisert [mailto:[EMAIL PROTECTED]
Sent: Friday, November 08, 2002 3:34 PM
To: [EMAIL PROTECTED]
Subject: Re: Letter Spacing


Balajee Chandrasekaran wrote:
 Hi All,
 I want to increase the letter spacing within words in order to shrink or 
 expand the word to fit into a specific width.
 Is it possible in fop 0.20.4???

Yes, have a look at docs/examples/fo/textdeko.fo

Christian



MASTEK
Investing in relationships
In the US, we're called MAJESCO

~~
Opinions expressed in this e-mail are those of the individual and not that of 
Mastek Limited, unless specifically indicated to that effect. Mastek Limited 
does not accept any responsibility or liability for it. This e-mail and 
attachments (if any) transmitted with it are confidential and/or privileged and 
solely for the use of the intended person or entity to which it is addressed. 
Any review, re-transmission, dissemination or other use of or taking of any 
action in reliance upon this information by persons or entities other than the 
intended recipient is prohibited. This e-mail and its attachments have been 
scanned for the presence of computer viruses. It is the responsibility of the 
recipient to run the virus check on e-mails and attachments before opening 
them. If you have received this e-mail in error, kindly delete this e-mail from 
all computers.
~~