J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 3 | * |
| 4 | * This code is free software; you can redistribute it and/or modify it |
| 5 | * under the terms of the GNU General Public License version 2 only, as |
| 6 | * published by the Free Software Foundation. Sun designates this |
| 7 | * particular file as subject to the "Classpath" exception as provided |
| 8 | * by Sun in the LICENSE file that accompanied this code. |
| 9 | * |
| 10 | * This code is distributed in the hope that it will be useful, but WITHOUT |
| 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 13 | * version 2 for more details (a copy is included in the LICENSE file that |
| 14 | * accompanied this code). |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License version |
| 17 | * 2 along with this work; if not, write to the Free Software Foundation, |
| 18 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 19 | * |
| 20 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
| 21 | * CA 95054 USA or visit www.sun.com if you need additional information or |
| 22 | * have any questions. |
| 23 | * |
| 24 | */ |
| 25 | |
| 26 | |
| 27 | /* |
| 28 | * |
| 29 | * (C) Copyright IBM Corp. 1998-2005 - All Rights Reserved |
| 30 | * |
| 31 | */ |
| 32 | |
| 33 | #include "LETypes.h" |
| 34 | #include "LayoutEngine.h" |
| 35 | #include "ThaiLayoutEngine.h" |
| 36 | #include "ScriptAndLanguageTags.h" |
| 37 | #include "LEGlyphStorage.h" |
| 38 | |
| 39 | #include "ThaiShaping.h" |
| 40 | |
| 41 | ThaiLayoutEngine::ThaiLayoutEngine(const LEFontInstance *fontInstance, |
| 42 | le_int32 scriptCode, le_int32 languageCode, le_int32 typoFlags) |
| 43 | : LayoutEngine(fontInstance, scriptCode, languageCode, typoFlags) |
| 44 | { |
| 45 | fErrorChar = 0x25CC; |
| 46 | |
| 47 | // Figure out which presentation forms the font uses |
| 48 | if (fontInstance->canDisplay(0x0E64)) { |
| 49 | // WorldType uses reserved space in Thai block |
| 50 | fGlyphSet = 0; |
| 51 | } else if (fontInstance->canDisplay(0xF701)) { |
| 52 | // Microsoft corporate zone |
| 53 | fGlyphSet = 1; |
| 54 | |
| 55 | if (!fontInstance->canDisplay(fErrorChar)) { |
| 56 | fErrorChar = 0xF71B; |
| 57 | } |
| 58 | } else if (fontInstance->canDisplay(0xF885)) { |
| 59 | // Apple corporate zone |
| 60 | fGlyphSet = 2; |
| 61 | } else { |
| 62 | // no presentation forms in the font |
| 63 | fGlyphSet = 3; |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | ThaiLayoutEngine::~ThaiLayoutEngine() |
| 68 | { |
| 69 | // nothing to do |
| 70 | } |
| 71 | |
| 72 | // Input: characters (0..max provided for context) |
| 73 | // Output: glyphs, char indices |
| 74 | // Returns: the glyph count |
| 75 | // NOTE: this assumes that ThaiShaping::compose will allocate the outChars array... |
| 76 | le_int32 ThaiLayoutEngine::computeGlyphs(const LEUnicode chars[], le_int32 offset, |
| 77 | le_int32 count, le_int32 max, le_bool /*rightToLeft*/, |
| 78 | LEGlyphStorage &glyphStorage, LEErrorCode &success) |
| 79 | { |
| 80 | if (LE_FAILURE(success)) { |
| 81 | return 0; |
| 82 | } |
| 83 | |
| 84 | if (chars == NULL || offset < 0 || count < 0 || max < 0 || |
| 85 | offset >= max || offset + count > max) { |
| 86 | success = LE_ILLEGAL_ARGUMENT_ERROR; |
| 87 | return 0; |
| 88 | } |
| 89 | |
| 90 | LEUnicode *outChars; |
| 91 | le_int32 glyphCount; |
| 92 | |
| 93 | // This is enough room for the worst-case expansion |
| 94 | // (it says here...) |
| 95 | outChars = LE_NEW_ARRAY(LEUnicode, count * 2); |
| 96 | |
| 97 | if (outChars == NULL) { |
| 98 | success = LE_MEMORY_ALLOCATION_ERROR; |
| 99 | return 0; |
| 100 | } |
| 101 | |
| 102 | glyphStorage.allocateGlyphArray(count * 2, FALSE, success); |
| 103 | |
| 104 | if (LE_FAILURE(success)) { |
| 105 | LE_DELETE_ARRAY(outChars); |
| 106 | success = LE_MEMORY_ALLOCATION_ERROR; |
| 107 | return 0; |
| 108 | } |
| 109 | |
| 110 | glyphCount = ThaiShaping::compose(chars, offset, count, fGlyphSet, fErrorChar, |
| 111 | outChars, glyphStorage); |
| 112 | mapCharsToGlyphs(outChars, 0, glyphCount, FALSE, FALSE, glyphStorage, success); |
| 113 | |
| 114 | LE_DELETE_ARRAY(outChars); |
| 115 | |
| 116 | glyphStorage.adoptGlyphCount(glyphCount); |
| 117 | return glyphCount; |
| 118 | } |