Example usage for java.lang Character isMirrored

List of usage examples for java.lang Character isMirrored

Introduction

In this page you can find the example usage for java.lang Character isMirrored.

Prototype

public static boolean isMirrored(int codePoint) 

Source Link

Document

Determines whether the specified character (Unicode code point) is mirrored according to the Unicode specification.

Usage

From source file:Main.java

public static void main(String[] args) {
    int cp1 = 0x0c01;
    int cp2 = 0x003c;

    boolean b1 = Character.isMirrored(cp1);
    boolean b2 = Character.isMirrored(cp2);

    System.out.println((char) cp1 + " represents a mirrored character is " + b1);
    System.out.println((char) cp2 + " represents a mirrored character is " + b2);
}

From source file:Main.java

public static void main(String[] args) {
    for (char ch = Character.MIN_VALUE; ch < Character.MAX_VALUE; ch++) {
        if (Character.isMirrored(ch)) {
            String s = String.format("\\u%04x", (int) ch);
            System.out.println(s);
        }//from   w  w w .  java2 s.c om
    }

}

From source file:com.repeatability.pdf.PDFTextStripper.java

/**
 * Handles the LTR and RTL direction of the given words. The whole implementation stands and falls with the given
 * word. If the word is a full line, the results will be the best. If the word contains of single words or
 * characters, the order of the characters in a word or words in a line may wrong, due to RTL and LTR marks and
 * characters!/*from  w w w .  ja  va 2s.  c o  m*/
 * 
 * Based on http://www.nesterovsky-bros.com/weblog/2013/07/28/VisualToLogicalConversionInJava.aspx
 * 
 * @param word The word that shall be processed
 * @return new word with the correct direction of the containing characters
 */
// kwa
//private String handleDirection(String word)
protected String handleDirection(String word) {
    Bidi bidi = new Bidi(word, Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT);

    // if there is pure LTR text no need to process further
    if (!bidi.isMixed() && bidi.getBaseLevel() == Bidi.DIRECTION_LEFT_TO_RIGHT) {
        return word;
    }

    // collect individual bidi information
    int runCount = bidi.getRunCount();
    byte[] levels = new byte[runCount];
    Integer[] runs = new Integer[runCount];

    for (int i = 0; i < runCount; i++) {
        levels[i] = (byte) bidi.getRunLevel(i);
        runs[i] = i;
    }

    // reorder individual parts based on their levels
    Bidi.reorderVisually(levels, 0, runs, 0, runCount);

    // collect the parts based on the direction within the run
    StringBuilder result = new StringBuilder();

    for (int i = 0; i < runCount; i++) {
        int index = runs[i];
        int start = bidi.getRunStart(index);
        int end = bidi.getRunLimit(index);

        int level = levels[index];

        if ((level & 1) != 0) {
            for (; --end >= start;) {
                char character = word.charAt(end);
                if (Character.isMirrored(word.codePointAt(end))) {
                    if (MIRRORING_CHAR_MAP.containsKey(character)) {
                        result.append(MIRRORING_CHAR_MAP.get(character));
                    } else {
                        result.append(character);
                    }
                } else {
                    result.append(character);
                }
            }
        } else {
            result.append(word, start, end);
        }
    }

    return result.toString();
}

From source file:org.apache.pdfbox.text.PDFTextStripper.java

/**
 * Handles the LTR and RTL direction of the given words. The whole implementation stands and falls with the given
 * word. If the word is a full line, the results will be the best. If the word contains of single words or
 * characters, the order of the characters in a word or words in a line may wrong, due to RTL and LTR marks and
 * characters!//from   www . j  a v  a2 s. co m
 * 
 * Based on http://www.nesterovsky-bros.com/weblog/2013/07/28/VisualToLogicalConversionInJava.aspx
 * 
 * @param word The word that shall be processed
 * @return new word with the correct direction of the containing characters
 */
private String handleDirection(String word) {
    Bidi bidi = new Bidi(word, Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT);

    // if there is pure LTR text no need to process further
    if (!bidi.isMixed() && bidi.getBaseLevel() == Bidi.DIRECTION_LEFT_TO_RIGHT) {
        return word;
    }

    // collect individual bidi information
    int runCount = bidi.getRunCount();
    byte[] levels = new byte[runCount];
    Integer[] runs = new Integer[runCount];

    for (int i = 0; i < runCount; i++) {
        levels[i] = (byte) bidi.getRunLevel(i);
        runs[i] = i;
    }

    // reorder individual parts based on their levels
    Bidi.reorderVisually(levels, 0, runs, 0, runCount);

    // collect the parts based on the direction within the run
    StringBuilder result = new StringBuilder();

    for (int i = 0; i < runCount; i++) {
        int index = runs[i];
        int start = bidi.getRunStart(index);
        int end = bidi.getRunLimit(index);

        int level = levels[index];

        if ((level & 1) != 0) {
            while (--end >= start) {
                char character = word.charAt(end);
                if (Character.isMirrored(word.codePointAt(end))) {
                    if (MIRRORING_CHAR_MAP.containsKey(character)) {
                        result.append(MIRRORING_CHAR_MAP.get(character));
                    } else {
                        result.append(character);
                    }
                } else {
                    result.append(character);
                }
            }
        } else {
            result.append(word, start, end);
        }
    }

    return result.toString();
}