UNPKG

devexpress-richedit

Version:

DevExpress Rich Text Editor is an advanced word-processing tool designed for working with rich text documents.

91 lines (90 loc) 5.01 kB
import { CharacterPropertyDescriptor } from '../../../model/character/character-property-descriptor'; import { RtfFontInfo } from '../import/model/character/rtf-font-info'; import { isDefined } from '@devexpress/utils/lib/utils/common'; export class UnicodeCharHelper { static highestCyrillic = 1279; static lowLatinExtendedAdditional = 7680; static highLatinExtendedAdditional = 7929; static lowGeneralPunctuation = 8192; static highGeneralPunctuation = 8303; static lowCurrencySymbols = 8352; static highCurrencySymbols = 8367; static lowLetterlikeSymbols = 8448; static highLetterlikeSymbols = 8506; static lowNumberForms = 8531; static highNumberForms = 8579; static lowMathematicalOperations = 8704; static highMathematicalOperations = 8945; static lowAnsiCharactersStart = 0x00; static lowAnsiCharactersEnd = 0x7F; static highAnsiCharactersStart = 0x80; static highAnsiCharactersEnd = 0xFF; static privateUseAreaStart = 0xE000; static privateUseAreaEnd = 0xF8FF; static setUnicodeFontName(fontInfoCache, ch, position) { const charType = this.calculateCharType(ch); if (position.useDoubleByteCharactersFontName || position.useLowAnsiCharactersFontName || position.useHighAnsiCharactersFontName) UnicodeCharHelper.setUnicodeFontNameByCharType(fontInfoCache, charType, position); } static setUnicodeFontNameByCharType(fontInfoCache, charType, position) { const characterFormatting = position.coreProperties; if (position.useDoubleByteCharactersFontName || position.useLowAnsiCharactersFontName || position.useHighAnsiCharactersFontName) { if (position.useDoubleByteCharactersFontName && charType == CharType.DoubleByteCharacter) characterFormatting.setValue(CharacterPropertyDescriptor.fontInfo, RtfFontInfo.getFontInfo(fontInfoCache, position.doubleByteCharactersFontName)); else if (position.useLowAnsiCharactersFontName && charType == CharType.LowAnsiCharacter) characterFormatting.setValue(CharacterPropertyDescriptor.fontInfo, RtfFontInfo.getFontInfo(fontInfoCache, position.lowAnsiCharactersFontName)); else if (position.useHighAnsiCharactersFontName && charType == CharType.HighAnsiCharacter) characterFormatting.setValue(CharacterPropertyDescriptor.fontInfo, RtfFontInfo.getFontInfo(fontInfoCache, position.highAnsiCharactersFontName)); } } static isLowAnsiCharacter(ch) { var chVal = ch.charCodeAt(0); return chVal >= UnicodeCharHelper.lowAnsiCharactersStart && chVal <= UnicodeCharHelper.lowAnsiCharactersEnd; } static isDoubleByteChar(ch) { const chVal = ch.charCodeAt(0); if (chVal < UnicodeCharHelper.lowLatinExtendedAdditional) return false; if (chVal >= UnicodeCharHelper.lowLatinExtendedAdditional && chVal <= UnicodeCharHelper.highLatinExtendedAdditional) return false; if (chVal >= UnicodeCharHelper.lowGeneralPunctuation && chVal <= UnicodeCharHelper.highGeneralPunctuation) return false; if (chVal >= UnicodeCharHelper.lowCurrencySymbols && chVal <= UnicodeCharHelper.highCurrencySymbols) return false; if (chVal >= UnicodeCharHelper.lowLetterlikeSymbols && chVal <= UnicodeCharHelper.highLetterlikeSymbols) return false; if (chVal >= UnicodeCharHelper.lowNumberForms && chVal <= UnicodeCharHelper.highNumberForms) return false; if (chVal >= UnicodeCharHelper.lowMathematicalOperations && chVal <= UnicodeCharHelper.highMathematicalOperations) return false; if (chVal >= UnicodeCharHelper.privateUseAreaStart && chVal <= UnicodeCharHelper.privateUseAreaEnd) return false; return true; } static calculateCharType(ch) { if (UnicodeCharHelper.isLowAnsiCharacter(ch)) return CharType.LowAnsiCharacter; if (UnicodeCharHelper.isDoubleByteChar(ch)) return CharType.DoubleByteCharacter; return CharType.HighAnsiCharacter; } static isHighSurrogate(ch) { if (!isDefined(ch) || ch.length > 1) return false; const charCode = ch.charCodeAt(0); return 0xd800 <= charCode && charCode <= 0xdbff; } static isLowSurrogate(ch) { if (!isDefined(ch) || ch.length > 1) return false; const charCode = ch.charCodeAt(0); return 0xdc00 <= charCode && charCode <= 0xdfff; } } export var CharType; (function (CharType) { CharType[CharType["LowAnsiCharacter"] = 0] = "LowAnsiCharacter"; CharType[CharType["DoubleByteCharacter"] = 1] = "DoubleByteCharacter"; CharType[CharType["HighAnsiCharacter"] = 2] = "HighAnsiCharacter"; CharType[CharType["ComplexScriptCharacter"] = 3] = "ComplexScriptCharacter"; })(CharType || (CharType = {}));