/* RSTText.java * * Copyright (c) 2003, Benja Fallenstein * * This file is part of Fenfire. * * Fenfire is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * Fenfire is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General * Public License for more details. * * You should have received a copy of the GNU Lesser General * Public License along with Fenfire; if not, write to the Free * Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, * MA 02111-1307 USA * * */ /* * Written by Benja Fallenstein and Matti J. Katila */ package org.fenfire.view.lava; import org.fenfire.view.*; import org.fenfire.swamp.*; import org.nongnu.alph.*; import org.nongnu.libvob.*; import org.nongnu.libvob.util.*; import org.nongnu.libvob.vobs.*; /** A node function returning a vob that shows * the given node as text. */ public class RSTText extends TextHandler implements NodeFunction { private void p(String s) { System.out.println("RSTText:: "+s); } final LineVob cursorVob = new LineVob(0, 0, 0, 1, java.awt.Color.black); final NodeFunction nodeContent; final TextStyle style; private FenPDFContext context = null; public void setContext(FenPDFContext context) { this.context = context; } public RSTText(NodeFunction nodeContent, TextStyle style, float scale) { super(); this.nodeContent = nodeContent; this.style = style; super.setScale(scale); } public Object f(ConstGraph g, Object node) { if (context == null) throw new Error("No context set"); context.isToBePlaced(node, this); p("placed, offs: "+cursorOffset); Enfilade1D enf = (Enfilade1D)nodeContent.f(g, node); final Object objNode = node; final String s = enf.makeString(); final TextVob vob = new TextVob(style, s, false, color); final float width = style.getWidth(s, scale); final float height = style.getHeight(scale); final int offs = super.getCursorOffset(); return new org.nongnu.libvob.lava.placeable.Placeable() { public void place(VobScene vs, int into) { int scaled = vs.orthoCS(into, objNode, 0, 0, 0, height, height); vs.put(vob, scaled); // doesn't work, could someone fix this? // I get "Error: CallistCoorded with non-glperformable." if(offs >= 0) { float x = style.getWidth(s.substring(0,offs), scale); p("offs x: "+x); int cursor = vs.orthoBoxCS(into, "CURSOR_KEY", -1, x,0, 1,1, 1, height); vs.map.put(cursorVob, cursor); } } public float getWidth() { return width; } public float getHeight() { return height; } }; } }