Hi Thomas I think, setting the TextPainter coul dbe another possibility to solve this problem. My problem doing this way is to find the font parameters (fontname, size, weight, style, ...). But I'm working...
I try it with the following method, but it isn't working until now: protected Point2D paintACI(AttributedCharacterIterator aci, Graphics2D g2d, Point2D loc) { aci.first(); TextNode.Anchor anchor = (TextNode.Anchor)aci.getAttribute(GVTAttributedCharacterIterator.TextAttribu te.ANCHOR_TYPE); //Adjust position of span Float xpos = (Float)aci.getAttribute(GVTAttributedCharacterIterator.TextAttribute.X); Float ypos = (Float)aci.getAttribute(GVTAttributedCharacterIterator.TextAttribute.Y); Float dxpos = (Float)aci.getAttribute(GVTAttributedCharacterIterator.TextAttribute.DX); Float dypos = (Float)aci.getAttribute(GVTAttributedCharacterIterator.TextAttribute.DY); if (xpos != null) loc.setLocation(xpos.doubleValue(), loc.getY()); if (ypos != null) loc.setLocation(loc.getX(), ypos.doubleValue()); if (dxpos != null) loc.setLocation(loc.getX()+dxpos.doubleValue(), loc.getY()); if (dypos != null) loc.setLocation(loc.getX(), loc.getY()+dypos.doubleValue()); //Set up font List gvtFonts = (List)aci.getAttribute(GVTAttributedCharacterIterator.TextAttribute.GVT_FONT _FAMILIES); Paint forg = (Paint) aci.getAttribute(TextAttribute.FOREGROUND); Float size = (Float) aci.getAttribute(TextAttribute.SIZE); if (size == null) { return loc; } //Stroke stroke = $$$ // (Stroke)aci.getAttribute(GVTAttributedCharacterIterator.TextAttribute.STROKE ); Float posture = (Float)aci.getAttribute(TextAttribute.POSTURE); Float taWeight = (Float)aci.getAttribute(TextAttribute.WEIGHT); if (forg instanceof Color) { g2d.setColor((Color)forg); } g2d.setPaint(forg); //g2d.setStroke(stroke); $$$ String style = ((posture != null) && (posture.floatValue() > 0.0)) ? "italic" : "normal"; String weight = ((taWeight != null) && (taWeight.floatValue() > 1.0)) ? "bold" : "normal"; String sFont = ""; Iterator i = gvtFonts.iterator(); //for (Iterator i = gvtFonts.iterator(); i.hasNext(); ) { GVTFontFamily fam = (GVTFontFamily) i.next(); sFont = fam.getFamilyName(); //} int fStyle = Font.PLAIN; if (weight.equals("bold")) { if (style.equals("italic")) { fStyle = Font.BOLD | Font.ITALIC; } else { fStyle = Font.BOLD; } } else { if (style.equals("italic")) { fStyle = Font.ITALIC; } else { fStyle = Font.PLAIN; } } Font font = new Font(sFont, fStyle, (int) (size.floatValue() + 0.5f)); g2d.setFont(font); //Get text and paint String txt = getText(aci); float advance = StringFormat.getWidth(txt, g2d.getFont()); float tx = 0; if (anchor != null) { switch (anchor.getType()) { case TextNode.Anchor.ANCHOR_MIDDLE: tx = -advance / 2; break; case TextNode.Anchor.ANCHOR_END: tx = -advance; } } //printAttrs(aci); g2d.drawString(txt, (float)(loc.getX() + tx), (float)loc.getY()); loc.setLocation(loc.getX()+(double)advance, loc.getY()); return loc; } I have copied this method from PDFTextPainter (FOP), but I can't find the right font! The size, weight and style is OK. Do you know how I can find the font? Regards Hans > -----Ursprungliche Nachricht----- > Von: Thomas DeWeese [mailto:[EMAIL PROTECTED] > Gesendet: Freitag, 5. Marz 2004 14:02 > An: Batik Users > Betreff: Re: AW: AW: Rendering text in SVG > > > Hans Stoessel wrote: > > > Hi > > > > I think I have found the right file. But how can I implement this? > > > > I use the jar files from Batik to use the classes from Batik. How can I > > overwrite a class or method from a class in Batik? > > You need to do what they do in the PDF transcoder and replace > the bridge class for text in the BridgeContext with the > PDFTextBridge: > > PDFTextElementBridge pdfTextElementBridge; > pdfTextElementBridge = new > PDFTextElementBridge(graphics.getFontInfo()); > ctx.putBridge(pdfTextElementBridge); > > You will likely need to modify the PDFTextBridge since you don't > the font info, but the part about drawing with drawString should > be mostly the same. > > > I use the following code to convert from SVG to WMF: > > > > public boolean saveAsWMF() { > > boolean bOK = true; > > FileOutputStream oStream = null; > > SVGDocument svgDoc = null; > > BridgeContext ctx = null; > > UserAgent userAgent = new UserAgentAdapter(); > > DocumentLoader loader = new DocumentLoader(userAgent); > > GVTBuilder builder = new GVTBuilder(); > > GraphicsNode gvtRoot = null; > > > > try { > > ctx = new BridgeContext(userAgent, loader); > > ctx.setDynamic(true); > > svgDoc = (SVGDocument) > loader.loadDocument("C:\\Temp\\Test.svg"); > > gvtRoot = builder.build(ctx, svgDoc); > > > > WMF wmf = new WMF(); > > WMFGraphics2D wmfGenerator = new WMFGraphics2D(wmf, 300, 200); > > wmfGenerator.setGDIPenDrawing(false); > > > > oStream = new FileOutputStream(new File("C:\\Temp\\Test.wmf")); > > gvtRoot.paint(wmfGenerator); > > wmf.writePlaceableWMF(oStream, 0, 0, 300, 200, 72); > > oStream.close(); > > } > > catch (FileNotFoundException e) { > > bOK = false; > > } > > catch (IOException e) { > > bOK = false; > > } > > return bOK; > > } > > > > I don't know how to solve my problem. Maybe you can give me a > tip. Thanks. > > > > Regards > > Hans > > > > > > > > > >>-----Ursprungliche Nachricht----- > >>Von: Thomas DeWeese [mailto:[EMAIL PROTECTED] > >>Gesendet: Donnerstag, 4. Marz 2004 16:39 > >>An: Batik Users > >>Betreff: Re: AW: Rendering text in SVG > >> > >> > >>Hans Stoessel wrote: > >> > >> > >>>The problem is that you can't edit the text in PowerPoint f.e. > >> > >>if it isn't a > >> > >>>text object. And so it should be a text object... > >>> > >>>- Whats about this 'hack' in FOP? Where can I find that? > >> > >> Check out http://xml.apache.org/fop > >> > >> The hack lives in src/java/org/apache/fop/svg. It is the > >>replacement text bridge. > >> > >> > >>>- Is it possible to use drawString instead of drawGlyphVector? > >> > >>Maybe if I > >> > >>>use an own class to draw my SVG text derived from > SVGGraphics2D? In this > >>>derived class I would replace drawGlyphVector with drawString... > >> > >> This is essentially what the FOP hack does. > >> > >> > >>>Thanks for the help > >>>Hans > >>> > >>> > >>> > >>> > >>> > >>>>-----Ursprungliche Nachricht----- > >>>>Von: Thomas DeWeese [mailto:[EMAIL PROTECTED] > >>>>Gesendet: Donnerstag, 4. Marz 2004 14:02 > >>>>An: Batik Users > >>>>Betreff: Re: Rendering text in SVG > >>>> > >>>> > >>>>Hi Hans, > >>>> > >>>>Hans Stoessel wrote: > >>>> > >>>> > >>>> > >>>>>I convert a SVG in a WMF document using the WMFWriter from Piet > >>>> > >>>>Jonas and > >>>> > >>>> > >>>>>Batik 1.5. > >>>> > >>>>>Now I have problems with the text rendering. The rendered text > >>>> > >>>>in the WMF > >>>> > >>>> > >>>>>file is not a text object. It is graphic and the result on the > >> > >>screen is > >> > >>>>>really bad. > >>>>> > >>>>>- How is the text in the following SVG row rendered? > >>>>> <text x="11.1230469" y="387.1083984" style="stroke:none;" > >>>>>xml:space="preserve">0</text> > >>>> > >>>> It is drawn with Graphics2D.drawGlyphVector. > >>>> > >>>> > >>>> > >>>>>- Will the text be written with Graphics2D.drawString form the Batik > >>>>>library? > >>>> > >>>> No draw string isn't nearly powerful enough to handle SVG text. > >>>> > >>>> > >>>> > >>>>>Or is another Graphics2D method used? The developer of the WMF > >>>>>library says, the Graphics2D methods of his library will be > >>>> > >>>>used instead of > >>>> > >>>> > >>>>>the Graphics2D methods from Batik. And if the Batik library use > >>>> > >>>>drawString > >>>> > >>>> > >>>>>the result would be OK. > >>>>> > >>>>>- Can I do something, that the text will be drawn with > >>>>>Graphics2D.drawString? > >>>> > >>>> The PDFTranscoder from the FOP project has a 'hack' so very simple > >>>>text is drawn using 'drawString'. You might look into using that. > >>>> > >>>> > >>>> > >>>>--------------------------------------------------------------------- > >>>>To unsubscribe, e-mail: [EMAIL PROTECTED] > >>>>For additional commands, e-mail: [EMAIL PROTECTED] > >>>> > >>>> > >>>> > >>> > >>> > >>> > >>>--------------------------------------------------------------------- > >>>To unsubscribe, e-mail: [EMAIL PROTECTED] > >>>For additional commands, e-mail: [EMAIL PROTECTED] > >>> > >> > >> > >> > >>--------------------------------------------------------------------- > >>To unsubscribe, e-mail: [EMAIL PROTECTED] > >>For additional commands, e-mail: [EMAIL PROTECTED] > >> > >> > >> > > > > > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]