uctx = UnitProcessor.createContext(ctx, filteredElement); s = filterPrimitiveElement.getAttributeNS(null, SVG_X_ATTRIBUTE); if (s.length() != 0) { x = UnitProcessor.svgHorizontalCoordinateToUserSpace (s, SVG_X_ATTRIBUTE, uctx); s = filterPrimitiveElement.getAttributeNS(null, SVG_Y_ATTRIBUTE); if (s.length() != 0) { y = UnitProcessor.svgVerticalCoordinateToUserSpace (s, SVG_Y_ATTRIBUTE, uctx); s = filterPrimitiveElement.getAttributeNS(null, SVG_WIDTH_ATTRIBUTE); if (s.length() != 0) { w = UnitProcessor.svgHorizontalLengthToUserSpace (s, SVG_WIDTH_ATTRIBUTE, uctx); s = filterPrimitiveElement.getAttributeNS(null, SVG_HEIGHT_ATTRIBUTE); if (s.length() != 0) { h = UnitProcessor.svgVerticalLengthToUserSpace (s, SVG_HEIGHT_ATTRIBUTE, uctx);
ShapeNode shapeNode) { UnitProcessor.Context uctx = UnitProcessor.createContext(ctx, e); String s; float cx = 0; if (s.length() != 0) { cx = UnitProcessor.svgHorizontalCoordinateToUserSpace (s, SVG_CX_ATTRIBUTE, uctx); float cy = 0; if (s.length() != 0) { cy = UnitProcessor.svgVerticalCoordinateToUserSpace (s, SVG_CY_ATTRIBUTE, uctx); float r; if (s.length() != 0) { r = UnitProcessor.svgOtherLengthToUserSpace (s, SVG_R_ATTRIBUTE, uctx); } else {
/** * Returns the specified length with the specified direction in * user units. A length must be greater than 0. * * @param s the length * @param attr the attribute name that represents the length * @param d the direction of the length * @param ctx the context used to resolve relative value */ public static float svgLengthToObjectBoundingBox(String s, String attr, short d, Context ctx) { float v = svgToObjectBoundingBox(s, attr, d, ctx); if (v < 0) { throw new BridgeException(getBridgeContext(ctx), ctx.getElement(), ErrorConstants.ERR_LENGTH_NEGATIVE, new Object[] {attr, s}); } return v; }
/** * Returns a float in user units according to the specified parameters. * * @param length the length * @param attr the name of the attribute that represents the length * @param unitsType the coordinate system (OBJECT_BOUNDING_BOX | * USER_SPACE_ON_USE) * @param uctx the unit processor context */ public static float convertLength(String length, String attr, short unitsType, UnitProcessor.Context uctx) { switch (unitsType) { case OBJECT_BOUNDING_BOX: return UnitProcessor.svgOtherLengthToObjectBoundingBox (length, attr, uctx); case USER_SPACE_ON_USE: return UnitProcessor.svgOtherLengthToUserSpace(length, attr, uctx); default: throw new IllegalArgumentException("Invalid unit type"); } }
switch (unitsType) { case OBJECT_BOUNDING_BOX: x = UnitProcessor.svgHorizontalCoordinateToObjectBoundingBox (xStr, xAttr, uctx); y = UnitProcessor.svgVerticalCoordinateToObjectBoundingBox (yStr, yAttr, uctx); break; case USER_SPACE_ON_USE: x = UnitProcessor.svgHorizontalCoordinateToUserSpace (xStr, xAttr, uctx); y = UnitProcessor.svgVerticalCoordinateToUserSpace (yStr, yAttr, uctx); break;
/** * Returns the float list that represents a set of values or percentage. * * * @param element the element that defines the specified coordinates * @param attrName the name of the attribute (used by error handling) * @param valueStr the delimited string containing values of the coordinate * @param ctx the bridge context */ public static ArrayList svgVerticalCoordinateArrayToUserSpace(Element element, String attrName, String valueStr, BridgeContext ctx) { UnitProcessor.Context uctx = UnitProcessor.createContext(ctx, element); ArrayList values = new ArrayList(); StringTokenizer st = new StringTokenizer(valueStr, ", ", false); while (st.hasMoreTokens()) { values.add (UnitProcessor.svgVerticalCoordinateToUserSpace (st.nextToken(), attrName, uctx)); } return values; }
switch (unitsType) { case OBJECT_BOUNDING_BOX: x = UnitProcessor.svgHorizontalCoordinateToObjectBoundingBox (xStr, SVG_X_ATTRIBUTE, uctx); y = UnitProcessor.svgVerticalCoordinateToObjectBoundingBox (yStr, SVG_Y_ATTRIBUTE, uctx); w = UnitProcessor.svgHorizontalLengthToObjectBoundingBox (wStr, SVG_WIDTH_ATTRIBUTE, uctx); h = UnitProcessor.svgVerticalLengthToObjectBoundingBox (hStr, SVG_HEIGHT_ATTRIBUTE, uctx); x = UnitProcessor.svgHorizontalCoordinateToUserSpace (xStr, SVG_X_ATTRIBUTE, uctx); y = UnitProcessor.svgVerticalCoordinateToUserSpace (yStr, SVG_Y_ATTRIBUTE, uctx); w = UnitProcessor.svgHorizontalLengthToUserSpace (wStr, SVG_WIDTH_ATTRIBUTE, uctx); h = UnitProcessor.svgVerticalLengthToUserSpace (hStr, SVG_HEIGHT_ATTRIBUTE, uctx); break;
protected void gatherRegionInfo(BridgeContext ctx, Element rgn, float verticalAlign, List regions) { for (Node n = rgn.getFirstChild(); n != null; n = n.getNextSibling()) { if (n.getNodeType() != Node.ELEMENT_NODE) continue; if (!getNamespaceURI().equals(n.getNamespaceURI())) continue; Element e = (Element)n; String ln = n.getLocalName(); if (ln.equals(SVGConstants.SVG_RECT_TAG)) { UnitProcessor.Context uctx; uctx = UnitProcessor.createContext(ctx, e); RegionInfo ri = buildRegion(uctx, e, verticalAlign); if (ri != null) regions.add(ri); } } }
UnitProcessor.Context uctx = UnitProcessor.createContext(ctx, e); s = SVGOMDocument.SVG_SVG_WIDTH_DEFAULT_VALUE; float width = UnitProcessor.svgHorizontalLengthToUserSpace( s, SVGOMDocument.SVG_WIDTH_ATTRIBUTE, uctx); s = SVGOMDocument.SVG_SVG_HEIGHT_DEFAULT_VALUE; float height = UnitProcessor.svgVerticalLengthToUserSpace( s, SVGOMDocument.SVG_HEIGHT_ATTRIBUTE, uctx);
= UnitProcessor.createContext(ctx, cursorElement); x = UnitProcessor.svgHorizontalCoordinateToUserSpace (s, SVG_X_ATTRIBUTE, uctx); float y = 0; if (s.length() != 0) { y = UnitProcessor.svgVerticalCoordinateToUserSpace (s, SVG_Y_ATTRIBUTE, uctx);
/** * Returns the float list that represents a set of horizontal * values or percentage. * * @param element the element that defines the specified coordinates * @param attrName the name of the attribute (used by error handling) * @param valueStr the delimited string containing values of the coordinate * @param ctx the bridge context */ public static ArrayList svgHorizontalCoordinateArrayToUserSpace(Element element, String attrName, String valueStr, BridgeContext ctx) { UnitProcessor.Context uctx = UnitProcessor.createContext(ctx, element); ArrayList values = new ArrayList(); StringTokenizer st = new StringTokenizer(valueStr, ", ", false); while (st.hasMoreTokens()) { values.add (UnitProcessor.svgHorizontalCoordinateToUserSpace (st.nextToken(), attrName, uctx)); } return values; }
UnitProcessor.Context uctx = UnitProcessor.createContext(ctx, textPathElement); startOffset = UnitProcessor.svgOtherLengthToUserSpace(s, SVG_START_OFFSET_ATTRIBUTE, uctx);
protected void transcode(Document document, String uri, TranscoderOutput output) throws TranscoderException { setupImageInfrastructure(uri); super.transcode(document, uri, output); if (getLogger().isTraceEnabled()) { getLogger().trace("document size: " + width + " x " + height); } // prepare the image to be painted UnitProcessor.Context uctx = UnitProcessor.createContext(ctx, document.getDocumentElement()); float widthInPt = UnitProcessor.userSpaceToSVG(width, SVGLength.SVG_LENGTHTYPE_PT, UnitProcessor.HORIZONTAL_LENGTH, uctx); int w = (int) (widthInPt + 0.5); float heightInPt = UnitProcessor.userSpaceToSVG(height, SVGLength.SVG_LENGTHTYPE_PT, UnitProcessor.HORIZONTAL_LENGTH, uctx); int h = (int) (heightInPt + 0.5); if (getLogger().isTraceEnabled()) { getLogger().trace("document size: " + w + "pt x " + h + "pt"); } this.root.paint(graphics); } }
/** * Get the size of the SVG root element. * @param size the font size * @param svgRoot the svg root element * @param ptmm the pixel to millimeter conversion factor * @return the size of the SVG document */ public static Point2D getSize(int size, Element svgRoot, float ptmm) { String str; UnitProcessor.Context ctx; ctx = new PDFUnitContext(size, svgRoot, ptmm); str = svgRoot.getAttributeNS(null, SVGConstants.SVG_WIDTH_ATTRIBUTE); if (str.length() == 0) { str = "100%"; } float width = UnitProcessor.svgHorizontalLengthToUserSpace( str, SVGConstants.SVG_WIDTH_ATTRIBUTE, ctx); str = svgRoot.getAttributeNS(null, SVGConstants.SVG_HEIGHT_ATTRIBUTE); if (str.length() == 0) { str = "100%"; } float height = UnitProcessor.svgVerticalLengthToUserSpace( str, SVGConstants.SVG_HEIGHT_ATTRIBUTE, ctx); return new Point2D.Float(width, height); }
/** * Returns the specified length with the specified direction in * user units. A length must be greater than 0. * * @param s the 'other' coordinate * @param attr the attribute name that represents the length * @param d the direction of the length * @param ctx the context used to resolve relative value */ public static float svgLengthToUserSpace(String s, String attr, short d, Context ctx) { float v = svgToUserSpace(s, attr, d, ctx); if (v < 0) { throw new BridgeException(getBridgeContext(ctx), ctx.getElement(), ErrorConstants.ERR_LENGTH_NEGATIVE, new Object[] {attr, s}); } else { return v; } }
/** * Returns the specified coordinate with the specified direction * in user units. * * @param s the 'other' coordinate * @param attr the attribute name that represents the length * @param d the direction of the coordinate * @param ctx the context used to resolve relative value */ public static float svgToUserSpace(String s, String attr, short d, Context ctx) { try { return org.apache.batik.parser.UnitProcessor. svgToUserSpace(s, attr, d, ctx); } catch (ParseException pEx ) { throw new BridgeException (getBridgeContext(ctx), ctx.getElement(), pEx, ErrorConstants.ERR_ATTRIBUTE_VALUE_MALFORMED, new Object[] {attr, s, pEx, }); } }
switch (unitsType) { case OBJECT_BOUNDING_BOX: x = UnitProcessor.svgHorizontalCoordinateToObjectBoundingBox (xStr, SVG_X_ATTRIBUTE, uctx); y = UnitProcessor.svgVerticalCoordinateToObjectBoundingBox (yStr, SVG_Y_ATTRIBUTE, uctx); w = UnitProcessor.svgHorizontalLengthToObjectBoundingBox (wStr, SVG_WIDTH_ATTRIBUTE, uctx); h = UnitProcessor.svgVerticalLengthToObjectBoundingBox (hStr, SVG_HEIGHT_ATTRIBUTE, uctx); x = UnitProcessor.svgHorizontalCoordinateToUserSpace (xStr, SVG_X_ATTRIBUTE, uctx); y = UnitProcessor.svgVerticalCoordinateToUserSpace (yStr, SVG_Y_ATTRIBUTE, uctx); w = UnitProcessor.svgHorizontalLengthToUserSpace (wStr, SVG_WIDTH_ATTRIBUTE, uctx); h = UnitProcessor.svgVerticalLengthToUserSpace (hStr, SVG_HEIGHT_ATTRIBUTE, uctx); break;
protected void gatherRegionInfo(BridgeContext ctx, Element rgn, float verticalAlign, List regions) { for (Node n = rgn.getFirstChild(); n != null; n = n.getNextSibling()) { if (n.getNodeType() != Node.ELEMENT_NODE) continue; if (!getNamespaceURI().equals(n.getNamespaceURI())) continue; Element e = (Element)n; String ln = n.getLocalName(); if (ln.equals(SVGConstants.SVG_RECT_TAG)) { UnitProcessor.Context uctx; uctx = UnitProcessor.createContext(ctx, e); RegionInfo ri = buildRegion(uctx, e, verticalAlign); if (ri != null) regions.add(ri); } } }
float height = DEFAULT_PREFERRED_HEIGHT; UnitProcessor.Context uctx = UnitProcessor.createContext(ctx, rootElement); width = UnitProcessor.svgHorizontalLengthToUserSpace (s, SVG_WIDTH_ATTRIBUTE, uctx); height = UnitProcessor.svgVerticalLengthToUserSpace (s, SVG_HEIGHT_ATTRIBUTE, uctx);
switch (unitsType) { case OBJECT_BOUNDING_BOX: x = UnitProcessor.svgHorizontalCoordinateToObjectBoundingBox (xStr, xAttr, uctx); y = UnitProcessor.svgVerticalCoordinateToObjectBoundingBox (yStr, yAttr, uctx); break; case USER_SPACE_ON_USE: x = UnitProcessor.svgHorizontalCoordinateToUserSpace (xStr, xAttr, uctx); y = UnitProcessor.svgVerticalCoordinateToUserSpace (yStr, yAttr, uctx); break;