⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bidiline.java

📁 源码包含生成 PDF 和 HTML 的类库
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
/* * * Copyright 2002 Paulo Soares * * The contents of this file are subject to the Mozilla Public License Version 1.1 * (the "License"); you may not use this file except in compliance with the License. * You may obtain a copy of the License at http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License * for the specific language governing rights and limitations under the License. * * The Original Code is 'iText, a free JAVA-PDF library'. * * The Initial Developer of the Original Code is Bruno Lowagie. Portions created by * the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie. * All Rights Reserved. * Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer * are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved. * * Contributor(s): all the names of the contributors are added in the source code * where applicable. * * Alternatively, the contents of this file may be used under the terms of the * LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the * provisions of LGPL are applicable instead of those above.  If you wish to * allow use of your version of this file only under the terms of the LGPL * License and not to allow others to use your version of this file under * the MPL, indicate your decision by deleting the provisions above and * replace them with the notice and other provisions required by the LGPL. * If you do not delete the provisions above, a recipient may use your version * of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE. * * This library is free software; you can redistribute it and/or modify it * under the terms of the MPL as stated above or under the terms of the GNU * Library General Public License as published by the Free Software Foundation; * either version 2 of the License, or any later version. * * This library 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 Library general Public License for more * details. * * If you didn't download this code from the following link, you should check if * you aren't using an obsolete version: * http://www.lowagie.com/iText/ */package com.lowagie.text.pdf;import java.util.ArrayList;import com.lowagie.text.Chunk;import com.lowagie.text.Utilities;/** Does all the line bidirectional processing with PdfChunk assembly. * * @author Paulo Soares (psoares@consiste.pt) */public class BidiLine {	    protected int runDirection;    protected int pieceSize = 256;    protected char text[] = new char[pieceSize];    protected PdfChunk detailChunks[] = new PdfChunk[pieceSize];    protected int totalTextLength = 0;        protected byte orderLevels[] = new byte[pieceSize];    protected int indexChars[] = new int[pieceSize];        protected ArrayList chunks = new ArrayList();    protected int indexChunk = 0;    protected int indexChunkChar = 0;    protected int currentChar = 0;        protected int storedRunDirection;    protected char storedText[] = new char[0];    protected PdfChunk storedDetailChunks[] = new PdfChunk[0];    protected int storedTotalTextLength = 0;        protected byte storedOrderLevels[] = new byte[0];    protected int storedIndexChars[] = new int[0];        protected int storedIndexChunk = 0;    protected int storedIndexChunkChar = 0;    protected int storedCurrentChar = 0;        protected boolean shortStore;//    protected ArabicShaping arabic = new ArabicShaping(ArabicShaping.LETTERS_SHAPE | ArabicShaping.LENGTH_GROW_SHRINK | ArabicShaping.TEXT_DIRECTION_LOGICAL);    protected static final IntHashtable mirrorChars = new IntHashtable();    protected int arabicOptions;        /** Creates new BidiLine */    public BidiLine() {    }        public BidiLine(BidiLine org) {        runDirection = org.runDirection;        pieceSize = org.pieceSize;        text = (char[])org.text.clone();        detailChunks = (PdfChunk[])org.detailChunks.clone();        totalTextLength = org.totalTextLength;        orderLevels = (byte[])org.orderLevels.clone();        indexChars = (int[])org.indexChars.clone();        chunks = new ArrayList(org.chunks);        indexChunk = org.indexChunk;        indexChunkChar = org.indexChunkChar;        currentChar = org.currentChar;        storedRunDirection = org.storedRunDirection;        storedText = (char[])org.storedText.clone();        storedDetailChunks = (PdfChunk[])org.storedDetailChunks.clone();        storedTotalTextLength = org.storedTotalTextLength;        storedOrderLevels = (byte[])org.storedOrderLevels.clone();        storedIndexChars = (int[])org.storedIndexChars.clone();        storedIndexChunk = org.storedIndexChunk;        storedIndexChunkChar = org.storedIndexChunkChar;        storedCurrentChar = org.storedCurrentChar;        shortStore = org.shortStore;        arabicOptions = org.arabicOptions;    }        public boolean isEmpty() {        return (currentChar >= totalTextLength && indexChunk >= chunks.size());    }        public void clearChunks() {        chunks.clear();        totalTextLength = 0;        currentChar = 0;    }    public boolean getParagraph(int runDirection) {        this.runDirection = runDirection;        currentChar = 0;        totalTextLength = 0;        boolean hasText = false;        char c;        char uniC;        BaseFont bf;        for (; indexChunk < chunks.size(); ++indexChunk) {            PdfChunk ck = (PdfChunk)chunks.get(indexChunk);            bf = ck.font().getFont();            String s = ck.toString();            int len = s.length();            for (; indexChunkChar < len; ++indexChunkChar) {                c = s.charAt(indexChunkChar);                uniC = (char)bf.getUnicodeEquivalent(c);                if (uniC == '\r' || uniC == '\n') {                    // next condition is never true for CID                    if (uniC == '\r' && indexChunkChar + 1 < len && s.charAt(indexChunkChar + 1) == '\n')                        ++indexChunkChar;                    ++indexChunkChar;                    if (indexChunkChar >= len) {                        indexChunkChar = 0;                        ++indexChunk;                    }                    hasText = true;                    if (totalTextLength == 0)                        detailChunks[0] = ck;                    break;                }                addPiece(c, ck);            }            if (hasText)                break;            indexChunkChar = 0;        }        if (totalTextLength == 0)            return hasText;        // remove trailing WS        totalTextLength = trimRight(0, totalTextLength - 1) + 1;        if (totalTextLength == 0) {        	return true;        }                if (runDirection == PdfWriter.RUN_DIRECTION_LTR || runDirection == PdfWriter.RUN_DIRECTION_RTL) {            if (orderLevels.length < totalTextLength) {                orderLevels = new byte[pieceSize];                indexChars = new int[pieceSize];            }            ArabicLigaturizer.processNumbers(text, 0, totalTextLength, arabicOptions);            BidiOrder order = new BidiOrder(text, 0, totalTextLength, (byte)(runDirection == PdfWriter.RUN_DIRECTION_RTL ? 1 : 0));            byte od[] = order.getLevels();            for (int k = 0; k < totalTextLength; ++k) {                orderLevels[k] = od[k];                indexChars[k] = k;            }            doArabicShapping();            mirrorGlyphs();        }        totalTextLength = trimRightEx(0, totalTextLength - 1) + 1;        return true;    }        public void addChunk(PdfChunk chunk) {        chunks.add(chunk);    }        public void addChunks(ArrayList chunks) {        this.chunks.addAll(chunks);    }        public void addPiece(char c, PdfChunk chunk) {        if (totalTextLength >= pieceSize) {            char tempText[] = text;            PdfChunk tempDetailChunks[] = detailChunks;            pieceSize *= 2;            text = new char[pieceSize];            detailChunks = new PdfChunk[pieceSize];            System.arraycopy(tempText, 0, text, 0, totalTextLength);            System.arraycopy(tempDetailChunks, 0, detailChunks, 0, totalTextLength);        }        text[totalTextLength] = c;        detailChunks[totalTextLength++] = chunk;    }        public void save() {        if (indexChunk > 0) {            if (indexChunk >= chunks.size())                chunks.clear();            else {                for (--indexChunk; indexChunk >= 0; --indexChunk)                    chunks.remove(indexChunk);            }            indexChunk = 0;        }        storedRunDirection = runDirection;        storedTotalTextLength = totalTextLength;        storedIndexChunk = indexChunk;        storedIndexChunkChar = indexChunkChar;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -