Package com.lowagie.text

Examples of com.lowagie.text.LwgRectangle


    }

    void applyRotation(PdfDictionary pageN, ByteBuffer out) {
        if (!rotateContents)
            return;
        LwgRectangle page = reader.getPageSizeWithRotation(pageN);
        int rotation = page.getRotation();
        switch (rotation) {
            case 90:
                out.append(PdfContents.ROTATE90);
                out.append(page.getTop());
                out.append(' ').append('0').append(PdfContents.ROTATEFINAL);
                break;
            case 180:
                out.append(PdfContents.ROTATE180);
                out.append(page.getRight());
                out.append(' ');
                out.append(page.getTop());
                out.append(PdfContents.ROTATEFINAL);
                break;
            case 270:
                out.append(PdfContents.ROTATE270);
                out.append('0').append(' ');
                out.append(page.getRight());
                out.append(PdfContents.ROTATEFINAL);
                break;
        }
    }
View Full Code Here


            }
        }
    }

    private static void moveRectangle(PdfDictionary dic2, PdfReader r, int pageImported, PdfName key, String name) {
        LwgRectangle m = r.getBoxSize(pageImported, name);
        if (m == null)
            dic2.remove(key);
        else
            dic2.put(key, new PdfRectangle(m));
    }
View Full Code Here

        PageStamp ps = (PageStamp)pagesToContent.get(pageN);
        ps.replacePoint = ps.over.getInternalBuffer().size();
    }

    void insertPage(int pageNumber, LwgRectangle mediabox) {
        LwgRectangle media = new LwgRectangle(mediabox);
        int rotation = media.getRotation() % 360;
        PdfDictionary page = new PdfDictionary(PdfName.PAGE);
        PdfDictionary resources = new PdfDictionary();
        PdfArray procset = new PdfArray();
        procset.add(PdfName.PDF);
        procset.add(PdfName.TEXT);
View Full Code Here

                                }
                            }
                        }
                    }
                    if (app != null) {
                        LwgRectangle box = PdfReader.getNormalizedRectangle(merged.getAsArray(PdfName.RECT));
                        PdfContentByte cb = getOverContent(page);
                        cb.setLiteral("Q ");
                        cb.addTemplate(app, box.getLeft(), box.getBottom());
                        cb.setLiteral("q ");
                    }
                }
                if (partialFlattening.isEmpty())
                    continue;
View Full Code Here

              }
            }
          }
          if (app != null)
          {
            LwgRectangle box = PdfReader.getNormalizedRectangle(annDic.getAsArray(PdfName.RECT));
            PdfContentByte cb = getOverContent(page);
            cb.setLiteral("Q ");
            cb.addTemplate(app, box.getLeft(), box.getBottom());
            cb.setLiteral("q ");
          }
        }
      }
      for (int idx = 0; idx < annots.size(); ++idx)
View Full Code Here

                    markUsed(annots);
                    if (!annot.isUsed()) {
                        PdfRectangle rect = (PdfRectangle)annot.get(PdfName.RECT);
                        if (rect != null && (rect.left() != 0 || rect.right() != 0 || rect.top() != 0 || rect.bottom() != 0)) {
                            int rotation = reader.getPageRotation(pageN);
                            LwgRectangle pageSize = reader.getPageSizeWithRotation(pageN);
                            switch (rotation) {
                                case 90:
                                    annot.put(PdfName.RECT, new PdfRectangle(
                                    pageSize.getTop() - rect.top(),
                                    rect.right(),
                                    pageSize.getTop() - rect.bottom(),
                                    rect.left()));
                                    break;
                                case 180:
                                    annot.put(PdfName.RECT, new PdfRectangle(
                                    pageSize.getRight() - rect.left(),
                                    pageSize.getTop() - rect.bottom(),
                                    pageSize.getRight() - rect.right(),
                                    pageSize.getTop() - rect.top()));
                                    break;
                                case 270:
                                    annot.put(PdfName.RECT, new PdfRectangle(
                                    rect.bottom(),
                                    pageSize.getRight() - rect.left(),
                                    rect.top(),
                                    pageSize.getRight() - rect.right()));
                                    break;
                            }
                        }
                    }
                }
View Full Code Here

     * @return the template
     * @see #placeBarcode(PdfContentByte cb, Color barColor, Color textColor)
     */   
    public PdfTemplate createTemplateWithBarcode(PdfContentByte cb, Color barColor, Color textColor) {
        PdfTemplate tp = cb.createTemplate(0, 0);
        LwgRectangle rect = placeBarcode(tp, barColor, textColor);
        tp.setBoundingBox(rect);
        return tp;
    }
