merge the formfield patch from ooo-build
[ooovba.git] / vcl / unx / source / gdi / xlfd_attr.hxx
blobad708fd8cbd83a4db4753828d45a14a938f5950d
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xlfd_attr.hxx,v $
10 * $Revision: 1.9 $
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 ************************************************************************/
30 #ifndef XLFD_ATTRIBUTE_HXX
31 #define XLFD_ATTRIBUTE_HXX
33 #include <salunx.h>
34 #include <tools/string.hxx>
37 struct Attribute {
39 const char* mpName;
40 unsigned short mnLength;
41 unsigned short mnValue;
42 unsigned short mnFeature;
43 String* mpAnnotation;
44 rtl::OString* mpKeyName;
46 const char* GetName() const
47 { return mpName; }
48 unsigned short GetValue() const
49 { return mnValue; }
50 unsigned short GetLength() const
51 { return mnLength; }
52 Bool HasFeature( unsigned short nFeature ) const
53 { return ((mnFeature & nFeature) != 0); }
54 const String &GetAnnotation() const
55 { return *mpAnnotation; }
56 const rtl::OString&
57 GetKey();
58 void InitKey();
60 void SetName( const char *p, int nLen );
61 void SetValue( unsigned short nIn )
62 { mnValue = nIn; }
63 void SetAnnotation( String *pString )
64 { mpAnnotation = pString; }
65 void SetFeature( unsigned short nFeature )
66 { mnFeature = nFeature; }
67 void TagFeature( unsigned short nFeature );
69 int Compare( const char *p, int nLen );
70 Bool ExactMatch( const char *p, int nLen );
71 void Release();
75 void
76 AppendAttribute( Attribute *pAttribute, ByteString &rString );
79 typedef String*(*AttributeAnnotatorT)(const Attribute &rAttribute);
80 extern "C" {
81 typedef rtl_TextEncoding(*AttributeClassifierT)(const char* pStr);
84 #define XLFD_FEATURE_NONE 0x0000
85 #define XLFD_FEATURE_NARROW 0x0001
86 #define XLFD_FEATURE_OL_GLYPH 0x0002
87 #define XLFD_FEATURE_OL_CURSOR 0x0004
88 #define XLFD_FEATURE_REDUNDANTSTYLE 0x0008
89 #define XLFD_FEATURE_APPLICATION_FONT 0x0010
91 #define XLFD_FEATURE_INTERFACE_FONT 0x0020
92 #define XLFD_FEATURE_LQ 0x0040
93 #define XLFD_FEATURE_MQ 0x0080
94 #define XLFD_FEATURE_HQ 0x0100
96 // ---------------------------------------------------------------------------
99 // manage global lists of Attributes
100 // since XListFonts does never list more than 64K fonts this storage does
101 // handle array size and indices with unsigned short values for low
102 // memory consumption
105 // ---------------------------------------------------------------------------
107 class AttributeStorage {
109 private:
111 Attribute* mpList;
112 unsigned short mnSize;
113 unsigned short mnCount;
114 unsigned short mnLastmatch;
115 unsigned short mnDefaultValue;
117 void Enlarge();
118 AttributeStorage();
120 public:
122 AttributeStorage( unsigned short nDefaultValue );
123 ~AttributeStorage();
124 unsigned short Insert( const char *pString, int nLength );
125 Attribute* Retrieve( unsigned short nIndex ) const ;
126 void AddClassification( Attribute *pClassification,
127 unsigned short nNum );
128 void AddClassification( AttributeClassifierT Classify );
129 void TagFeature( unsigned short nFeature );
130 void AddAnnotation( AttributeAnnotatorT Annotate );
131 #if OSL_DEBUG_LEVEL > 1
132 void Dump();
133 #endif
137 // ---------------------------------------------------------------------------
140 // Attribute provider is a frame for a set of AttributeStorages. For XLFD
141 // interpretation and efficient storage, AttributeStorages for foundry,
142 // family_name, weight_name, slant, setwidth_name, add_style_name and combined
143 // charset_registry and charset_encoding are used. pixel_size, point_size,
144 // resolution_x and resolution_y are stored as numbers. please note that this
145 // does not allow storage of matrix-enhanced fonts. spacing is stored as
146 // a char, since only the 'm', 'c' and 'p' types are defined.
149 // ---------------------------------------------------------------------------
151 enum eXLFDAttributeT {
152 eXLFDFoundry = 0,
153 eXLFDFamilyName,
154 eXLFDWeightName,
155 eXLFDSlant,
156 eXLFDSetwidthName,
157 eXLFDAddstyleName,
158 eXLFDCharset,
159 eXLFDMaxEntry
162 class AttributeProvider {
164 private:
166 AttributeStorage* mpField[ eXLFDMaxEntry ];
168 AttributeStorage* GetField( eXLFDAttributeT eXLFDField )
169 { return mpField[ eXLFDField]; }
170 public:
172 AttributeProvider ();
173 ~AttributeProvider ();
175 void AddClassification();
176 void AddAnnotation();
177 void TagFeature();
178 #if OSL_DEBUG_LEVEL > 1
179 void Dump();
180 #endif
182 // these are just shortcuts or proxies for the most common used
183 // AttributeStorage functionality
184 AttributeStorage* GetFoundry()
185 { return GetField(eXLFDFoundry); }
186 AttributeStorage* GetFamily()
187 { return GetField(eXLFDFamilyName); }
188 AttributeStorage* GetWeight()
189 { return GetField(eXLFDWeightName); }
190 AttributeStorage* GetSlant()
191 { return GetField(eXLFDSlant); }
192 AttributeStorage* GetSetwidth()
193 { return GetField(eXLFDSetwidthName); }
194 AttributeStorage* GetAddstyle()
195 { return GetField(eXLFDAddstyleName); }
196 AttributeStorage* GetCharset()
197 { return GetField(eXLFDCharset); }
199 Attribute* RetrieveFoundry( unsigned short nIndex )
200 { return GetFoundry()->Retrieve(nIndex); }
201 Attribute* RetrieveFamily( unsigned short nIndex )
202 { return GetFamily()->Retrieve(nIndex); }
203 Attribute* RetrieveWeight( unsigned short nIndex )
204 { return GetWeight()->Retrieve(nIndex); }
205 Attribute* RetrieveSlant( unsigned short nIndex )
206 { return GetSlant()->Retrieve(nIndex); }
207 Attribute* RetrieveSetwidth( unsigned short nIndex )
208 { return GetSetwidth()->Retrieve(nIndex); }
209 Attribute* RetrieveAddstyle( unsigned short nIndex )
210 { return GetAddstyle()->Retrieve(nIndex); }
211 Attribute* RetrieveCharset( unsigned short nIndex )
212 { return GetCharset()->Retrieve(nIndex); }
214 unsigned short InsertFoundry( const char *pString, int nLength )
215 { return GetFoundry()->Insert(pString, nLength); }
216 unsigned short InsertFamily( const char *pString, int nLength )
217 { return GetFamily()->Insert(pString, nLength); }
218 unsigned short InsertWeight( const char *pString, int nLength )
219 { return GetWeight()->Insert(pString, nLength); }
220 unsigned short InsertSlant( const char *pString, int nLength )
221 { return GetSlant()->Insert(pString, nLength); }
222 unsigned short InsertSetwidth( const char *pString, int nLength )
223 { return GetSetwidth()->Insert(pString, nLength);}
224 unsigned short InsertAddstyle( const char *pString, int nLength )
225 { return GetAddstyle()->Insert(pString, nLength);}
226 unsigned short InsertCharset( const char *pString, int nLength )
227 { return GetCharset()->Insert(pString, nLength); }
230 #endif /* XLFD_ATTRIBUTE_HXX */