merge the formfield patch from ooo-build
[ooovba.git] / vcl / source / glyphs / graphite_textsrc.cxx
blobadc2ae99c4f85121324fbf01d1314d7340159984
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: $
10 * $Revision: $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_vcl.hxx"
34 // We need this to enable namespace support in libgrengine headers.
35 #define GR_NAMESPACE
37 // Header files
39 // Standard Library
40 #include <string>
41 #include <cassert>
42 #include "graphite_textsrc.hxx"
43 #include <vcl/graphite_features.hxx>
45 // class TextSourceAdaptor implementation.
47 TextSourceAdaptor::~TextSourceAdaptor()
49 delete mpFeatures;
52 gr::UtfType TextSourceAdaptor::utfEncodingForm() {
53 return gr::kutf16;
57 size_t TextSourceAdaptor::getLength()
59 return maLayoutArgs.mnLength;
63 size_t TextSourceAdaptor::fetch(gr::toffset, size_t, gr::utf32 *)
65 assert(false);
66 return 0;
70 size_t TextSourceAdaptor::fetch(gr::toffset offset, size_t char_count, gr::utf16 * char_buffer)
72 assert(char_buffer);
74 size_t copy_count = std::min(size_t(maLayoutArgs.mnLength), char_count);
75 std::copy(maLayoutArgs.mpStr + offset, maLayoutArgs.mpStr + offset + copy_count, char_buffer);
77 return copy_count;
81 size_t TextSourceAdaptor::fetch(gr::toffset, size_t, gr::utf8 *)
83 assert(false);
84 return 0;
88 inline void TextSourceAdaptor::getCharProperties(const int nCharIdx, int & min, int & lim, size_t & depth)
90 maLayoutArgs.ResetPos();
91 bool rtl = maLayoutArgs.mnFlags & SAL_LAYOUT_BIDI_RTL;
92 for(depth = ((rtl)? 1:0); maLayoutArgs.maRuns.GetRun(&min, &lim, &rtl); maLayoutArgs.maRuns.NextRun())
94 if (min > nCharIdx)
95 break;
96 // Only increase the depth when a change of direction occurs.
97 depth += int(rtl ^ bool(depth & 0x1));
98 if (min <= nCharIdx && nCharIdx < lim)
99 break;
101 // If there is no run for this position increment the depth, but don't
102 // change if this is out of bounds context
103 if (lim > 0 && nCharIdx >= lim && nCharIdx < maLayoutArgs.mnEndCharPos)
104 depth++;
108 bool TextSourceAdaptor::getRightToLeft(gr::toffset nCharIdx)
110 size_t depth;
111 int min, lim = 0;
112 getCharProperties(nCharIdx, min, lim, depth);
113 //printf("getRtl %d,%x=%d\n", nCharIdx, maLayoutArgs.mpStr[nCharIdx], depth & 0x1);
114 return depth & 0x1;
118 unsigned int TextSourceAdaptor::getDirectionDepth(gr::toffset nCharIdx)
120 size_t depth;
121 int min, lim;
122 getCharProperties(nCharIdx, min, lim, depth);
123 //printf("getDirectionDepth %d,%x=%d\n", nCharIdx, maLayoutArgs.mpStr[nCharIdx], depth);
124 return depth;
128 float TextSourceAdaptor::getVerticalOffset(gr::toffset)
130 return 0.0f; //TODO: Implement correctly
133 gr::isocode TextSourceAdaptor::getLanguage(gr::toffset)
135 if (mpFeatures && mpFeatures->hasLanguage())
136 return mpFeatures->getLanguage();
137 gr::isocode unknown = {{0,0,0,0}};
138 return unknown;
141 std::pair<gr::toffset, gr::toffset> TextSourceAdaptor::propertyRange(gr::toffset nCharIdx)
144 if (nCharIdx < unsigned(maLayoutArgs.mnMinCharPos))
145 return std::make_pair(0, maLayoutArgs.mnMinCharPos);
147 if (nCharIdx < mnEnd)
148 return std::make_pair(maLayoutArgs.mnMinCharPos, mnEnd);
150 return std::make_pair(mnEnd, maLayoutArgs.mnLength);
153 size_t TextSourceAdaptor::getFontFeatures(gr::toffset, gr::FeatureSetting * settings)
155 if (mpFeatures) return mpFeatures->getFontFeatures(settings);
156 return 0;
160 bool TextSourceAdaptor::sameSegment(gr::toffset char_idx1, gr::toffset char_idx2)
162 const std::pair<gr::toffset, gr::toffset>
163 range1 = propertyRange(char_idx1),
164 range2 = propertyRange(char_idx2);
166 return range1 == range2;
169 void TextSourceAdaptor::setFeatures(const grutils::GrFeatureParser * pFeatures)
171 mpFeatures = new grutils::GrFeatureParser(*pFeatures);