• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java UnitConv类的典型用法和代码示例

java 2次浏览

本文整理汇总了Java中org.krysalis.barcode4j.tools.UnitConv的典型用法代码示例。如果您正苦于以下问题:Java UnitConv类的具体用法?Java UnitConv怎么用?Java UnitConv使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。

UnitConv类属于org.krysalis.barcode4j.tools包,在下文中一共展示了UnitConv类的21个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: getDimension

点赞 3

import org.krysalis.barcode4j.tools.UnitConv; //导入依赖的package包/类
public Point2D getDimension(Point2D view) {
    Configuration cfg = ConfigurationUtil.buildConfiguration(this.doc);
    try {
        String msg = ConfigurationUtil.getMessage(cfg);
        msg = MessageUtil.unescapeUnicode(msg);

        int orientation = cfg.getAttributeAsInteger("orientation", 0);
        orientation = BarcodeDimension.normalizeOrientation(orientation);

        BarcodeGenerator bargen = BarcodeUtil.getInstance().
                createBarcodeGenerator(cfg);
        String expandedMsg = VariableUtil.getExpandedMessage((PageInfo)null, msg);
        BarcodeDimension bardim = bargen.calcDimensions(expandedMsg);
        float w = (float)UnitConv.mm2pt(bardim.getWidthPlusQuiet(orientation));
        float h = (float)UnitConv.mm2pt(bardim.getHeightPlusQuiet(orientation));
        return new Point2D.Float(w, h);
    } catch (ConfigurationException ce) {
        ce.printStackTrace();
    } catch (BarcodeException be) {
        be.printStackTrace();
    }
    return null;
}
 

开发者ID:thanakrit,
项目名称:barcode4j,
代码行数:24,
代码来源:BarcodeElement.java

示例2: renderUsingEPS

点赞 3

import org.krysalis.barcode4j.tools.UnitConv; //导入依赖的package包/类
private void renderUsingEPS(RendererContext context, BarcodeGenerator bargen,
            String msg, int orientation) throws IOException {
    PSGenerator gen = (PSGenerator)context.getProperty(PS_GENERATOR);
    ByteArrayOutputStream baout = new ByteArrayOutputStream(1024);
    EPSCanvasProvider canvas = new EPSCanvasProvider(baout, orientation);
    bargen.generateBarcode(canvas, msg);
    canvas.finish();

    final BarcodeDimension barDim = canvas.getDimensions();
    float bw = (float)UnitConv.mm2pt(barDim.getWidthPlusQuiet(orientation));
    float bh = (float)UnitConv.mm2pt(barDim.getHeightPlusQuiet(orientation));

    float width = ((Integer)context.getProperty(WIDTH)).intValue() / 1000f;
    float height = ((Integer)context.getProperty(HEIGHT)).intValue() / 1000f;
    float x = ((Integer)context.getProperty(XPOS)).intValue() / 1000f;
    float y = ((Integer)context.getProperty(YPOS)).intValue() / 1000f;

    if (DEBUG) {
        System.out.println(" --> EPS");
    }
    PSImageUtils.renderEPS(new java.io.ByteArrayInputStream(baout.toByteArray()),
            "Barcode:" + msg,
            new Rectangle2D.Float(x, y, width, height),
            new Rectangle2D.Float(0, 0, bw, bh),
            gen);
}
 

开发者ID:thanakrit,
项目名称:barcode4j,
代码行数:27,
代码来源:BarcodeXMLHandler.java

示例3: setFourStateAttributes

点赞 2

import org.krysalis.barcode4j.tools.UnitConv; //导入依赖的package包/类
protected void setFourStateAttributes(
		FourStateBarcodeComponent barcodeComponent, 
		AbstractFourStateBean barcodeBean)
{
	if (barcodeComponent.getChecksumMode() != null)
	{
		barcodeBean.setChecksumMode(
				ChecksumMode.byName(barcodeComponent.getChecksumMode()));
	}
	
	if (barcodeComponent.getAscenderHeight() != null)
	{
		barcodeBean.setAscenderHeight(
				UnitConv.pt2mm(barcodeComponent.getAscenderHeight().doubleValue()));
	}
	
	if (barcodeComponent.getIntercharGapWidth() != null)
	{
		barcodeBean.setIntercharGapWidth(
				UnitConv.pt2mm(barcodeComponent.getIntercharGapWidth().doubleValue()));
	}
	
	if (barcodeComponent.getTrackHeight() != null)
	{
		barcodeBean.setTrackHeight(
				UnitConv.pt2mm(barcodeComponent.getTrackHeight().doubleValue()));
	}
}
 

