You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by to...@apache.org on 2001/04/22 23:07:30 UTC

cvs commit: xml-fop/src/org/apache/fop/render/pdf SVGRenderer.java

tore        01/04/22 14:07:30

  Modified:    src/org/apache/fop/render/pdf SVGRenderer.java
  Log:
  Submitted by:	Rafal Maczewski
  Fix for using embedded TrueType fonts in SVG. This fix adds the use of
  FontState.mapChar to ensure that glyphs used in the SVG document are included
  in the embedded font.
  
  Revision  Changes    Path
  1.10      +130 -63   xml-fop/src/org/apache/fop/render/pdf/SVGRenderer.java
  
  Index: SVGRenderer.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/render/pdf/SVGRenderer.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- SVGRenderer.java	2001/03/07 22:52:11	1.9
  +++ SVGRenderer.java	2001/04/22 21:07:28	1.10
  @@ -1,4 +1,4 @@
  -/*-- $Id: SVGRenderer.java,v 1.9 2001/03/07 22:52:11 keiron Exp $ --
  +/*-- $Id: SVGRenderer.java,v 1.10 2001/04/22 21:07:28 tore Exp $ --
   
    ============================================================================
   					 The Apache Software License, Version 1.1
  @@ -2208,66 +2208,101 @@
           			} 
   
   				for (int i = 0; i < str.length(); i++) {
  -						char ch = str.charAt(i);
  -						if ( useMultiByte ) {
  -	               						pdf = pdf.append(Integer.toHexString((int) ch));
  -                						currentX += fs.width(ch) / 1000f;
  -                						inbetween = true;
  -                						addedspace = false;
  -						} else if (ch > 127) {
  -								pdf = pdf.append("\\");
  -								pdf = pdf.append(Integer.toOctalString((int) ch));
  -								currentX += fs.width(ch) / 1000f;
  -								inbetween = true;
  -								addedspace = false;
  -						} else {
  -								switch (ch) {
  -										case '(' :
  -												pdf = pdf.append("\\(");
  -												currentX += fs.width(ch) / 1000f;
  -												inbetween = true;
  -												addedspace = false;
  -												break;
  -										case ')' :
  -												pdf = pdf.append("\\)");
  -												currentX += fs.width(ch) / 1000f;
  -												inbetween = true;
  -												addedspace = false;
  -												break;
  -										case '\\' :
  -												pdf = pdf.append("\\\\");
  -												currentX += fs.width(ch) / 1000f;
  -												inbetween = true;
  -												addedspace = false;
  -												break;
  -										case '\t':
  -										case ' ':
  -												if (spacing) {
  -														pdf = pdf.append(' ');
  -														currentX += fs.width(' ') / 1000f;
  -												} else {
  -														if (inbetween && !addedspace) {
  -																addedspace = true;
  -																pdf = pdf.append(' ');
  -																currentX += fs.width(' ') / 1000f;
  -														}
  -												}
  -												break;
  -										case '\n':
  -										case '\r':
  -												if (spacing) {
  -														pdf = pdf.append(' ');
  -														currentX += fs.width(' ') / 1000f;
  -												}
  -												break;
  -										default:
  -												addedspace = false;
  -												pdf = pdf.append(ch);
  -												currentX += fs.width(ch) / 1000f;
  -												inbetween = true;
  -												break;
  -								}
  -						}
  +                                    char ch = fs.mapChar(str.charAt(i));
  +                                    if ( useMultiByte ) {
  +                                        switch ( str.charAt( i ))
  +                                        {
  +                                            case '\t':
  +                                            case ' ':
  +                                                if (spacing) {
  +                                                    pdf = pdf.append( endText );
  +                                                    
  +                                                    pdf = pdf.append( startText );
  +                                                    currentX += fs.width(fs.mapChar(' ')) / 1000f;
  +                                                } else {
  +                                                    if (inbetween && !addedspace) {
  +                                                        addedspace = true;
  +                                                        pdf = pdf.append( endText );
  +                                                        pdf = pdf.append(" ");
  +                                                        pdf = pdf.append(Float.toString(-fs.width(fs.mapChar(' '))));
  +                                                        pdf = pdf.append(" ");
  +                                                        pdf = pdf.append( startText );
  +                                                        currentX += fs.width(fs.mapChar(' ')) / 1000f;
  +                                                    }
  +                                                }
  +                                                break;
  +                                            case '\n':
  +                                            case '\r':
  +                                                if (spacing) {
  +                                                    pdf = pdf.append( endText );
  +                                                    pdf = pdf.append(" ");
  +                                                    pdf = pdf.append(Float.toString(-fs.width(fs.mapChar(' '))));
  +                                                    pdf = pdf.append(" ");
  +                                                    pdf = pdf.append( startText );
  +                                                    currentX += fs.width(fs.mapChar(' ')) / 1000f;
  +                                                }
  +                                                break;
  +                                            default:
  +                                                pdf = pdf.append(getUnicodeString( ch));
  +                                                currentX += fs.width(ch) / 1000f;
  +                                                inbetween = true;
  +                                                addedspace = false;
  +                                                break;
  +								}
  +                                    } else if (ch > 127) {
  +                                        pdf = pdf.append("\\");
  +                                        pdf = pdf.append(Integer.toOctalString((int) ch));
  +                                        currentX += fs.width(ch) / 1000f;
  +                                        inbetween = true;
  +                                        addedspace = false;
  +                                    } else {
  +                                        switch (ch) {
  +                                            case '(' :
  +                                                pdf = pdf.append("\\(");
  +                                                currentX += fs.width(ch) / 1000f;
  +                                                inbetween = true;
  +                                                addedspace = false;
  +                                                break;
  +                                            case ')' :
  +                                                pdf = pdf.append("\\)");
  +                                                currentX += fs.width(ch) / 1000f;
  +                                                inbetween = true;
  +                                                addedspace = false;
  +                                                break;
  +                                            case '\\' :
  +                                                pdf = pdf.append("\\\\");
  +                                                currentX += fs.width(ch) / 1000f;
  +                                                inbetween = true;
  +                                                addedspace = false;
  +                                                break;
  +                                            case '\t':
  +                                            case ' ':
  +                                                if (spacing) {
  +                                                    pdf = pdf.append(' ');
  +                                                    currentX += fs.width(' ') / 1000f;
  +                                                } else {
  +                                                    if (inbetween && !addedspace) {
  +                                                        addedspace = true;
  +                                                        pdf = pdf.append(' ');
  +                                                        currentX += fs.width(' ') / 1000f;
  +                                                    }
  +                                                }
  +                                                break;
  +                                            case '\n':
  +                                            case '\r':
  +                                                if (spacing) {
  +                                                    pdf = pdf.append(' ');
  +                                                    currentX += fs.width(' ') / 1000f;
  +                                                }
  +                                                break;
  +                                            default:
  +                                                addedspace = false;
  +                                                pdf = pdf.append(ch);
  +                                                currentX += fs.width(ch) / 1000f;
  +                                                inbetween = true;
  +                                                break;
  +                                        }
  +                                    }
   				}
                  			pdf.append(endText);
   				currentStream.write(pdf.toString());
  @@ -2400,10 +2435,10 @@
   										String str = ((CharacterData) o).getData();
   										currentStream.write(transstr +
   																				(currentX + matrix.getE()) + " " +
  -																				(baseY + matrix.getF()) + " Tm " );
  +																				(baseY + matrix.getF()) + " Tm [" );
   										boolean spacing = "preserve".equals(te.getXMLspace());
   										currentX = addSVGStr(fs, currentX, str, spacing);
  -										currentStream.write(" Tj\n");
  +										currentStream.write(" ] TJ\n");
   								} else if (o instanceof SVGTextPathElementImpl) {
   										SVGTextPathElementImpl tpg = (SVGTextPathElementImpl) o;
   										String ref = tpg.str;
  @@ -2688,4 +2723,36 @@
   						return changed;
   				}
   		}
  +
  +    /**
  +      * Convert a char to a multibyte hex representation
  +      */
  +    private String getUnicodeString(char c) {
  +
  +		StringBuffer buf = new StringBuffer(4);
  +		
  +		byte[] uniBytes = null;
  +		try {
  +			char[] a = {c};
  +			uniBytes = new String(a).getBytes("UnicodeBigUnmarked");
  +		} catch (Exception e) {
  +			// This should never fail
  +		}
  +		
  +		for (int i = 0; i < uniBytes.length; i++) {
  +			int b = (uniBytes[i] < 0) ? (int)(256 + uniBytes[i]) :
  +			(int) uniBytes[i];
  +			
  +			String hexString = Integer.toHexString(b);
  +			if (hexString.length() == 1)
  +			buf = buf.append("0"+hexString);
  +			else
  +			buf = buf.append(hexString);
  +		}
  +		
  +		return buf.toString();
  +			
  +    }
  +
  +
   }
  
  
  

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