1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // Description: 29 // Parse a string of features specified as ; separated pairs. 30 // e.g. 31 // 1001=1&2002=2&fav1=0 32 #include <preextstl.h> 33 #include <graphite/GrClient.h> 34 #include <graphite/Font.h> 35 #include <graphite/GrFeature.h> 36 #include <postextstl.h> 37 38 namespace grutils 39 { 40 41 class GrFeatureParser 42 { 43 public: 44 enum { MAX_FEATURES = 64 }; 45 static const char FEAT_PREFIX; 46 static const char FEAT_SEPARATOR; 47 static const char FEAT_ID_VALUE_SEPARATOR; 48 static const std::string ISO_LANG; 49 GrFeatureParser(gr::Font & font, const std::string features, const std::string lang); 50 GrFeatureParser(gr::Font & font, const std::string lang); 51 GrFeatureParser(const GrFeatureParser & copy); 52 ~GrFeatureParser(); 53 size_t getFontFeatures(gr::FeatureSetting settings[MAX_FEATURES]) const; 54 bool parseErrors() { return mbErrors; }; 55 static bool isValid(gr::Font & font, gr::FeatureSetting & setting); 56 gr::isocode getLanguage() const { return maLang; }; 57 bool hasLanguage() const { return (maLang.rgch[0] != '\0'); } 58 sal_Int32 hashCode() const; 59 private: 60 void setLang(gr::Font & font, const std::string & lang); 61 bool isCharId(const std::string & id, size_t offset, size_t length); 62 int getCharId(const std::string & id, size_t offset, size_t length); 63 int getIntValue(const std::string & id, size_t offset, size_t length); 64 size_t mnNumSettings; 65 gr::isocode maLang; 66 bool mbErrors; 67 gr::FeatureSetting maSettings[64]; 68 }; 69 70 union FeatId 71 { 72 gr::featid num; 73 unsigned char label[5]; 74 }; 75 } 76