1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3  * Version: NPL 1.1/GPL 2.0/LGPL 2.1
4  *
5  * The contents of this file are subject to the Netscape Public License
6  * Version 1.1 (the "License"); you may not use this file except in
7  * compliance with the License. You may obtain a copy of the License at
8  * http://www.mozilla.org/NPL/
9  *
10  * Software distributed under the License is distributed on an "AS IS" basis,
11  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12  * for the specific language governing rights and limitations under the
13  * License.
14  *
15  * The Original Code is sila.mozdev.org code.
16  *
17  * The Initial Developer of the Original Code is
18  * Keith Stribley.
19  * Portions created by the Initial Developer are Copyright (C) 2004
20  * the Initial Developer. All Rights Reserved.
21  *
22  * Contributor(s):
23  *
24  *
25  * Alternatively, the contents of this file may be used under the terms of
26  * either the GNU General Public License Version 2 or later (the "GPL"), or
27  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28  * in which case the provisions of the GPL or the LGPL are applicable instead
29  * of those above. If you wish to allow use of your version of this file only
30  * under the terms of either the GPL or the LGPL, and not to allow others to
31  * use your version of this file under the terms of the NPL, indicate your
32  * decision by deleting the provisions above and replace them with the notice
33  * and other provisions required by the GPL or the LGPL. If you do not delete
34  * the provisions above, a recipient may use your version of this file under
35  * the terms of any one of the NPL, the GPL or the LGPL.
36  *
37  * ***** END LICENSE BLOCK ***** */
38 #ifdef _MSC_VER
39 #pragma once
40 #endif
41 #ifndef GRUTFTXTSRC_INCLUDED
42 #define GRUTFTXTSRC_INCLUDED
43 
44 #include <vector>
45 #include <assert.h>
46 
47 #include <graphite/GrAppData.h>
48 #include <graphite/GrStructs.h>
49 #include <graphite/ITextSource.h>
50 
51 class nsIGrSegWrapper;
52 
53 /*-----------------------------------------------------------------------------
54   Class: ITextSource
55   This class provides an interface of a text source for the Graphite engine.
56 ------------------------------------------------------------------------------*/
57 class GrUtfTextSrc : public gr::IColorTextSource
58 {
59 public:
60   GrUtfTextSrc();
61   ~GrUtfTextSrc();
62   bool setText(const gr::utf8 * pszText, int len);
63   bool setText(const char * pszText, int len);
64   bool setText(const gr::utf16 * pszText, int len);
65   bool setText(const gr::utf32 * pszText, int len);
setColors(int foreground,int background)66   void setColors(int foreground, int background)
67   {
68     mForeground = foreground;
69     mBackground = background;
70   };
71   //void setSelectionDetails(nsIGrSegWrapper * wrapper);
setFont(gr::Font * font)72   void setFont(gr::Font * font) { mFont = font; };
setPointSize(float & pointSize)73   void setPointSize(float & pointSize) { mPointSize = pointSize; };
74   // --------------------------------------------------------------------------
75   // New V2 interface:
76 
utfEncodingForm()77   virtual gr::UtfType utfEncodingForm() { return mType; };
getLength()78   virtual size_t getLength() { return mLength; };
79   virtual size_t fetch(gr::toffset ichMin, size_t cch, gr::utf32 * prgchBuffer);
80   virtual size_t fetch(gr::toffset ichMin, size_t cch, gr::utf16 * prgchwBuffer);
81   virtual size_t fetch(gr::toffset ichMin, size_t cch, gr::utf8  * prgchsBuffer);
getFaceName(int,unsigned int,gr::utf16 * prgchFaceName,unsigned int * pcchLen)82   virtual gr::GrResult getFaceName(int /*ich*/, unsigned int /*cchMax*/,
83     gr::utf16 * prgchFaceName, unsigned int * pcchLen)
84   {
85     prgchFaceName[0] = 0;
86     *pcchLen = 0;
87     return gr::kresNotImpl;
88   };
89   //virtual std::wstring getFaceName(int ich) { return mFont->getFaceName(); };
90   virtual float getFontSize(gr::toffset ich);
91   virtual bool getBold(gr::toffset ich);
92   virtual bool getItalic(gr::toffset ich);
93   virtual bool getRightToLeft(gr::toffset ich);
94   virtual unsigned int getDirectionDepth(gr::toffset ich);
getVerticalOffset(gr::toffset)95   virtual float getVerticalOffset(gr::toffset /*ich*/) { return 0;};
96   virtual gr::isocode getLanguage(gr::toffset ich);
97 
98   virtual std::pair<gr::toffset, gr::toffset> propertyRange(gr::toffset ich);
99   virtual size_t getFontFeatures(gr::toffset ich, gr::FeatureSetting * prgfset);
sameSegment(gr::toffset,gr::toffset)100   virtual bool sameSegment(gr::toffset /*ich1*/, gr::toffset /*ich2*/) { return true; };
101 
102 protected:
103   bool checkBuffer8();
104   bool checkBuffer16();
105   bool checkBuffer32();
106 
107 private:
108   size_t mLength;
109   size_t mBufferLength8;
110   size_t mBufferLength16;
111   size_t mBufferLength32;
112   gr::utf8 * mData8;
113   gr::utf16 * mData16;
114   gr::utf32 * mData32;
115   gr::UtfType mType;
116   int mForeground;
117   int mBackground;
118   int mSelectForeground;
119   int mSelectBackground;
120   bool mIsSelected;
121   std::wstring mFaceName;
122   std::vector<bool> mSelectionVector;
123   gr::Font * mFont;
124   bool mRtl;
125   float mPointSize;
126 
127 public: // methods that will go
128   // Temporary--eventually these will be of interest only to SegmentPainter.
129   virtual void getColors(gr::toffset ich, int * pclrFore, int * pclrBack);
130 
131   // Shouldn't be here!
Fetch(int,int,gr::utf16 *)132   virtual gr::GrResult Fetch(int /*ichMin*/, int /*ichLim*/, gr::utf16 * /*prgchBuf*/) { return gr::kresNotImpl; };
get_Length(int *)133   virtual gr::GrResult get_Length(int * /*pcch*/) { return gr::kresNotImpl; };
GetFontVariations(int,wchar_t *,int,int *,int *,int *)134   virtual gr::GrResult GetFontVariations(int /*ich*/,
135     wchar_t * /*prgchFontVar*/, int /*ichMax*/, int * /*pich*/,
136     int * /*pichMin*/, int * /*pichLim*/) { return gr::kresNotImpl; };
137 
138 };
139 
140 
141 #if !defined(GR_NAMESPACE)
142 using namespace gr;
143 #endif
144 
145 #endif // !GRUTFTXTSRC_INCLUDED
146 
147