1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_vcl.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir // We need this to enable namespace support in libgrengine headers. 32*cdf0e10cSrcweir #define GR_NAMESPACE 33*cdf0e10cSrcweir 34*cdf0e10cSrcweir // Header files 35*cdf0e10cSrcweir // 36*cdf0e10cSrcweir // Standard Library 37*cdf0e10cSrcweir #include <string> 38*cdf0e10cSrcweir #include <cassert> 39*cdf0e10cSrcweir #include "graphite_textsrc.hxx" 40*cdf0e10cSrcweir #include <graphite_features.hxx> 41*cdf0e10cSrcweir 42*cdf0e10cSrcweir // class TextSourceAdaptor implementation. 43*cdf0e10cSrcweir // 44*cdf0e10cSrcweir TextSourceAdaptor::~TextSourceAdaptor() 45*cdf0e10cSrcweir { 46*cdf0e10cSrcweir delete mpFeatures; 47*cdf0e10cSrcweir } 48*cdf0e10cSrcweir 49*cdf0e10cSrcweir gr::UtfType TextSourceAdaptor::utfEncodingForm() { 50*cdf0e10cSrcweir return gr::kutf16; 51*cdf0e10cSrcweir } 52*cdf0e10cSrcweir 53*cdf0e10cSrcweir 54*cdf0e10cSrcweir size_t TextSourceAdaptor::getLength() 55*cdf0e10cSrcweir { 56*cdf0e10cSrcweir return maLayoutArgs.mnLength; 57*cdf0e10cSrcweir } 58*cdf0e10cSrcweir 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir size_t TextSourceAdaptor::fetch(gr::toffset, size_t, gr::utf32 *) 61*cdf0e10cSrcweir { 62*cdf0e10cSrcweir assert(false); 63*cdf0e10cSrcweir return 0; 64*cdf0e10cSrcweir } 65*cdf0e10cSrcweir 66*cdf0e10cSrcweir 67*cdf0e10cSrcweir size_t TextSourceAdaptor::fetch(gr::toffset offset, size_t char_count, gr::utf16 * char_buffer) 68*cdf0e10cSrcweir { 69*cdf0e10cSrcweir assert(char_buffer); 70*cdf0e10cSrcweir 71*cdf0e10cSrcweir size_t copy_count = std::min(size_t(maLayoutArgs.mnLength), char_count); 72*cdf0e10cSrcweir std::copy(maLayoutArgs.mpStr + offset, maLayoutArgs.mpStr + offset + copy_count, char_buffer); 73*cdf0e10cSrcweir 74*cdf0e10cSrcweir return copy_count; 75*cdf0e10cSrcweir } 76*cdf0e10cSrcweir 77*cdf0e10cSrcweir 78*cdf0e10cSrcweir size_t TextSourceAdaptor::fetch(gr::toffset, size_t, gr::utf8 *) 79*cdf0e10cSrcweir { 80*cdf0e10cSrcweir assert(false); 81*cdf0e10cSrcweir return 0; 82*cdf0e10cSrcweir } 83*cdf0e10cSrcweir 84*cdf0e10cSrcweir 85*cdf0e10cSrcweir inline void TextSourceAdaptor::getCharProperties(const int nCharIdx, int & min, int & lim, size_t & depth) 86*cdf0e10cSrcweir { 87*cdf0e10cSrcweir maLayoutArgs.ResetPos(); 88*cdf0e10cSrcweir bool rtl = maLayoutArgs.mnFlags & SAL_LAYOUT_BIDI_RTL; 89*cdf0e10cSrcweir for(depth = ((rtl)? 1:0); maLayoutArgs.maRuns.GetRun(&min, &lim, &rtl); maLayoutArgs.maRuns.NextRun()) 90*cdf0e10cSrcweir { 91*cdf0e10cSrcweir if (min > nCharIdx) 92*cdf0e10cSrcweir break; 93*cdf0e10cSrcweir // Only increase the depth when a change of direction occurs. 94*cdf0e10cSrcweir depth += int(rtl ^ bool(depth & 0x1)); 95*cdf0e10cSrcweir if (min <= nCharIdx && nCharIdx < lim) 96*cdf0e10cSrcweir break; 97*cdf0e10cSrcweir } 98*cdf0e10cSrcweir // If there is no run for this position increment the depth, but don't 99*cdf0e10cSrcweir // change if this is out of bounds context 100*cdf0e10cSrcweir if (lim > 0 && nCharIdx >= lim && nCharIdx < maLayoutArgs.mnEndCharPos) 101*cdf0e10cSrcweir depth++; 102*cdf0e10cSrcweir } 103*cdf0e10cSrcweir 104*cdf0e10cSrcweir 105*cdf0e10cSrcweir bool TextSourceAdaptor::getRightToLeft(gr::toffset nCharIdx) 106*cdf0e10cSrcweir { 107*cdf0e10cSrcweir size_t depth; 108*cdf0e10cSrcweir int min, lim = 0; 109*cdf0e10cSrcweir getCharProperties(nCharIdx, min, lim, depth); 110*cdf0e10cSrcweir //printf("getRtl %d,%x=%d\n", nCharIdx, maLayoutArgs.mpStr[nCharIdx], depth & 0x1); 111*cdf0e10cSrcweir return depth & 0x1; 112*cdf0e10cSrcweir } 113*cdf0e10cSrcweir 114*cdf0e10cSrcweir 115*cdf0e10cSrcweir unsigned int TextSourceAdaptor::getDirectionDepth(gr::toffset nCharIdx) 116*cdf0e10cSrcweir { 117*cdf0e10cSrcweir size_t depth; 118*cdf0e10cSrcweir int min, lim; 119*cdf0e10cSrcweir getCharProperties(nCharIdx, min, lim, depth); 120*cdf0e10cSrcweir //printf("getDirectionDepth %d,%x=%d\n", nCharIdx, maLayoutArgs.mpStr[nCharIdx], depth); 121*cdf0e10cSrcweir return depth; 122*cdf0e10cSrcweir } 123*cdf0e10cSrcweir 124*cdf0e10cSrcweir 125*cdf0e10cSrcweir float TextSourceAdaptor::getVerticalOffset(gr::toffset) 126*cdf0e10cSrcweir { 127*cdf0e10cSrcweir return 0.0f; //TODO: Implement correctly 128*cdf0e10cSrcweir } 129*cdf0e10cSrcweir 130*cdf0e10cSrcweir gr::isocode TextSourceAdaptor::getLanguage(gr::toffset) 131*cdf0e10cSrcweir { 132*cdf0e10cSrcweir if (mpFeatures && mpFeatures->hasLanguage()) 133*cdf0e10cSrcweir return mpFeatures->getLanguage(); 134*cdf0e10cSrcweir gr::isocode unknown = {{0,0,0,0}}; 135*cdf0e10cSrcweir return unknown; 136*cdf0e10cSrcweir } 137*cdf0e10cSrcweir 138*cdf0e10cSrcweir ext_std::pair<gr::toffset, gr::toffset> TextSourceAdaptor::propertyRange(gr::toffset nCharIdx) 139*cdf0e10cSrcweir { 140*cdf0e10cSrcweir 141*cdf0e10cSrcweir if (nCharIdx < unsigned(maLayoutArgs.mnMinCharPos)) 142*cdf0e10cSrcweir return ext_std::make_pair(0, maLayoutArgs.mnMinCharPos); 143*cdf0e10cSrcweir 144*cdf0e10cSrcweir if (nCharIdx < mnEnd) 145*cdf0e10cSrcweir return ext_std::make_pair(maLayoutArgs.mnMinCharPos, mnEnd); 146*cdf0e10cSrcweir 147*cdf0e10cSrcweir return ext_std::make_pair(mnEnd, maLayoutArgs.mnLength); 148*cdf0e10cSrcweir } 149*cdf0e10cSrcweir 150*cdf0e10cSrcweir size_t TextSourceAdaptor::getFontFeatures(gr::toffset, gr::FeatureSetting * settings) 151*cdf0e10cSrcweir { 152*cdf0e10cSrcweir if (mpFeatures) return mpFeatures->getFontFeatures(settings); 153*cdf0e10cSrcweir return 0; 154*cdf0e10cSrcweir } 155*cdf0e10cSrcweir 156*cdf0e10cSrcweir 157*cdf0e10cSrcweir bool TextSourceAdaptor::sameSegment(gr::toffset char_idx1, gr::toffset char_idx2) 158*cdf0e10cSrcweir { 159*cdf0e10cSrcweir const ext_std::pair<gr::toffset, gr::toffset> 160*cdf0e10cSrcweir range1 = propertyRange(char_idx1), 161*cdf0e10cSrcweir range2 = propertyRange(char_idx2); 162*cdf0e10cSrcweir 163*cdf0e10cSrcweir return range1 == range2; 164*cdf0e10cSrcweir } 165*cdf0e10cSrcweir 166*cdf0e10cSrcweir void TextSourceAdaptor::setFeatures(const grutils::GrFeatureParser * pFeatures) 167*cdf0e10cSrcweir { 168*cdf0e10cSrcweir mpFeatures = new grutils::GrFeatureParser(*pFeatures); 169*cdf0e10cSrcweir } 170