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

📄 bidiline.java

📁 一个java操作pdf文件的开发包,很好用的.
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                char c = text[src];                if (c < 0x0600 || c > 0x06ff)                    break;                ++src;            }            int arabicWordSize = src - startArabicIdx;            int size = arabic.shape(text, startArabicIdx, arabicWordSize, text, dest, arabicWordSize);            if (startArabicIdx != dest) {                for (int k = 0; k < size; ++k) {                    detailChunks[dest] = detailChunks[startArabicIdx];                    orderLevels[dest++] = orderLevels[startArabicIdx++];                }            }            else                dest += size;        }    }           public PdfLine processLine(float width, int alignment, int runDirection) {        save();        if (currentChar >= totalTextLength) {            boolean hasText = getParagraph(runDirection);            if (!hasText)                return null;            if (totalTextLength == 0) {                ArrayList ar = new ArrayList();                PdfChunk ck = new PdfChunk("", detailChunks[0]);                ar.add(ck);                return new PdfLine(0, 0, alignment, true, ar, (runDirection == PdfWriter.RUN_DIRECTION_RTL));            }        }        float originalWidth = width;        int lastSplit = -1;        if (currentChar != 0)            currentChar = trimLeftEx(currentChar, totalTextLength - 1);        int oldCurrentChar = currentChar;        char c = 0;        PdfChunk ck = null;        float charWidth = 0;        PdfChunk lastValidChunk = null;        for (; currentChar < totalTextLength; ++currentChar) {            c = text[currentChar];            if (PdfChunk.noPrint(c))                continue;            ck = detailChunks[currentChar];            charWidth = ck.getCharWidth(c);            if (ck.isExtSplitCharacter(c))                lastSplit = currentChar;            if (width - charWidth < 0)                break;            width -= charWidth;            lastValidChunk = ck;        }        boolean isRTL = (runDirection == PdfWriter.RUN_DIRECTION_RTL);        if (lastValidChunk == null) {            // not even a single char fit; must output the first char            ++currentChar;            return new PdfLine(0, 0, alignment, false, createArrayOfPdfChunks(currentChar - 1, currentChar - 1), isRTL);        }        if (currentChar >= totalTextLength) {            // there was more line than text            return new PdfLine(0, width, alignment, true, createArrayOfPdfChunks(oldCurrentChar, totalTextLength - 1), isRTL);        }        int newCurrentChar = trimRightEx(oldCurrentChar, currentChar - 1);        if (newCurrentChar < oldCurrentChar) {            // only WS            return new PdfLine(0, width, alignment, false, createArrayOfPdfChunks(oldCurrentChar, currentChar - 1), isRTL);        }        if (lastSplit == -1 || lastSplit >= newCurrentChar) {            // no split point or split point ahead of end            return new PdfLine(0, width + getWidth(newCurrentChar + 1, currentChar - 1), alignment, false, createArrayOfPdfChunks(oldCurrentChar, newCurrentChar), isRTL);        }        // standard split        currentChar = lastSplit + 1;        newCurrentChar = trimRightEx(oldCurrentChar, lastSplit);        if (newCurrentChar < oldCurrentChar) {            // only WS again            newCurrentChar = currentChar - 1;        }        return new PdfLine(0, originalWidth - getWidth(oldCurrentChar, newCurrentChar), alignment, false, createArrayOfPdfChunks(oldCurrentChar, newCurrentChar), isRTL);    }        /** Gets the width of a range of characters.     * @param startIdx the first index to calculate     * @param lastIdx the last inclusive index to calculate     * @return the sum of all widths     */        public float getWidth(int startIdx, int lastIdx) {        char c = 0;        PdfChunk ck = null;        float width = 0;        for (; startIdx <= lastIdx; ++startIdx) {            c = text[startIdx];            if (PdfChunk.noPrint(c))                continue;            width += detailChunks[startIdx].getCharWidth(c);        }        return width;    }        public ArrayList createArrayOfPdfChunks(int startIdx, int endIdx) {        boolean bidi = (runDirection == PdfWriter.RUN_DIRECTION_LTR || runDirection == PdfWriter.RUN_DIRECTION_RTL);        if (bidi)            reorder(startIdx, endIdx);        ArrayList ar = new ArrayList();        PdfChunk refCk = detailChunks[startIdx];        PdfChunk ck = null;        StringBuffer buf = new StringBuffer();        char c;        int idx = 0;        for (; startIdx <= endIdx; ++startIdx) {            idx = bidi ? indexChars[startIdx] : startIdx;            c = text[idx];            if (PdfChunk.noPrint(c))                continue;            ck = detailChunks[idx];            if (ck.isImage()) {                if (buf.length() > 0) {                    ar.add(new PdfChunk(buf.toString(), refCk));                    buf = new StringBuffer();                }                ar.add(ck);            }            else if (ck == refCk) {                buf.append(c);            }            else {                if (buf.length() > 0) {                    ar.add(new PdfChunk(buf.toString(), refCk));                    buf = new StringBuffer();                }                if (!ck.isImage())                    buf.append(c);                refCk = ck;            }        }        if (buf.length() > 0) {            ar.add(new PdfChunk(buf.toString(), refCk));        }        return ar;    }        public int trimRight(int startIdx, int endIdx) {        int idx = endIdx;        for (; idx >= startIdx; --idx) {            if (!isWS(text[idx]))                break;        }        return idx;    }        public int trimLeft(int startIdx, int endIdx) {        int idx = startIdx;        for (; idx <= endIdx; ++idx) {            if (!isWS(text[idx]))                break;        }        return idx;    }        public int trimRightEx(int startIdx, int endIdx) {        int idx = endIdx;        char c = 0;        for (; idx >= startIdx; --idx) {            c = text[idx];            if (!isWS(c) && !PdfChunk.noPrint(c))                break;        }        return idx;    }        public int trimLeftEx(int startIdx, int endIdx) {        int idx = startIdx;        char c = 0;        for (; idx <= endIdx; ++idx) {            c = text[idx];            if (!isWS(c) && !PdfChunk.noPrint(c))                break;        }        return idx;    }        public void reorder(int start, int end) {        byte maxLevel = orderLevels[start];        byte minLevel = maxLevel;        byte onlyOddLevels = maxLevel;        byte onlyEvenLevels = maxLevel;        for (int k = start + 1; k <= end; ++k) {            byte b = orderLevels[k];            if (b > maxLevel)                maxLevel = b;            else if (b < minLevel)                minLevel = b;            onlyOddLevels &= b;            onlyEvenLevels |= b;        }        if ((onlyEvenLevels & 1) == 0) // nothing to do            return;        if ((onlyOddLevels & 1) == 1) { // single inversion            flip(start, end + 1);            return;        }        minLevel |= 1;        for (; maxLevel >= minLevel; --maxLevel) {            int pstart = start;            for (;;) {                for (;pstart <= end; ++pstart) {                    if (orderLevels[pstart] >= maxLevel)                        break;                }                if (pstart > end)                    break;                int pend = pstart + 1;                for (; pend <= end; ++pend) {                    if (orderLevels[pend] < maxLevel)                        break;                }                flip(pstart, pend);                pstart = pend + 1;            }        }    }        public void flip(int start, int end) {        int mid = (start + end) / 2;        --end;        for (; start < mid; ++start, --end) {            int temp = indexChars[start];            indexChars[start] = indexChars[end];            indexChars[end] = temp;        }    }        public static boolean isWS(char c) {        return (c <= ' ');    }    static {        mirrorChars.put(0x0028, 0x0029); // LEFT PARENTHESIS        mirrorChars.put(0x0029, 0x0028); // RIGHT PARENTHESIS        mirrorChars.put(0x003C, 0x003E); // LESS-THAN SIGN        mirrorChars.put(0x003E, 0x003C); // GREATER-THAN SIGN        mirrorChars.put(0x005B, 0x005D); // LEFT SQUARE BRACKET        mirrorChars.put(0x005D, 0x005B); // RIGHT SQUARE BRACKET        mirrorChars.put(0x007B, 0x007D); // LEFT CURLY BRACKET        mirrorChars.put(0x007D, 0x007B); // RIGHT CURLY BRACKET        mirrorChars.put(0x00AB, 0x00BB); // LEFT-POINTING DOUBLE ANGLE QUOTATION MARK        mirrorChars.put(0x00BB, 0x00AB); // RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK        mirrorChars.put(0x2039, 0x203A); // SINGLE LEFT-POINTING ANGLE QUOTATION MARK        mirrorChars.put(0x203A, 0x2039); // SINGLE RIGHT-POINTING ANGLE QUOTATION MARK        mirrorChars.put(0x2045, 0x2046); // LEFT SQUARE BRACKET WITH QUILL        mirrorChars.put(0x2046, 0x2045); // RIGHT SQUARE BRACKET WITH QUILL        mirrorChars.put(0x207D, 0x207E); // SUPERSCRIPT LEFT PARENTHESIS        mirrorChars.put(0x207E, 0x207D); // SUPERSCRIPT RIGHT PARENTHESIS        mirrorChars.put(0x208D, 0x208E); // SUBSCRIPT LEFT PARENTHESIS        mirrorChars.put(0x208E, 0x208D); // SUBSCRIPT RIGHT PARENTHESIS        mirrorChars.put(0x2208, 0x220B); // ELEMENT OF        mirrorChars.put(0x2209, 0x220C); // NOT AN ELEMENT OF        mirrorChars.put(0x220A, 0x220D); // SMALL ELEMENT OF        mirrorChars.put(0x220B, 0x2208); // CONTAINS AS MEMBER        mirrorChars.put(0x220C, 0x2209); // DOES NOT CONTAIN AS MEMBER        mirrorChars.put(0x220D, 0x220A); // SMALL CONTAINS AS MEMBER        mirrorChars.put(0x2215, 0x29F5); // DIVISION SLASH        mirrorChars.put(0x223C, 0x223D); // TILDE OPERATOR        mirrorChars.put(0x223D, 0x223C); // REVERSED TILDE        mirrorChars.put(0x2243, 0x22CD); // ASYMPTOTICALLY EQUAL TO        mirrorChars.put(0x2252, 0x2253); // APPROXIMATELY EQUAL TO OR THE IMAGE OF        mirrorChars.put(0x2253, 0x2252); // IMAGE OF OR APPROXIMATELY EQUAL TO        mirrorChars.put(0x2254, 0x2255); // COLON EQUALS        mirrorChars.put(0x2255, 0x2254); // EQUALS COLON        mirrorChars.put(0x2264, 0x2265); // LESS-THAN OR EQUAL TO        mirrorChars.put(0x2265, 0x2264); // GREATER-THAN OR EQUAL TO        mirrorChars.put(0x2266, 0x2267); // LESS-THAN OVER EQUAL TO        mirrorChars.put(0x2267, 0x2266); // GREATER-THAN OVER EQUAL TO        mirrorChars.put(0x2268, 0x2269); // [BEST FIT] LESS-THAN BUT NOT EQUAL TO        mirrorChars.put(0x2269, 0x2268); // [BEST FIT] GREATER-THAN BUT NOT EQUAL TO        mirrorChars.put(0x226A, 0x226B); // MUCH LESS-THAN        mirrorChars.put(0x226B, 0x226A); // MUCH GREATER-THAN        mirrorChars.put(0x226E, 0x226F); // [BEST FIT] NOT LESS-THAN        mirrorChars.put(0x226F, 0x226E); // [BEST FIT] NOT GREATER-THAN

⌨️ 快捷键说明

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