0N/A/*
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A *
0N/A */
0N/A
0N/A
0N/A/*
0N/A *
3171N/A * (C) Copyright IBM Corp. 1998-2009 - All Rights Reserved
0N/A *
0N/A */
0N/A
0N/A#include "LETypes.h"
0N/A#include "LayoutEngine.h"
0N/A#include "OpenTypeLayoutEngine.h"
0N/A#include "IndicLayoutEngine.h"
0N/A#include "ScriptAndLanguageTags.h"
0N/A
0N/A#include "GlyphSubstitutionTables.h"
0N/A#include "GlyphDefinitionTables.h"
0N/A#include "GlyphPositioningTables.h"
0N/A
0N/A#include "GDEFMarkFilter.h"
0N/A#include "LEGlyphStorage.h"
0N/A
0N/A#include "IndicReordering.h"
3171N/A#include <stdio.h>
1693N/AU_NAMESPACE_BEGIN
1693N/A
1693N/AUOBJECT_DEFINE_RTTI_IMPLEMENTATION(IndicOpenTypeLayoutEngine)
1693N/A
1693N/AIndicOpenTypeLayoutEngine::IndicOpenTypeLayoutEngine(const LEFontInstance *fontInstance, le_int32 scriptCode, le_int32 languageCode,
5980N/A le_int32 typoFlags, le_bool version2, const LEReferenceTo<GlyphSubstitutionTableHeader> &gsubTable, LEErrorCode &success)
3171N/A : OpenTypeLayoutEngine(fontInstance, scriptCode, languageCode, typoFlags, gsubTable, success), fMPreFixups(NULL)
3171N/A{
3171N/A if ( version2 ) {
3171N/A fFeatureMap = IndicReordering::getv2FeatureMap(fFeatureMapCount);
3171N/A } else {
3171N/A fFeatureMap = IndicReordering::getFeatureMap(fFeatureMapCount);
3171N/A }
3171N/A fFeatureOrder = TRUE;
3171N/A fVersion2 = version2;
3171N/A fFilterZeroWidth = IndicReordering::getFilterZeroWidth(fScriptCode);
3171N/A}
3171N/A
3171N/AIndicOpenTypeLayoutEngine::IndicOpenTypeLayoutEngine(const LEFontInstance *fontInstance, le_int32 scriptCode, le_int32 languageCode, le_int32 typoFlags, LEErrorCode &success)
3171N/A : OpenTypeLayoutEngine(fontInstance, scriptCode, languageCode, typoFlags, success), fMPreFixups(NULL)
0N/A{
0N/A fFeatureMap = IndicReordering::getFeatureMap(fFeatureMapCount);
0N/A fFeatureOrder = TRUE;
3171N/A fVersion2 = FALSE;
0N/A}
0N/A
0N/AIndicOpenTypeLayoutEngine::~IndicOpenTypeLayoutEngine()
0N/A{
0N/A // nothing to do
0N/A}
0N/A
0N/A// Input: characters, tags
0N/A// Output: glyphs, char indices
1693N/Ale_int32 IndicOpenTypeLayoutEngine::glyphProcessing(const LEUnicode chars[], le_int32 offset, le_int32 count, le_int32 max, le_bool rightToLeft,
1693N/A LEGlyphStorage &glyphStorage, LEErrorCode &success)
0N/A{
0N/A if (LE_FAILURE(success)) {
0N/A return 0;
0N/A }
0N/A
0N/A if (chars == NULL || offset < 0 || count < 0 || max < 0 || offset >= max || offset + count > max) {
0N/A success = LE_ILLEGAL_ARGUMENT_ERROR;
0N/A return 0;
0N/A }
0N/A
1693N/A le_int32 retCount = OpenTypeLayoutEngine::glyphProcessing(chars, offset, count, max, rightToLeft, glyphStorage, success);
0N/A
0N/A if (LE_FAILURE(success)) {
0N/A return 0;
0N/A }
0N/A
3171N/A if (fVersion2) {
3171N/A IndicReordering::finalReordering(glyphStorage,retCount);
3171N/A IndicReordering::applyPresentationForms(glyphStorage,retCount);
3171N/A OpenTypeLayoutEngine::glyphSubstitution(count,max, rightToLeft, glyphStorage, success);
3171N/A } else {
3171N/A IndicReordering::adjustMPres(fMPreFixups, glyphStorage, success);
3171N/A }
0N/A return retCount;
0N/A}
0N/A
0N/A// Input: characters
0N/A// Output: characters, char indices, tags
0N/A// Returns: output character count
1693N/Ale_int32 IndicOpenTypeLayoutEngine::characterProcessing(const LEUnicode chars[], le_int32 offset, le_int32 count, le_int32 max, le_bool rightToLeft,
1693N/A LEUnicode *&outChars, LEGlyphStorage &glyphStorage, LEErrorCode &success)
0N/A{
0N/A if (LE_FAILURE(success)) {
0N/A return 0;
0N/A }
0N/A
0N/A if (chars == NULL || offset < 0 || count < 0 || max < 0 || offset >= max || offset + count > max) {
0N/A success = LE_ILLEGAL_ARGUMENT_ERROR;
0N/A return 0;
0N/A }
0N/A
0N/A le_int32 worstCase = count * IndicReordering::getWorstCaseExpansion(fScriptCode);
0N/A
0N/A outChars = LE_NEW_ARRAY(LEUnicode, worstCase);
0N/A
0N/A if (outChars == NULL) {
0N/A success = LE_MEMORY_ALLOCATION_ERROR;
0N/A return 0;
0N/A }
0N/A
0N/A glyphStorage.allocateGlyphArray(worstCase, rightToLeft, success);
0N/A glyphStorage.allocateAuxData(success);
0N/A
0N/A if (LE_FAILURE(success)) {
0N/A LE_DELETE_ARRAY(outChars);
0N/A return 0;
0N/A }
0N/A
0N/A // NOTE: assumes this allocates featureTags...
0N/A // (probably better than doing the worst case stuff here...)
3171N/A
3171N/A le_int32 outCharCount;
3171N/A if (fVersion2) {
3171N/A outCharCount = IndicReordering::v2process(&chars[offset], count, fScriptCode, outChars, glyphStorage);
3171N/A } else {
3171N/A outCharCount = IndicReordering::reorder(&chars[offset], count, fScriptCode, outChars, glyphStorage, &fMPreFixups, success);
3171N/A }
3171N/A
3171N/A if (LE_FAILURE(success)) {
3171N/A LE_DELETE_ARRAY(outChars);
3171N/A return 0;
3171N/A }
1693N/A
0N/A glyphStorage.adoptGlyphCount(outCharCount);
0N/A return outCharCount;
0N/A}
1693N/A
1693N/AU_NAMESPACE_END