904N/A/*
904N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
904N/A *
904N/A * This code is free software; you can redistribute it and/or modify it
904N/A * under the terms of the GNU General Public License version 2 only, as
904N/A * published by the Free Software Foundation. Oracle designates this
904N/A * particular file as subject to the "Classpath" exception as provided
904N/A * by Oracle in the LICENSE file that accompanied this code.
904N/A *
904N/A * This code is distributed in the hope that it will be useful, but WITHOUT
904N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
904N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
904N/A * version 2 for more details (a copy is included in the LICENSE file that
904N/A * accompanied this code).
904N/A *
904N/A * You should have received a copy of the GNU General Public License version
904N/A * 2 along with this work; if not, write to the Free Software Foundation,
904N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
904N/A *
904N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
904N/A * or visit www.oracle.com if you need additional information or have any
904N/A * questions.
904N/A *
904N/A */
904N/A
904N/A
904N/A/*
904N/A *
904N/A * (C) Copyright IBM Corp. 1998-2010 - All Rights Reserved
904N/A *
904N/A */
904N/A
904N/A#include "LETypes.h"
904N/A#include "LayoutEngine.h"
904N/A#include "ThaiLayoutEngine.h"
904N/A#include "ScriptAndLanguageTags.h"
904N/A#include "LEGlyphStorage.h"
904N/A
904N/A#include "KernTable.h"
904N/A
904N/A#include "ThaiShaping.h"
904N/A
904N/AU_NAMESPACE_BEGIN
904N/A
904N/AUOBJECT_DEFINE_RTTI_IMPLEMENTATION(ThaiLayoutEngine)
904N/A
904N/AThaiLayoutEngine::ThaiLayoutEngine(const LEFontInstance *fontInstance, le_int32 scriptCode, le_int32 languageCode, le_int32 typoFlags, LEErrorCode &success)
904N/A : LayoutEngine(fontInstance, scriptCode, languageCode, typoFlags, success)
904N/A{
904N/A fErrorChar = 0x25CC;
904N/A
904N/A // Figure out which presentation forms the font uses
904N/A if (! fontInstance->canDisplay(0x0E01)) {
904N/A // No Thai in font; don't use presentation forms.
904N/A fGlyphSet = 3;
904N/A } else if (fontInstance->canDisplay(0x0E64)) {
904N/A // WorldType uses reserved space in Thai block
904N/A fGlyphSet = 0;
904N/A } else if (fontInstance->canDisplay(0xF701)) {
904N/A // Microsoft corporate zone
904N/A fGlyphSet = 1;
904N/A
904N/A if (!fontInstance->canDisplay(fErrorChar)) {
904N/A fErrorChar = 0xF71B;
904N/A }
904N/A } else if (fontInstance->canDisplay(0xF885)) {
904N/A // Apple corporate zone
904N/A fGlyphSet = 2;
904N/A } else {
904N/A // no presentation forms in the font
904N/A fGlyphSet = 3;
904N/A }
904N/A}
904N/A
904N/AThaiLayoutEngine::~ThaiLayoutEngine()
904N/A{
904N/A // nothing to do
904N/A}
904N/A
904N/A// Input: characters (0..max provided for context)
904N/A// Output: glyphs, char indices
904N/A// Returns: the glyph count
904N/A// NOTE: this assumes that ThaiShaping::compose will allocate the outChars array...
904N/Ale_int32 ThaiLayoutEngine::computeGlyphs(const LEUnicode chars[], le_int32 offset, le_int32 count, le_int32 max, le_bool /*rightToLeft*/, LEGlyphStorage &glyphStorage, LEErrorCode &success)
904N/A{
904N/A if (LE_FAILURE(success)) {
904N/A return 0;
904N/A }
904N/A
904N/A if (chars == NULL || offset < 0 || count < 0 || max < 0 || offset >= max || offset + count > max) {
904N/A success = LE_ILLEGAL_ARGUMENT_ERROR;
904N/A return 0;
904N/A }
904N/A
904N/A LEUnicode *outChars;
904N/A le_int32 glyphCount;
904N/A
904N/A // This is enough room for the worst-case expansion
904N/A // (it says here...)
904N/A outChars = LE_NEW_ARRAY(LEUnicode, count * 2);
904N/A
904N/A if (outChars == NULL) {
904N/A success = LE_MEMORY_ALLOCATION_ERROR;
904N/A return 0;
904N/A }
904N/A
904N/A glyphStorage.allocateGlyphArray(count * 2, FALSE, success);
904N/A
904N/A if (LE_FAILURE(success)) {
904N/A LE_DELETE_ARRAY(outChars);
904N/A success = LE_MEMORY_ALLOCATION_ERROR;
904N/A return 0;
904N/A }
904N/A
904N/A glyphCount = ThaiShaping::compose(chars, offset, count, fGlyphSet, fErrorChar, outChars, glyphStorage);
904N/A mapCharsToGlyphs(outChars, 0, glyphCount, FALSE, FALSE, glyphStorage, success);
904N/A
904N/A LE_DELETE_ARRAY(outChars);
904N/A
904N/A glyphStorage.adoptGlyphCount(glyphCount);
904N/A return glyphCount;
904N/A}
904N/A
904N/A// This is the same as LayoutEngline::adjustGlyphPositions() except that it doesn't call adjustMarkGlyphs
904N/Avoid ThaiLayoutEngine::adjustGlyphPositions(const LEUnicode chars[], le_int32 offset, le_int32 count, le_bool /*reverse*/,
904N/A LEGlyphStorage &glyphStorage, LEErrorCode &success)
904N/A{
904N/A if (LE_FAILURE(success)) {
904N/A return;
904N/A }
904N/A
904N/A if (chars == NULL || offset < 0 || count < 0) {
904N/A success = LE_ILLEGAL_ARGUMENT_ERROR;
904N/A return;
904N/A }
904N/A
904N/A if (fTypoFlags & LE_Kerning_FEATURE_FLAG) { /* kerning enabled */
904N/A LETableReference kernTable(fFontInstance, LE_KERN_TABLE_TAG, success);
904N/A KernTable kt(kernTable, success);
904N/A kt.process(glyphStorage, success);
904N/A }
904N/A
904N/A // default is no adjustments
904N/A return;
904N/A}
904N/A
904N/AU_NAMESPACE_END
904N/A