开发者ID:TIBCOSoftware,
项目名称:jasperreports,
代码行数:29,
代码来源:AbstractBarcodeEvaluator.java

示例4: visitPostnet

点赞 2

import org.krysalis.barcode4j.tools.UnitConv; //导入依赖的package包/类
@Override
public void visitPostnet(POSTNETComponent postnet)
{
	POSTNETBean postnetBean = new POSTNETBean();
	barcodeBean = postnetBean;
	evaluatePOSTNET(postnet);
	setBaseAttributes(postnet);
	
	if (postnet.getShortBarHeight() != null)
	{
		postnetBean.setShortBarHeight(
				UnitConv.pt2mm(postnet.getShortBarHeight().doubleValue()));
	}
	
	if (postnet.getBaselinePosition() != null)
	{
		postnetBean.setBaselinePosition(
				BaselineAlignment.byName(postnet.getBaselinePosition()));
	}
	
	if (postnet.getChecksumMode() != null)
	{
		postnetBean.setChecksumMode(
				ChecksumMode.byName(postnet.getChecksumMode()));
	}
	
	if (postnet.getDisplayChecksum() != null)
	{
		postnetBean.setDisplayChecksum(
				postnet.getDisplayChecksum().booleanValue());
	}
	
	if (postnet.getIntercharGapWidth() != null)
	{
		postnetBean.setIntercharGapWidth(
				UnitConv.pt2mm(postnet.getIntercharGapWidth().doubleValue()));
	}
	evaluateBarcodeRenderable(postnet);
}
 

开发者ID:TIBCOSoftware,
项目名称:jasperreports,
代码行数:40,
代码来源:AbstractBarcodeEvaluator.java

示例5: createBarcode

点赞 2

import org.krysalis.barcode4j.tools.UnitConv; //导入依赖的package包/类
private BufferedImage createBarcode() throws IOException
{
	String data = (volume.getIsbn().equals("") ? volume.getBarcode() : volume.getIsbn().replace("-", "")) + "+" + (volume.getNumber().length() == 1 ? "0" + volume.getNumber() : volume.getNumber());
	EAN13Bean bean = new EAN13Bean();
	bean.setHeight(12d);
	bean.setModuleWidth(UnitConv.in2mm(1.0f / 100));
	bean.setFontSize(2);

	BitmapCanvasProvider provider = new BitmapCanvasProvider(100, BufferedImage.TYPE_INT_RGB, true, 0);
	bean.generateBarcode(provider, data);
	provider.finish();

	BufferedImage barcodeImage = provider.getBufferedImage();
	BufferedImage result = new BufferedImage(barcodeImage.getWidth() + 4, barcodeImage.getHeight() + 9, BufferedImage.TYPE_INT_RGB);
	Graphics2D g2d = result.createGraphics();
	g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);

	g2d.setPaint(Utilities.deriveColorAlpha(BorderUtils.DEFAULT_LINE_COLOR, 255));
	g2d.fillRect(0, 0, result.getWidth(), result.getHeight());
	g2d.setPaint(Color.WHITE);
	g2d.fillRect(2, 2, result.getWidth() - 4, result.getHeight() - 4);
	g2d.drawImage(barcodeImage, 2, 5, barcodeImage.getWidth(), barcodeImage.getHeight(), null);

	g2d.dispose();

	return result;
}
 

开发者ID:alessandrojean,
项目名称:manga-no-keiei,
代码行数:28,
代码来源:VolumeCard.java

示例6: main

点赞 2

