xref: /trunk/main/vcl/inc/graphite_features.hxx (revision 161f4cd1)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // Description:
25 // Parse a string of features specified as ; separated pairs.
26 // e.g.
27 // 1001=1&2002=2&fav1=0
28 #include <preextstl.h>
29 #include <graphite/GrClient.h>
30 #include <graphite/Font.h>
31 #include <graphite/GrFeature.h>
32 #include <postextstl.h>
33 
34 namespace grutils
35 {
36 
37     class GrFeatureParser
38     {
39     public:
40         enum { MAX_FEATURES = 64 };
41         static const char FEAT_PREFIX;
42         static const char FEAT_SEPARATOR;
43         static const char FEAT_ID_VALUE_SEPARATOR;
44         static const std::string ISO_LANG;
45         GrFeatureParser(gr::Font & font, const std::string features, const std::string lang);
46         GrFeatureParser(gr::Font & font, const std::string lang);
47         GrFeatureParser(const GrFeatureParser & copy);
48         ~GrFeatureParser();
49         size_t getFontFeatures(gr::FeatureSetting settings[MAX_FEATURES]) const;
parseErrors()50         bool parseErrors() { return mbErrors; };
51         static bool isValid(gr::Font & font, gr::FeatureSetting & setting);
getLanguage() const52         gr::isocode getLanguage() const { return maLang; };
hasLanguage() const53         bool hasLanguage() const { return (maLang.rgch[0] != '\0'); }
54         sal_Int32 hashCode() const;
55     private:
56         void setLang(gr::Font & font, const std::string & lang);
57         bool isCharId(const std::string & id, size_t offset, size_t length);
58         int getCharId(const std::string & id, size_t offset, size_t length);
59         int getIntValue(const std::string & id, size_t offset, size_t length);
60         size_t mnNumSettings;
61         gr::isocode maLang;
62         bool mbErrors;
63         gr::FeatureSetting maSettings[64];
64     };
65 
66     union FeatId
67     {
68         gr::featid num;
69         unsigned char label[5];
70     };
71 }
72