Chargement du reste de cette comparaison.

PersianShaping

Créé Le diff n'expire jamais
16 suppressions
648 lignes
11 ajouts
644 lignes
// © 2016 and later: Unicode, Inc. and others.
//© 2016 and later: Unicode, Inc. and others.
// License & terms of use: http://www.unicode.org/copyright.html#License
//License & terms of use: http://www.unicode.org/copyright.html#License
/*
/*
*******************************************************************************
*******************************************************************************
* Copyright (C) 2001-2012, International Business Machines
* Copyright (C) 2001-2012, International Business Machines
* Corporation and others. All Rights Reserved.
* Corporation and others. All Rights Reserved.
*******************************************************************************
*******************************************************************************
*/
*/
import com.ibm.icu.impl.UBiDiProps;
import com.ibm.icu.impl.UBiDiProps;
import com.ibm.icu.lang.UCharacterDirection;
import com.ibm.icu.lang.UCharacterDirection;
import com.ibm.icu.text.ArabicShapingException;
/**
/**
* Shape Arabic text on a character basis.
* Shape Persian text on a character basis. - Edited by soheil rahsaz
*
*
* <p>ArabicShaping performs basic operations for "shaping" Arabic text. It is most
* <p>PersianShaping performs basic operations for "shaping" Arabic text. It is most
* useful for use with legacy data formats and legacy display technology
* useful for use with legacy data formats and legacy display technology
* (simple terminals). All operations are performed on Unicode characters.</p>
* (simple terminals). All operations are performed on Unicode characters.</p>
*
*
* <p>Text-based shaping means that some character code points in the text are
* <p>Text-based shaping means that some character code points in the text are
* replaced by others depending on the context. It transforms one kind of text
* replaced by others depending on the context. It transforms one kind of text
* into another. In comparison, modern displays for Arabic text select
* into another. In comparison, modern displays for Arabic text select
* appropriate, context-dependent font glyphs for each text element, which means
* appropriate, context-dependent font glyphs for each text element, which means
* that they transform text into a glyph vector.</p>
* that they transform text into a glyph vector.</p>
*
*
* <p>Text transformations are necessary when modern display technology is not
* <p>Text transformations are necessary when modern display technology is not
* available or when text needs to be transformed to or from legacy formats that
* available or when text needs to be transformed to or from legacy formats that
* use "shaped" characters. Since the Arabic script is cursive, connecting
* use "shaped" characters. Since the Arabic script is cursive, connecting
* adjacent letters to each other, computers select images for each letter based
* adjacent letters to each other, computers select images for each letter based
* on the surrounding letters. This usually results in four images per Arabic
* on the surrounding letters. This usually results in four images per Arabic
* letter: initial, middle, final, and isolated forms. In Unicode, on the other
* letter: initial, middle, final, and isolated forms. In Unicode, on the other
* hand, letters are normally stored abstract, and a display system is expected
* hand, letters are normally stored abstract, and a display system is expected
* to select the necessary glyphs. (This makes searching and other text
* to select the necessary glyphs. (This makes searching and other text
* processing easier because the same letter has only one code.) It is possible
* processing easier because the same letter has only one code.) It is possible
* to mimic this with text transformations because there are characters in
* to mimic this with text transformations because there are characters in
* Unicode that are rendered as letters with a specific shape
* Unicode that are rendered as letters with a specific shape
* (or cursive connectivity). They were included for interoperability with
* (or cursive connectivity). They were included for interoperability with
* legacy systems and codepages, and for unsophisticated display systems.</p>
* legacy systems and codepages, and for unsophisticated display systems.</p>
*
*
* <p>A second kind of text transformations is supported for Arabic digits:
* <p>A second kind of text transformations is supported for Arabic digits:
* For compatibility with legacy codepages that only include European digits,
* For compatibility with legacy codepages that only include European digits,
* it is possible to replace one set of digits by another, changing the
* it is possible to replace one set of digits by another, changing the
* character code points. These operations can be performed for either
* character code points. These operations can be performed for either
* Arabic-Indic Digits (U+0660...U+0669) or Eastern (Extended) Arabic-Indic
* Arabic-Indic Digits (U+0660...U+0669) or Eastern (Extended) Arabic-Indic
* digits (U+06f0...U+06f9).</p>
* digits (U+06f0...U+06f9).</p>
*
*
* <p>Some replacements may result in more or fewer characters (code points).
* <p>Some replacements may result in more or fewer characters (code points).
* By default, this means that the destination buffer may receive text with a
* By default, this means that the destination buffer may receive text with a
* length different from the source length. Some legacy systems rely on the
* length different from the source length. Some legacy systems rely on the
* length of the text to be constant. They expect extra spaces to be added
* length of the text to be constant. They expect extra spaces to be added
* or consumed either next to the affected character or at the end of the
* or consumed either next to the affected character or at the end of the
* text.</p>
* text.</p>
* @stable ICU 2.0
* @stable ICU 2.0
* @author Edited: Soheil Rahsaz
*/
*/
public final class ArabicShaping {
public final class PersianShaping {
private final int options;
private final int options;
private boolean isLogical; // convenience
private boolean isLogical; // convenience
private boolean spacesRelativeToTextBeginEnd;
private boolean spacesRelativeToTextBeginEnd;
private char tailChar;
private char tailChar;
/**
/**
* Convert a range of text in the source array, putting the result
* Convert a range of text in the source array, putting the result
* into a range of text in the destination array, and return the number
* into a range of text in the destination array, and return the number
* of characters written.
* of characters written.
*
*
* @param source An array containing the input text
* @param source An array containing the input text
* @param sourceStart The start of the range of text to convert
* @param sourceStart The start of the range of text to convert
* @param sourceLength The length of the range of text to convert
* @param sourceLength The length of the range of text to convert
* @param dest The destination array that will receive the result.
* @param dest The destination array that will receive the result.
* It may be <code>NULL</code> only if <code>destSize</code> is 0.
* It may be <code>NULL</code> only if <code>destSize</code> is 0.
* @param destStart The start of the range of the destination buffer to use.
* @param destStart The start of the range of the destination buffer to use.
* @param destSize The size (capacity) of the destination buffer.
* @param destSize The size (capacity) of the destination buffer.
* If <code>destSize</code> is 0, then no output is produced,
* If <code>destSize</code> is 0, then no output is produced,
* but the necessary buffer size is returned ("preflighting"). This
* but the necessary buffer size is returned ("preflighting"). This
* does not validate the text against the options, for example,
* does not validate the text against the options, for example,
* if letters are being unshaped, and spaces are being consumed
* if letters are being unshaped, and spaces are being consumed
* following lamalef, this will not detect a lamalef without a
* following lamalef, this will not detect a lamalef without a
* corresponding space. An error will be thrown when the actual
* corresponding space. An error will be thrown when the actual
* conversion is attempted.
* conversion is attempted.
* @return The number of chars written to the destination buffer.
* @return The number of chars written to the destination buffer.
* If an error occurs, then no output was written, or it may be
* If an error occurs, then no output was written, or it may be
* incomplete.
* incomplete.
* @throws ArabicShapingException if the text cannot be converted according to the options.
* @throws ArabicShapingException if the text cannot be converted according to the options.
* @stable ICU 2.0
* @stable ICU 2.0
*/
*/
public int shape(char[] source, int sourceStart, int sourceLength,
public int shape(char[] source, int sourceStart, int sourceLength,
char[] dest, int destStart, int destSize) throws ArabicShapingException {
char[] dest, int destStart, int destSize) throws ArabicShapingException {
if (source == null) {
if (source == null) {
throw new IllegalArgumentException("source can not be null");
throw new IllegalArgumentException("source can not be null");
}
}
if (sourceStart < 0 || sourceLength < 0 || sourceStart + sourceLength > source.length) {
if (sourceStart < 0 || sourceLength < 0 || sourceStart + sourceLength > source.length) {
throw new IllegalArgumentException("bad source start (" + sourceStart +
throw new IllegalArgumentException("bad source start (" + sourceStart +
") or length (" + sourceLength +
") or length (" + sourceLength +
") for buffer of length " + source.length);
") for buffer of length " + source.length);
}
}
if (dest == null && destSize != 0) {
if (dest == null && destSize != 0) {
throw new IllegalArgumentException("null dest requires destSize == 0");
throw new IllegalArgumentException("null dest requires destSize == 0");
}
}
if ((destSize != 0) &&
if ((destSize != 0) &&
(destStart < 0 || destSize < 0 || destStart + destSize > dest.length)) {
(destStart < 0 || destSize < 0 || destStart + destSize > dest.length)) {
throw new IllegalArgumentException("bad dest start (" + destStart +
throw new IllegalArgumentException("bad dest start (" + destStart +
") or size (" + destSize +
") or size (" + destSize +