import org.krysalis.barcode4j.tools.UnitConv; //导入依赖的package包/类
public static void main(String[] args) {
    try {
        //Create the barcode bean
        Code39Bean bean = new Code39Bean();
        
        final int dpi = 150;
        
        //Configure the barcode generator
        bean.setModuleWidth(UnitConv.in2mm(1.0f / dpi)); //makes the narrow bar 
                                                         //width exactly one pixel
        bean.setWideFactor(3);
        bean.doQuietZone(false);
        
        //Open output file
        File outputFile = new File("out.jpg");
        OutputStream out = new FileOutputStream(outputFile);
        try {
            //Set up the canvas provider for monochrome JPEG output 
            BitmapCanvasProvider canvas = new BitmapCanvasProvider(
                    out, "image/jpeg", dpi, BufferedImage.TYPE_BYTE_BINARY, false, 0);
        
            //Generate the barcode
            bean.generateBarcode(canvas, "123456");
        
            //Signal end of generation
            canvas.finish();
        } finally {
            out.close();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 

开发者ID:thanakrit,
项目名称:barcode4j,
代码行数:34,
代码来源:SampleBitmapBarcodeWithBean.java

示例7: prepareImage

点赞 2

import org.krysalis.barcode4j.tools.UnitConv; //导入依赖的package包/类
/**
 * Prepares a BufferedImage to paint to.
 * @param dim the barcode dimensions
 * @param orientation the barcode orientation (0, 90, 180, 270)
 * @param resolution the desired image resolution (dots per inch)
 * @param imageType the desired image type (Values: BufferedImage.TYPE_*)
 * @return the requested BufferedImage
 */
public static BufferedImage prepareImage(BarcodeDimension dim,
                    int orientation,
                    int resolution, int imageType) {
    int bmw = UnitConv.mm2px(dim.getWidthPlusQuiet(orientation), resolution);
    int bmh = UnitConv.mm2px(dim.getHeightPlusQuiet(orientation), resolution);
    BufferedImage bi = new BufferedImage(
            bmw,
            bmh,
            imageType);
    return bi;
}
 

开发者ID:thanakrit,
项目名称:barcode4j,
代码行数:20,
代码来源:BitmapBuilder.java

示例8: deviceText

点赞 2

import org.krysalis.barcode4j.tools.UnitConv; //导入依赖的package包/类
/** {@inheritDoc} */
public void deviceText(
            String text,
            double x1,
            double x2,
            double y1,
            String fontName,
            double fontSize,
            TextAlignment textAlign) {
    if (firstError != null) {
        return;
    }
    checkFontName(fontName);
    try {
        writer.write("/" + fontName + " findfont "
                + UnitConv.mm2pt(fontSize) + " scalefont setfont\n");
        if (textAlign == TextAlignment.TA_LEFT) {
            writer.write(formatmm(x1, y1) + " moveto (" + text + ") show\n");
        } else if (textAlign == TextAlignment.TA_RIGHT) {
            writer.write("(" + text + ") "
                    + formatmm(x1) + " "
                    + formatmm(x2) + " "
                    + formatmm(this.height - y1) + " rt\n");
        } else if (textAlign == TextAlignment.TA_CENTER) {
            writer.write("(" + text + ") "
                    + formatmm((x1 + x2) / 2, y1) + " ct\n");
        } else if (textAlign == TextAlignment.TA_JUSTIFY) {
            writer.write("(" + text + ") "
                    + formatmm(x1) + " "
                    + formatmm(x2) + " "
                    + formatmm(this.height - y1) + " jt\n");
        }
    } catch (IOException ioe) {
        firstError = ioe;
    }
}
 

开发者ID:thanakrit,
项目名称:barcode4j,
代码行数:37,
代码来源:EPSCanvasProvider.java

示例9: USPSIntelligentMailBean

点赞 2

import org.krysalis.barcode4j.tools.UnitConv; //导入依赖的package包/类
/** Create a new instance. */
public USPSIntelligentMailBean() {
    super();
    setMsgPosition(HumanReadablePlacement.HRP_NONE); //Different default than normal
    setModuleWidth(UnitConv.in2mm(DEFAULT_MODULE_WIDTH_INCH)); //0.015 - 0.025in
    setIntercharGapWidth(UnitConv.in2mm(DEFAULT_INTERCHAR_GAP_WIDTH_INCH)); //0.012 - 0.040in
    //Defaults result in a pitch of 0.045in (22.2 bars per inch)
    
    setQuietZone(UnitConv.in2mm(DEFAULT_HORZ_QUIET_ZONE_INCH));
    setVerticalQuietZone(UnitConv.in2mm(DEFAULT_VERT_QUIET_ZONE_INCH));
    
    setTrackHeight(UnitConv.in2mm(DEFAULT_TRACK_HEIGHT_INCH)); //0.039 - 0.057in
    setAscenderHeight(UnitConv.in2mm(DEFAULT_ASCENDER_HEIGHT_INCH)); //0.0435 - 0.0555in
}
 

开发者ID:thanakrit,
项目名称:barcode4j,
代码行数:15,
代码来源:USPSIntelligentMailBean.java

示例10: verifySettings

点赞 2

import org.krysalis.barcode4j.tools.UnitConv; //导入依赖的package包/类
/**
 * Verifies whether the current settings of the bean are within the limits given by the
 * USPS Intelligent Mail specification.
 */
public void verifySettings() {
    if (getBarHeight() < UnitConv.in2mm(0.125)) {
        throw new IllegalArgumentException("Resulting bar height is smaller than 0.125in!");
    }
    if (getBarHeight() > UnitConv.in2mm(0.165)) {
        throw new IllegalArgumentException("Resulting bar height is larger than 0.165in!");
    }

    if (getModuleWidth() < UnitConv.in2mm(0.015)) {
        throw new IllegalArgumentException("Module width is smaller than 0.015in!");
    }
    if (getModuleWidth() > UnitConv.in2mm(0.025)) {
        throw new IllegalArgumentException("Module width is larger than 0.025in!");
    }
    
    if (getIntercharGapWidth() < UnitConv.in2mm(0.012)) {
        throw new IllegalArgumentException("Space between bars is smaller than 0.012in!");
    }
    if (getIntercharGapWidth() > UnitConv.in2mm(0.040)) {
        throw new IllegalArgumentException("Space between bars is larger than 0.040in!");
    }
    
    double pitch = UnitConv.mm2in(getModuleWidth() + getIntercharGapWidth());
    double barsPerInch = 1 / pitch;
    if (barsPerInch < 20) {
        throw new IllegalArgumentException(
                "Resulting barcode pitch is smaller than 20 bars per inch!");
    }
    if (barsPerInch > 24) {
        throw new IllegalArgumentException(
                "Resulting barcode pitch is larger than 24 bars per inch");
    }
}
 

开发者ID:thanakrit,
项目名称:barcode4j,
代码行数:38,
代码来源:USPSIntelligentMailBean.java

示例11: POSTNETBean

点赞 2

import org.krysalis.barcode4j.tools.UnitConv; //导入依赖的package包/类
/** Create a new instance. */
public POSTNETBean() {
    super();
    this.msgPos = HumanReadablePlacement.HRP_NONE; //Different default than normal
    this.moduleWidth = UnitConv.in2mm(DEFAULT_MODULE_WIDTH);
    this.intercharGapWidth = this.moduleWidth;
    setQuietZone(UnitConv.in2mm(DEFAULT_HORZ_QUIET_ZONE_INCH));
    setVerticalQuietZone(UnitConv.in2mm(DEFAULT_VERT_QUIET_ZONE_INCH));
    setBarHeight(UnitConv.in2mm(DEFAULT_TALL_BAR_HEIGHT));
}
 

开发者ID:thanakrit,
项目名称:barcode4j,
代码行数:11,
代码来源:POSTNETBean.java

示例12: setBaseAttributes

点赞 2

import org.krysalis.barcode4j.tools.UnitConv; //导入依赖的package包/类
protected void setBaseAttributes(Barcode4jComponent barcodeComponent)
{
	JRStyle style = getElementStyle();
	if (style != null)
	{
		String fontName = style.getFontName();
		if (fontName != null)
		{
			barcodeBean.setFontName(fontName);
		}
		
		Float fontSize = style.getFontsize();
		if (fontSize != null)
		{
			double barFontSize = UnitConv.pt2mm(fontSize.floatValue());
			barcodeBean.setFontSize(barFontSize);
		}
	}
	
	Double moduleWidth = barcodeComponent.getModuleWidth();
	if (moduleWidth != null)
	{
		barcodeBean.setModuleWidth(UnitConv.pt2mm(moduleWidth.doubleValue()));
	}
	
	TextPositionEnum textPlacement = barcodeComponent.getTextPositionValue();
	if (textPlacement != null)
	{
		barcodeBean.setMsgPosition(
				HumanReadablePlacement.byName(textPlacement.getName()));
	}
	
	Double quietZone = barcodeComponent.getQuietZone();
	if (quietZone != null)
	{
		barcodeBean.doQuietZone(true);
		barcodeBean.setQuietZone(UnitConv.pt2mm(quietZone.doubleValue()));
	}
	
	Double vQuietZone = barcodeComponent.getVerticalQuietZone();
	if (vQuietZone != null)
	{
		barcodeBean.setVerticalQuietZone(UnitConv.pt2mm(vQuietZone.doubleValue()));
	}

	// FIXME DataMatrix?
	double barcodeHeight;
	if (BarcodeUtils.isVertical(barcodeComponent))
	{
		barcodeHeight = UnitConv.pt2mm(componentElement.getWidth());
	}
	else
	{
		barcodeHeight = UnitConv.pt2mm(componentElement.getHeight());
	}
	barcodeBean.setHeight(barcodeHeight);
}
 

开发者ID:TIBCOSoftware,
项目名称:jasperreports,
代码行数:58,
代码来源:AbstractBarcodeEvaluator.java

示例13: generate

点赞 2

import org.krysalis.barcode4j.tools.UnitConv; //导入依赖的package包/类
private void generate() throws IOException {
       // Erstelle PDF417 Barcode
       PDF417Bean bean = new PDF417Bean();

       // Setze das Fehlerkorekturlevel  
       bean.setErrorCorrectionLevel(2);

       // Nur zwei Spalten mit Inhalt
       bean.setColumns(2);

       bean.setModuleWidth(UnitConv.in2mm(10.0f / dpi));
       bean.doQuietZone(false);

       BitmapCanvasProvider bitmapCanvasProvider = new BitmapCanvasProvider(
               dpi, BufferedImage.TYPE_BYTE_BINARY, antiAlias, orientation);

       // Erstelle den Barcode
       bean.generateBarcode(bitmapCanvasProvider, uuid);

       // Beende die Barcode Generierung
       bitmapCanvasProvider.finish();

       // Hole das BufferedImage
       BufferedImage bufferedImage = bitmapCanvasProvider.getBufferedImage();


       int width = bufferedImage.getWidth();
       int height = bufferedImage.getHeight();

       //Add padding
       int padding = 2;
       width += 2 * padding;
       height += 3 * padding;

       BufferedImage bitmap = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_BINARY);
       Graphics2D g2d = (Graphics2D)bitmap.getGraphics();
       g2d.setBackground(Color.white);
       g2d.setColor(Color.black);
       g2d.clearRect(0, 0, bitmap.getWidth(), bitmap.getHeight());
       

       //Place the barcode symbol
       AffineTransform symbolPlacement = new AffineTransform();
       symbolPlacement.translate(padding, padding);
       g2d.drawRenderedImage(bufferedImage, symbolPlacement);

       //Add text lines (or anything else you might want to add)

       g2d.dispose();

       //Encode bitmap as file
       String mime = "image/png";
       OutputStream out = new FileOutputStream(file);
       try {
           final BitmapEncoder encoder = BitmapEncoderRegistry.getInstance(mime);
           encoder.encode(bitmap, out, mime, dpi);
       } finally {
           out.close();
       }
       
}
 

开发者ID:tiv-source,
项目名称:tiv-page,
代码行数:62,
代码来源:CreateBarcode.java

示例14: deviceText

点赞 2

import org.krysalis.barcode4j.tools.UnitConv; //导入依赖的package包/类
/** {@inheritDoc} */
public void deviceText(
        String text,
        double x1,
        double x2,
        double y1,
        String fontName,
        double fontSize,
        TextAlignment textAlign) {
    if (DEBUG) {
        System.out.println("deviceText " + x1 + " " + x2 + " " 
                + (x2 - x1) + " " + y1 + " " + text);
        System.out.println("fontSize: " 
                + fontSize + "mm (" + UnitConv.mm2pt(fontSize) + "pt)");
    }
    Font font = new Font(fontName, Font.PLAIN, 
        (int)Math.round(fontSize));
    FontRenderContext frc = g2d.getFontRenderContext();
    GlyphVector gv = font.createGlyphVector(frc, text);
    
    final float textwidth = (float)gv.getLogicalBounds().getWidth();
    final float distributableSpace = (float)((x2 - x1) - textwidth);
    final float intercharSpace;
    if (gv.getNumGlyphs() > 1) {
        intercharSpace = distributableSpace / (gv.getNumGlyphs() - 1);
    } else {
        intercharSpace = 0.0f;
    }
    if (DEBUG) {
        System.out.println(gv.getLogicalBounds()
                + " " + gv.getVisualBounds());
        System.out.println("textwidth=" + textwidth);
        System.out.println("distributableSpace=" + distributableSpace);
        System.out.println("intercharSpace=" + intercharSpace);
    }
    final float indent;
    if (textAlign == TextAlignment.TA_JUSTIFY) {
        if (text.length() > 1) {
            indent = 0.0f;
        } else {
            indent = distributableSpace / 2; //Center if only one character
        }
    } else if (textAlign == TextAlignment.TA_CENTER) {
        indent = distributableSpace / 2;
    } else if (textAlign == TextAlignment.TA_RIGHT) {
        indent = distributableSpace;
    } else {
        indent = 0.0f;
    }
    Font oldFont = g2d.getFont();
    g2d.setFont(font);
    if (textAlign == TextAlignment.TA_JUSTIFY) {
        //move the individual glyphs
        for (int i = 0; i < gv.getNumGlyphs(); i++) {
            Point2D point = gv.getGlyphPosition(i);
            point.setLocation(point.getX() + i * intercharSpace, point.getY());
            gv.setGlyphPosition(i, point);
            if (DEBUG) {
                System.out.println(i + " " + point 
                        + " " + gv.getGlyphLogicalBounds(i).getBounds2D());
                System.out.println(i + " " + text.substring(i, i + 1) 
                    + " " + gv.getGlyphMetrics(i).getBounds2D());
            }
        }
    }
    g2d.drawGlyphVector(gv, (float)x1 + indent, (float)y1);
    g2d.setFont(oldFont);
    if (DEBUG) {
        g2d.setStroke(new BasicStroke(0.01f));
        g2d.draw(new Rectangle2D.Double(x1, y1 - fontSize, 
            x2 - x1, fontSize));
        g2d.draw(new Rectangle2D.Double(x1 + indent, 
            y1 - fontSize, 
            textwidth, fontSize));
    }
}
 

开发者ID:thanakrit,
项目名称:barcode4j,
代码行数:77,
代码来源:Java2DCanvasProvider.java

示例15: formatmm

点赞 2

import org.krysalis.barcode4j.tools.UnitConv; //导入依赖的package包/类
private String formatmm(double coord) {
    return getDecimalFormat().format(UnitConv.mm2pt(coord));
}
 

开发者ID:thanakrit,
项目名称:barcode4j,
代码行数:4,
代码来源:EPSCanvasProvider.java

示例16: writeHeader

点赞 2

import org.krysalis.barcode4j.tools.UnitConv; //导入依赖的package包/类
private void writeHeader(double width, double height) throws IOException {
    writer.write("%!PS-Adobe-3.0 EPSF-3.0\n");
    double widthpt = UnitConv.mm2pt(width);
    double heightpt = UnitConv.mm2pt(height);
    writer.write("%%BoundingBox: 0 0 "
            + Math.round(Math.ceil(widthpt)) + " "
            + Math.round(Math.ceil(heightpt)) + "\n");
    writer.write("%%HiResBoundingBox: 0 0 "
            + format(widthpt) + " "
            + format(heightpt) + "\n");
    writer.write("%%Creator: Barcode4J (http://barcode4j.krysalis.org)\n");
    final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
    writer.write("%%CreationDate: " + sdf.format(new java.util.Date()) + "\n");
    writer.write("%%LanguageLevel: 1\n");
    writer.write("%%EndComments\n");
    writer.write("%%BeginProlog\n");
    writer.write("%%BeginProcSet: barcode4j-procset 1.1\n");
    writer.write("/rf {\n"); //rect fill: x y w h rf
    writer.write("newpath\n");
    writer.write("4 -2 roll moveto\n");
    writer.write("dup neg 0 exch rlineto\n");
    writer.write("exch 0 rlineto\n");
    writer.write("0 neg exch rlineto\n");
    writer.write("closepath fill\n");
    writer.write("} def\n");

    writer.write("/ct {\n"); //centered text: (text) middle-x y ct
    writer.write("moveto dup stringwidth\n");
    writer.write("2 div neg exch 2 div neg exch\n");
    writer.write("rmoveto show\n");
    writer.write("} def\n");

    writer.write("/rt {\n"); //right-aligned text: (text) x1 x2 y rt
    //Calc string width
    writer.write("4 -1 roll dup stringwidth pop\n");
    //Calc available width (x2-x1)
    writer.write("5 -2 roll 1 index sub\n");
    //Calc (text-width - avail-width) = diffx
    writer.write("3 -1 roll sub\n");
    //Calc x = (x1 + diffx)
    writer.write("add\n");
    //moveto and finally show
    writer.write("3 -1 roll moveto show\n");
    writer.write("} def\n");

    writer.write("/jt {\n"); //justified: (text) x1 x2 y jt
    //Calc string width
    writer.write("4 -1 roll dup stringwidth pop\n");
    //Calc available width (x2-x1)
    writer.write("5 -2 roll 1 index sub\n");
    //Calc (text-width - avail-width)
    writer.write("3 -1 roll sub\n");
    //Get string length
    writer.write("2 index length\n");
    //avail-width / (string-length - 1) = distributable-space
    writer.write("1 sub div\n");
    //setup moveto and ashow
    writer.write("0 4 -1 roll 4 -1 roll 5 -1 roll\n");
    writer.write("moveto ashow\n");
    writer.write("} def\n");

    writer.write("%%EndProcSet: barcode4j-procset 1.0\n");
    writer.write("%%EndProlog\n");
}
 

开发者ID:thanakrit,
项目名称:barcode4j,
代码行数:65,
代码来源:EPSCanvasProvider.java

示例17: mpt2mm

点赞 2

import org.krysalis.barcode4j.tools.UnitConv; //导入依赖的package包/类
public double mpt2mm(double mpt) {
    return UnitConv.pt2mm(mpt / 1000);
}
 

开发者ID:thanakrit,
项目名称:barcode4j,
代码行数:4,
代码来源:BarcodeArea.java

示例18: layout

点赞 2

import org.krysalis.barcode4j.tools.UnitConv; //导入依赖的package包/类
/**
 * layout this formatting object.
 *
 * @param area the area to layout the object into
 *
 * @return the status of the layout
 */
public int layout(final Area area) throws FOPException {
    if (!(area instanceof ForeignObjectArea)) {
        // this is an error
        throw new FOPException("Barcode not in fo:instream-foreign-object");
    }

    if (this.marker == START) {
        this.fs = area.getFontState();

        this.marker = 0;
    }

    //MessageHandler.logln("Creating barcode area");

    /* create a barcode area */
    /* if width and height are zero, get the bounds of the content. */
    final ForeignObjectArea foa = (ForeignObjectArea)area;

    Element e = this.doc.getDocumentElement();

    //if(!e.hasAttributeNS(XMLSupport.XMLNS_NAMESPACE_URI, "xmlns")) {
        e.setAttributeNS(XMLNS_NAMESPACE_URI, "xmlns", BarcodeConstants.NAMESPACE);
    //}

    Configuration cfg = ConfigurationUtil.buildConfiguration(this.doc);
    try {
        String msg = ConfigurationUtil.getMessage(cfg);
        msg = MessageUtil.unescapeUnicode(msg);

        int orientation = cfg.getAttributeAsInteger("orientation", 0);

        //MessageHandler.logln("Barcode message: " + msg);
        final String renderMode = cfg.getAttribute("render-mode", "native");
        //MessageHandler.logln("Render mode: " + renderMode);

        BarcodeGenerator bargen = BarcodeUtil.getInstance().
                createBarcodeGenerator(cfg);
        String expandedMsg = VariableUtil.getExpandedMessage(foa.getPage(), msg);
        BarcodeDimension bardim = bargen.calcDimensions(expandedMsg);
        final float w = (float)UnitConv.mm2pt(bardim.getWidthPlusQuiet(orientation)) * 1000;
        final float h = (float)UnitConv.mm2pt(bardim.getHeightPlusQuiet(orientation)) * 1000;


        BarcodeArea barcodeArea = createArea(fs, w, h);
        barcodeArea.setParent(foa);
        barcodeArea.setPage(foa.getPage());
        barcodeArea.setBarcode(bargen, expandedMsg, renderMode, orientation);
        barcodeArea.start();
        barcodeArea.end();

        /* add the SVG area to the containing area */
        foa.setObject(barcodeArea);
        foa.setIntrinsicWidth(barcodeArea.getWidth());
        foa.setIntrinsicHeight(barcodeArea.getHeight());

        /* return status */
        return Status.OK;
    } catch (ConfigurationException ce) {
        MessageHandler.errorln("Error in barcode XML: " + ce.getMessage());
        throw new FOPException("Error in barcode XML", ce);
    } catch (BarcodeException be) {
        MessageHandler.errorln("Error generating barcode: " + be.getMessage());
        throw new FOPException("Error generating barcode", be);
    }
}
 

开发者ID:thanakrit,
项目名称:barcode4j,
代码行数:73,
代码来源:BarcodeElement.java

示例19: renderUsingGraphics2D

点赞 2

import org.krysalis.barcode4j.tools.UnitConv; //导入依赖的package包/类
private boolean renderUsingGraphics2D(RendererContext context,
        final BarcodeGenerator bargen,
        final String msg, final int orientation) throws IOException {

    Graphics2DAdapter g2dAdapter = context.getRenderer().getGraphics2DAdapter();
    if (g2dAdapter != null) {
        final BarcodeDimension barDim = bargen.calcDimensions(msg);

        // get the 'width' and 'height' attributes of the barcode
        final int w = (int)Math.ceil(UnitConv.mm2pt(barDim.getWidthPlusQuiet())) * 1000;
        final int h = (int)Math.ceil(UnitConv.mm2pt(barDim.getHeightPlusQuiet())) * 1000;

        Graphics2DImagePainter painter = new Graphics2DImagePainter() {

            public void paint(Graphics2D g2d, Rectangle2D area) {
                Java2DCanvasProvider canvas = new Java2DCanvasProvider(null, orientation);
                canvas.setGraphics2D(g2d);
                g2d.scale(area.getWidth() / barDim.getWidthPlusQuiet(),
                        area.getHeight() / barDim.getHeightPlusQuiet());
                bargen.generateBarcode(canvas, msg);
            }

            public Dimension getImageSize() {
                return new Dimension(w, h);
            }

        };

        if (DEBUG) {
            System.out.println(" --> Java2D");
        }
        g2dAdapter.paintImage(painter,
                context,
                ((Integer)context.getProperty("xpos")).intValue(),
                ((Integer)context.getProperty("ypos")).intValue(),
                ((Integer)context.getProperty("width")).intValue(),
                ((Integer)context.getProperty("height")).intValue());
        return true;
    } else {
        //We can't paint the barcode
        return false;
    }
}
 

开发者ID:thanakrit,
项目名称:barcode4j,
代码行数:44,
代码来源:BarcodeXMLHandler.java

示例20: drawCenteredChar

点赞 1

import org.krysalis.barcode4j.tools.UnitConv; //导入依赖的package包/类
/**
 * Draws a centered character on a canvas.
 * @param canvas the canvas to paint on
 * @param bean the barcode bean to get the font settings from
 * @param ch the character
 * @param x1 the left boundary
 * @param x2 the right boundary
 * @param y1 the y coordinate of the font's baseline
 */
public static void drawCenteredChar(Canvas canvas, AbstractBarcodeBean bean, 
                                char ch, 
                                double x1, double x2, double y1) {
    canvas.drawCenteredChar(ch, x1, x2, 
            y1 - UnitConv.pt2mm(bean.getFontSize()) * 0.2, 
            bean.getFontName(), bean.getFontSize());
}
 

开发者ID:thanakrit,
项目名称:barcode4j,
代码行数:17,
代码来源:DrawingUtil.java

示例21: drawText

点赞 1

import org.krysalis.barcode4j.tools.UnitConv; //导入依赖的package包/类
/**
 * Draws text on a canvas.
 * @param canvas the canvas to paint on
 * @param bean the barcode bean to get the font settings from
 * @param text the text to paint
 * @param x1 the left boundary
 * @param x2 the right boundary
 * @param y1 the y coordinate of the font's baseline
 * @param textAlign the text alignment
 */
public static void drawText(Canvas canvas, AbstractBarcodeBean bean, 
                                String text, 
                                double x1, double x2, double y1,
                                TextAlignment textAlign) {
    canvas.drawText(text, x1, x2, 
            y1 - UnitConv.pt2mm(bean.getFontSize()) * 0.2, 
            bean.getFontName(), bean.getFontSize(),
            textAlign);
}
 

开发者ID:thanakrit,
项目名称:barcode4j,
代码行数:20,
代码来源:DrawingUtil.java


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)