View Full Code Here

        if (generateChecksum)
            ++len;
        float fullWidth = len * (3 * x + 2 * x * n) + (6 + n ) * x;
        fullWidth = Math.max(fullWidth, fontX);
        float fullHeight = barHeight + fontY;
        return new LwgRectangle(fullWidth, fullHeight);
    }
View Full Code Here

     * @throws DocumentException on error
     * @return the button appearance
     */   
    public PdfAppearance getAppearance() throws IOException, DocumentException {
        PdfAppearance app = getBorderAppearance();
        LwgRectangle box = new LwgRectangle(app.getBoundingBox());
        if ((text == null || text.length() == 0) && (layout == LAYOUT_LABEL_ONLY || (image == null && template == null && iconReference == null))) {
            return app;
        }
        if (layout == LAYOUT_ICON_ONLY && image == null && template == null && iconReference == null)
            return app;
        BaseFont ufont = getRealFont();
        boolean borderExtra = borderStyle == PdfBorderDictionary.STYLE_BEVELED || borderStyle == PdfBorderDictionary.STYLE_INSET;
        float h = box.getHeight() - borderWidth * 2;
        float bw2 = borderWidth;
        if (borderExtra) {
            h -= borderWidth * 2;
            bw2 *= 2;
        }
        float offsetX = (borderExtra ? 2 * borderWidth : borderWidth);
        offsetX = Math.max(offsetX, 1);
        float offX = Math.min(bw2, offsetX);
        tp = null;
        float textX = Float.NaN;
        float textY = 0;
        float fsize = fontSize;
        float wt = box.getWidth() - 2 * offX - 2;
        float ht = box.getHeight() - 2 * offX;
        float adj = (iconFitToBounds ? 0 : offX + 1);
        int nlayout = layout;
        if (image == null && template == null && iconReference == null)
            nlayout = LAYOUT_LABEL_ONLY;
        LwgRectangle iconBox = null;
        while (true) {
            switch (nlayout) {
                case LAYOUT_LABEL_ONLY:
                case LAYOUT_LABEL_OVER_ICON:
                    if (text != null && text.length() > 0 && wt > 0 && ht > 0) {
                        fsize = calculateFontSize(wt, ht);
                        textX = (box.getWidth() - ufont.getWidthPoint(text, fsize)) / 2;
                        textY = (box.getHeight() - ufont.getFontDescriptor(BaseFont.ASCENT, fsize)) / 2;
                    }
                case LAYOUT_ICON_ONLY:
                    if (nlayout == LAYOUT_LABEL_OVER_ICON || nlayout == LAYOUT_ICON_ONLY)
                        iconBox = new LwgRectangle(box.getLeft() + adj, box.getBottom() + adj, box.getRight() - adj, box.getTop() - adj);
                    break;
                case LAYOUT_ICON_TOP_LABEL_BOTTOM:
                    if (text == null || text.length() == 0 || wt <= 0 || ht <= 0) {
                        nlayout = LAYOUT_ICON_ONLY;
                        continue;
                    }
                    float nht = box.getHeight() * 0.35f - offX;
                    if (nht > 0)
                        fsize = calculateFontSize(wt, nht);
                    else
                        fsize = 4;
                    textX = (box.getWidth() - ufont.getWidthPoint(text, fsize)) / 2;
                    textY = offX - ufont.getFontDescriptor(BaseFont.DESCENT, fsize);
                    iconBox = new LwgRectangle(box.getLeft() + adj, textY + fsize, box.getRight() - adj, box.getTop() - adj);
                    break;
                case LAYOUT_LABEL_TOP_ICON_BOTTOM:
                    if (text == null || text.length() == 0 || wt <= 0 || ht <= 0) {
                        nlayout = LAYOUT_ICON_ONLY;
                        continue;
                    }
                    nht = box.getHeight() * 0.35f - offX;
                    if (nht > 0)
                        fsize = calculateFontSize(wt, nht);
                    else
                        fsize = 4;
                    textX = (box.getWidth() - ufont.getWidthPoint(text, fsize)) / 2;
                    textY = box.getHeight() - offX - fsize;
                    if (textY < offX)
                        textY = offX;
                    iconBox = new LwgRectangle(box.getLeft() + adj, box.getBottom() + adj, box.getRight() - adj, textY + ufont.getFontDescriptor(BaseFont.DESCENT, fsize));
                    break;
                case LAYOUT_LABEL_LEFT_ICON_RIGHT:
                    if (text == null || text.length() == 0 || wt <= 0 || ht <= 0) {
                        nlayout = LAYOUT_ICON_ONLY;
                        continue;
                    }
                    float nw = box.getWidth() * 0.35f - offX;
                    if (nw > 0)
                        fsize = calculateFontSize(wt, nw);
                    else
                        fsize = 4;
                    if (ufont.getWidthPoint(text, fsize) >= wt) {
                        nlayout = LAYOUT_LABEL_ONLY;
                        fsize = fontSize;
                        continue;
                    }
                    textX = offX + 1;
                    textY = (box.getHeight() - ufont.getFontDescriptor(BaseFont.ASCENT, fsize)) / 2;
                    iconBox = new LwgRectangle(textX + ufont.getWidthPoint(text, fsize), box.getBottom() + adj, box.getRight() - adj, box.getTop() - adj);
                    break;
                case LAYOUT_ICON_LEFT_LABEL_RIGHT:
                    if (text == null || text.length() == 0 || wt <= 0 || ht <= 0) {
                        nlayout = LAYOUT_ICON_ONLY;
                        continue;
                    }
                    nw = box.getWidth() * 0.35f - offX;
                    if (nw > 0)
                        fsize = calculateFontSize(wt, nw);
                    else
                        fsize = 4;
                    if (ufont.getWidthPoint(text, fsize) >= wt) {
                        nlayout = LAYOUT_LABEL_ONLY;
                        fsize = fontSize;
                        continue;
                    }
                    textX = box.getWidth() - ufont.getWidthPoint(text, fsize) - offX - 1;
                    textY = (box.getHeight() - ufont.getFontDescriptor(BaseFont.ASCENT, fsize)) / 2;
                    iconBox = new LwgRectangle(box.getLeft() + adj, box.getBottom() + adj, textX - 1, box.getTop() - adj);
                    break;
            }
            break;
        }
        if (textY < box.getBottom() + offX)
            textY = box.getBottom() + offX;
        if (iconBox != null && (iconBox.getWidth() <= 0 || iconBox.getHeight() <= 0))
            iconBox = null;
        boolean haveIcon = false;
        float boundingBoxWidth = 0;
        float boundingBoxHeight = 0;
        PdfArray matrix = null;
        if (iconBox != null) {
            if (image != null) {
                tp = new PdfTemplate(writer);
                tp.setBoundingBox(new LwgRectangle(image));
                writer.addDirectTemplateSimple(tp, PdfName.FRM);
                tp.addImage(image, image.getWidth(), 0, 0, image.getHeight(), 0, 0);
                haveIcon = true;
                boundingBoxWidth = tp.getBoundingBox().getWidth();
                boundingBoxHeight = tp.getBoundingBox().getHeight();
            }
            else if (template != null) {
                tp = new PdfTemplate(writer);
                tp.setBoundingBox(new LwgRectangle(template.getWidth(), template.getHeight()));
                writer.addDirectTemplateSimple(tp, PdfName.FRM);
                tp.addTemplate(template, template.getBoundingBox().getLeft(), template.getBoundingBox().getBottom());
                haveIcon = true;
                boundingBoxWidth = tp.getBoundingBox().getWidth();
                boundingBoxHeight = tp.getBoundingBox().getHeight();
            }
            else if (iconReference != null) {
                PdfDictionary dic = (PdfDictionary)PdfReader.getPdfObject(iconReference);
                if (dic != null) {
                    LwgRectangle r2 = PdfReader.getNormalizedRectangle(dic.getAsArray(PdfName.BBOX));
                    matrix = dic.getAsArray(PdfName.MATRIX);
                    haveIcon = true;
                    boundingBoxWidth = r2.getWidth();
                    boundingBoxHeight = r2.getHeight();
                }
            }
        }
        if (haveIcon) {
            float icx = iconBox.getWidth() / boundingBoxWidth;
View Full Code Here

     * any, will occupy. The lower left corner is always (0, 0).
     * @return the size the barcode occupies.
     */
    public LwgRectangle getBarcodeSize() {
        float width = ((code.length() + 1) * 5 + 1) * n + x;
        return new LwgRectangle(width, barHeight);
    }
View Full Code Here

TOP

Related Classes of com.lowagie.text.LwgRectangle

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.