Menu

#23 SVG - number not positioned below barcode

open
SVG (2)
5
2007-10-04
2007-10-04
Robert
No

version of barbecue code barbecue-1.5-beta1-src.zip

Other libraries - latest 'head' version, downloaded from Barbecue SVN on 2 October.

Viewing in inkscape (inkscape.org) v0.45 SVG drawing software shows the number at the top left. If you look at the SVG for the barcode below, you'll see that the x and y co-ordinates for the text are (0,0) which would explain the position top left.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg:svg xmlns:svg="http://www.w3.org/2000/svg" width="1.203125in" height="0.1875in"><svg:rect x="0.0in" y="0.0in" width="0.15625in" height="0.1875in" style="fill:#FFFFFF;" /><svg:rect x="0.15625in" y="0.0in" width="0.03125in" height="0.1875in" style="fill:#000000;" /><svg:rect x="0.1875in" y="0.0in" width="0.015625in" height="0.1875in" style="fill:#FFFFFF;" /><svg:rect x="0.203125in" y="0.0in" width="0.015625in" height="0.1875in" style="fill:#000000;" /><svg:rect x="0.21875in" y="0.0in" width="0.03125in" height="0.1875in" style="fill:#FFFFFF;" /><svg:rect x="0.25in" y="0.0in" width="0.015625in" height="0.1875in" style="fill:#000000;" /><svg:rect x="0.265625in" y="0.0in" width="0.0625in" height="0.1875in" style="fill:#FFFFFF;" /><svg:rect x="0.328125in" y="0.0in" width="0.03125in" height="0.1875in" style="fill:#000000;" /><svg:rect x="0.359375in" y="0.0in" width="0.03125in" height="0.1875in" style="fill:#FFFFFF;" /><svg:rect x="0.390625in" y="0.0in" width="0.015625in" height="0.1875in" style="fill:#000000;" /><svg:rect x="0.40625in" y="0.0in" width="0.015625in" height="0.1875in" style="fill:#FFFFFF;" /><svg:rect x="0.421875in" y="0.0in" width="0.046875in" height="0.1875in" style="fill:#000000;" /><svg:rect x="0.46875in" y="0.0in" width="0.03125in" height="0.1875in" style="fill:#FFFFFF;" /><svg:rect x="0.5in" y="0.0in" width="0.03125in" height="0.1875in" style="fill:#000000;" /><svg:rect x="0.53125in" y="0.0in" width="0.03125in" height="0.1875in" style="fill:#FFFFFF;" /><svg:rect x="0.5625in" y="0.0in" width="0.015625in" height="0.1875in" style="fill:#000000;" /><svg:rect x="0.578125in" y="0.0in" width="0.015625in" height="0.1875in" style="fill:#FFFFFF;" /><svg:rect x="0.59375in" y="0.0in" width="0.046875in" height="0.1875in" style="fill:#000000;" /><svg:rect x="0.640625in" y="0.0in" width="0.03125in" height="0.1875in" style="fill:#FFFFFF;" /><svg:rect x="0.671875in" y="0.0in" width="0.046875in" height="0.1875in" style="fill:#000000;" /><svg:rect x="0.71875in" y="0.0in" width="0.015625in" height="0.1875in" style="fill:#FFFFFF;" /><svg:rect x="0.734375in" y="0.0in" width="0.03125in" height="0.1875in" style="fill:#000000;" /><svg:rect x="0.765625in" y="0.0in" width="0.046875in" height="0.1875in" style="fill:#FFFFFF;" /><svg:rect x="0.8125in" y="0.0in" width="0.015625in" height="0.1875in" style="fill:#000000;" /><svg:rect x="0.828125in" y="0.0in" width="0.015625in" height="0.1875in" style="fill:#FFFFFF;" /><svg:rect x="0.84375in" y="0.0in" width="0.03125in" height="0.1875in" style="fill:#000000;" /><svg:rect x="0.875in" y="0.0in" width="0.046875in" height="0.1875in" style="fill:#FFFFFF;" /><svg:rect x="0.921875in" y="0.0in" width="0.046875in" height="0.1875in" style="fill:#000000;" /><svg:rect x="0.96875in" y="0.0in" width="0.015625in" height="0.1875in" style="fill:#FFFFFF;" /><svg:rect x="0.984375in" y="0.0in" width="0.015625in" height="0.1875in" style="fill:#000000;" /><svg:rect x="1.0in" y="0.0in" width="0.015625in" height="0.1875in" style="fill:#FFFFFF;" /><svg:rect x="1.015625in" y="0.0in" width="0.03125in" height="0.1875in" style="fill:#000000;" /><svg:rect x="1.046875in" y="0.0in" width="0.15625in" height="0.1875in" style="fill:#FFFFFF;" /><svg:text x="0.0in" y="0.0in" style="font-family: Dialog; font-size: 12pt; font-style: normal; ">33</svg:text></svg:svg>

Discussion

  • Robert

    Robert - 2007-10-04

    screen show showing the barcode viewed from inkscape SVG drawing editor, showing the number at the top left

     
  • Robert

    Robert - 2007-10-04

    Logged In: YES
    user_id=1340913
    Originator: YES

    File Added: barbecue.svg

     
  • Robert

    Robert - 2007-10-04
    • assigned_to: ibourke --> sullis
     
  • Robert

    Robert - 2007-10-04

    the SVG code generated by barbecue

     
  • Robert

    Robert - 2007-10-04

    Logged In: YES
    user_id=1340913
    Originator: YES

    Using the Barbecue SWING Application supplied, using code 128B, typed '33'.

     
  • Roland Quast

    Roland Quast - 2008-09-18

    I found the reason why this doesn't work.

    If you compare GraphicsOutput.java and SVGOutput.java, the implementation of drawText() is correct in GraphicsOutput and incorrect in SVGOutput.

    The key problem is that this line isn't being called:

    TextLayout layout = new TextLayout(text, font, g.getFontRenderContext());
    labelLayout.setTextLayout(layout);

    This line calls the calculate() method when setTextLayout() is called. The calculate method sets the X, Y, text width and text height.

    So essentially, the fix is to implement the line above (but you need to get the font renderer context).

    Can someone fix this for the next release? All my barcodes rely on SVG output (hence the reason I had to figure it out).

     
  • Roland Quast

    Roland Quast - 2008-09-18

    This is my SVGOutput drawText replacement so far... the only problem I have is that the text is about 5px too far right, and 3px too high. Could be something to do with the FontRendererContext? not really sure.

    public int drawText(String text, LabelLayout layout) throws OutputException {
    if(font == null) {
    return 0;
    } else {
    TextLayout textLayout = new TextLayout(text, font, new FontRenderContext(null, false, false));
    layout.setTextLayout(textLayout);
    Element textElement = createElement("text");
    textElement.setAttribute("x", getScaledDimension((int) layout.getTextX()));
    textElement.setAttribute("y", getScaledDimension((int) layout.getTextY()));
    textElement.setAttribute("style", constructStyleText());
    textElement.addContent(text);
    root.addContent(textElement);
    return layout.getBackgroundHeight();
    }
    }

     

Log in to post a comment.

MongoDB Logo MongoDB