diff options
author | Ivo Hinkelmann <ihi@openoffice.org> | 2009-08-17 14:12:14 +0000 |
---|---|---|
committer | Ivo Hinkelmann <ihi@openoffice.org> | 2009-08-17 14:12:14 +0000 |
commit | 5624be5a3520a16d57724064e16df3722d728010 (patch) | |
tree | db4266f6177346c927b43cf773fe5c4ac07bd2d9 /vcl/source/glyphs/graphite_features.cxx | |
parent | 92402b224fda5cb71e3f30430eb657bdbabfa6a1 (diff) |
CWS-TOOLING: integrate CWS graphite01
2009-08-06 11:09:01 +0200 hdu r274708 : #i10000# fix build breaker for SYSTEM_GRAPHITE=NO
2009-07-21 12:01:52 +0200 hdu r274174 : #i93645# fix include files for EXT_USE_STLPORT
2009-07-21 11:51:07 +0200 hdu r274173 : #i93645# convert line-endings of files to be patched
2009-07-21 10:49:01 +0200 hdu r274170 : #i93645# adjust makefile.vc8 for HH-RelEng env (thanks ause)
2009-07-20 05:21:32 +0200 kstribley r274105 : attempt to fix Windows build error caused by NULL variable in nmake file
2009-07-16 10:22:36 +0200 hdu r274032 : #i69129# also use solar minor version to find graphite lib
2009-07-16 05:36:06 +0200 kstribley r274029 : allow windows build to have Graphite disabled with SAL_DISABLE_GRAPHITE
2009-07-15 13:59:22 +0200 hdu r274011 : #i69129# default to ENABLE_GRAPHITE=TRUE
2009-07-15 13:19:54 +0200 hdu r274008 : #i93645# ignore compile warnings for graphite
2009-07-15 13:18:25 +0200 hdu r274006 : #i93645# stlport needs libmath, use solar minor version to find matching libs
2009-07-15 09:21:13 +0200 hdu r273989 : #i100000# avoid compile warning
2009-07-14 12:19:08 +0200 hdu r273963 : CWS-TOOLING: rebase CWS graphite01 to trunk@273858 (milestone: DEV300:m52)
2009-07-13 06:54:56 +0200 kstribley r273912 : change to use standard file headers
2009-07-13 05:39:14 +0200 kstribley r273911 : Remove unnecessary change to configure.in as reported by Rene
2009-07-10 16:58:44 +0200 hdu r273902 : #i100000# fix compile for precompiled-header support
2009-07-02 13:48:26 +0200 kstribley r273647 : #69129# fix a graphite bug which could crash with fonts containing obscure GDL positioning rules
2009-07-02 01:44:02 +0200 rene r273616 : #i10000# we need to link with -licuuc
2009-07-01 04:02:20 +0200 kstribley r273540 : restore missing sdf files from base
2009-07-01 04:01:40 +0200 kstribley r273539 : restore missing sdf files from base
2009-07-01 04:01:12 +0200 kstribley r273538 : restore missing sdf files from base
2009-07-01 03:59:41 +0200 kstribley r273537 : restore missing sdf files from base
2009-06-29 10:16:51 +0200 kstribley r273456 : #i69129# fixes a bug which caused occasional incorrect linebreaking when graphite is asked to render a part of a cluster not containing a base
2009-06-27 10:43:58 +0200 kstribley r273445 : #i69129# added kashida support for justified RTL text
2009-06-01 12:57:06 +0200 kstribley r272476 : CWS-TOOLING: rebase CWS graphite01 to trunk@272291 (milestone: DEV300:m49)
2009-05-26 10:50:06 +0200 kstribley r272286 : #i69129# fixes a build error when NDEBUG is not defined
2009-05-25 13:14:06 +0200 kstribley r272237 : #i69129# enable debugging by fixing compile warnings
2009-05-25 13:07:47 +0200 kstribley r272234 : #i69129# added env variable to disable GRAPHITE at run time on linux and fixed a bug with a rare attachment sequence
2009-04-20 17:39:25 +0200 kstribley r271001 : CWS-TOOLING: rebase CWS graphite01 to trunk@270723 (milestone: DEV300:m46)
2009-04-18 07:11:33 +0200 kstribley r270957 : #i101178# attempt to fix buildbot builds by reordering configure.in
2009-04-14 17:37:07 +0200 kstribley r270801 : #i93645# tweak configure to enable graphite by default on windows and linux to assist testing with tinderbox build
2009-04-14 16:33:17 +0200 kstribley r270796 : #i96925# another fix for rtl fallback and add optional debug info in MultiSalLayout
2009-04-08 13:27:55 +0200 kstribley r270641 : #i69129# fix features after a bad merge
2009-04-08 13:26:34 +0200 kstribley r270640 : #i69129# add a patch for WinFont
2009-03-24 12:37:54 +0100 kstribley r269937 : #i69129# fix build error due to locale being included in method for features
2009-03-24 12:36:10 +0100 kstribley r269936 : #i93645# change patch variable and fix configure
2009-03-20 04:18:56 +0100 kstribley r269776 : CWS-TOOLING: rebase CWS graphite01 to trunk@269297 (milestone: DEV300:m43)
2009-03-01 13:10:59 +0100 kstribley r268622 : added a patch to improve handling of a font with bad graphite language feature tables #i93645#
2009-02-12 04:50:51 +0100 kstribley r267631 : #i93645# fix windows build for graphite 2.3.1 and remove unnecessary patch
2009-02-10 04:48:50 +0100 kstribley r267535 : #i93645# fix a build error with stlport on Ubuntu 8.10 x86
2009-02-10 03:51:10 +0100 kstribley r267534 : #i69129# remove legacy config_office
2009-02-07 19:12:54 +0100 kstribley r267482 : #i93645# upgrade to using silgraphite-2.3.1
2009-02-02 18:17:57 +0100 kstribley r267290 : #i69129# backout unwanted checkin
2009-02-02 17:44:03 +0100 kstribley r267281 : #i69129# backout erroneous update to aclocal.m4
2009-02-01 10:05:03 +0100 kstribley r267236 : #i69129# fix build error due to locale being added to set font attributes
2009-02-01 06:02:52 +0100 kstribley r267235 : #i69129# fix erroneous merge
2009-01-31 16:24:56 +0100 kstribley r267234 : #i69129# update configure.in solenv.in in their new locations with enable graphite
2009-01-31 10:53:18 +0100 kstribley r267232 : CWS-TOOLING: rebase CWS graphite01 to trunk@267171 (milestone: DEV300:m41)
2008-12-17 04:17:33 +0100 kstribley r265577 : #i93645# remove superfluous autoreconf check and autoconf patch
2008-12-16 10:07:20 +0100 rene r265529 : fix aclocal.m4 breakage
2008-12-16 05:13:29 +0100 kstribley r265520 : #i93645# change to autoconf && configure
2008-12-16 04:39:48 +0100 kstribley r265519 : #i93645# modified LD_FLAGS so that system graphite isn't pulled in by accident and fixed autoconf problem
2008-12-15 14:16:25 +0100 rene r265497 : check for working STL
2008-12-15 12:53:39 +0100 rene r265473 : revert broken check
2008-12-15 11:59:21 +0100 kstribley r265472 : #i93645# added check for system STL, since this is a requirement for system graphite to work correctly and moved the position of the check further down
2008-12-15 11:55:34 +0100 kstribley r265471 : #i93645# remove references to gr3ooo to allow system graphite to be used
2008-12-12 18:48:18 +0100 rene r265437 : fix link for system-graphite
2008-12-12 18:46:45 +0100 rene r265436 : the tarball is in graphite, remove obsolete check
2008-12-12 18:22:22 +0100 rene r265433 : typo; re-autoconf
2008-12-12 17:35:26 +0100 rene r265432 : actually implement SYSTEM_GRAPHIT checks (as already checked for in makefile.mks) but remove the checks in graphit itself and move to BUILD_TYPE
2008-12-12 08:08:33 +0100 kstribley r265387 : #i69129# 2 of the patched files need windows line endings so patch works on linux as well as windows
2008-12-12 08:04:41 +0100 kstribley r265386 : #i69129# rtl fallback fix which prevents caching of segments with fallback
2008-12-08 04:28:12 +0100 kstribley r264969 : results of running autoconf with graphite config changes #i69129#
2008-12-05 08:12:47 +0100 kstribley r264886 : backout unintential change at r264884
2008-12-05 06:26:33 +0100 kstribley r264884 : #i96925# fixes for uniscribe fallback
2008-12-05 06:11:37 +0100 kstribley r264883 : #i69129# improvements to windows graphite code, including caching of sila table lookup
2008-12-02 13:28:51 +0100 kstribley r264694 : #i93645# add graphite library and append to patch
2008-11-27 06:47:10 +0100 kstribley r264445 : #69129# fix rtl loop bug and rtl caching problem
2008-11-27 06:42:20 +0100 kstribley r264444 : add caching for GraphiteFontAdaptor
2008-11-14 15:57:03 +0100 kstribley r263681 : #69129# add graphite addtional files from cvs
2008-11-14 15:54:47 +0100 kstribley r263680 : #69129# fix for modified resolution api
2008-11-13 16:24:09 +0100 kstribley r263652 : #69129# add skeleton to build graphite module library
2008-11-13 16:22:19 +0100 kstribley r263651 : #69129# add skeleton to build graphite module library
2008-11-13 16:16:10 +0100 kstribley r263650 : #69129# migrate from cvs
2008-11-13 15:26:54 +0100 kstribley r263646 : #69129# add a module for the graphite library
Diffstat (limited to 'vcl/source/glyphs/graphite_features.cxx')
-rw-r--r-- | vcl/source/glyphs/graphite_features.cxx | 289 |
1 files changed, 289 insertions, 0 deletions
diff --git a/vcl/source/glyphs/graphite_features.cxx b/vcl/source/glyphs/graphite_features.cxx new file mode 100644 index 000000000000..3c5214d3c420 --- /dev/null +++ b/vcl/source/glyphs/graphite_features.cxx @@ -0,0 +1,289 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: $ + * $Revision: $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// Description: +// Parse a string of features specified as & separated pairs. +// e.g. +// 1001=1&2002=2&fav1=0 + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_vcl.hxx" + +#include <sal/types.h> + +#ifdef MSC +#include <tools/svwin.h> +#include <svsys.h> +#endif + +#include <vcl/graphite_features.hxx> + +using namespace grutils; +// These mustn't conflict with font name lists which use ; and , +const char GrFeatureParser::FEAT_PREFIX = ':'; +const char GrFeatureParser::FEAT_SEPARATOR = '&'; +const char GrFeatureParser::FEAT_ID_VALUE_SEPARATOR = '='; +const std::string GrFeatureParser::ISO_LANG("lang"); + +GrFeatureParser::GrFeatureParser(gr::Font & font, const std::string lang) + : mnNumSettings(0), mbErrors(false) +{ + maLang.rgch[0] = maLang.rgch[1] = maLang.rgch[2] = maLang.rgch[3] = '\0'; + setLang(font, lang); +} + +GrFeatureParser::GrFeatureParser(gr::Font & font, const std::string features, const std::string lang) + : mnNumSettings(0), mbErrors(false) +{ + size_t nEquals = 0; + size_t nFeatEnd = 0; + size_t pos = 0; + maLang.rgch[0] = maLang.rgch[1] = maLang.rgch[2] = maLang.rgch[3] = '\0'; + setLang(font, lang); + while (pos < features.length() && mnNumSettings < MAX_FEATURES) + { + nEquals = features.find(FEAT_ID_VALUE_SEPARATOR,pos); + if (nEquals == std::string::npos) + { + mbErrors = true; + break; + } + // check for a lang=xxx specification + if (features.compare(pos, nEquals - pos, ISO_LANG) == 0) + { + pos = nEquals + 1; + nFeatEnd = features.find(FEAT_SEPARATOR, pos); + if (nFeatEnd == std::string::npos) + { + nFeatEnd = features.length(); + } + if (nFeatEnd - pos > 3) + mbErrors = true; + else + { + gr::isocode aLang = maLang; + for (size_t i = pos; i < nFeatEnd; i++) + aLang.rgch[i-pos] = features[i]; + std::pair<gr::LanguageIterator,gr::LanguageIterator> aSupported + = font.getSupportedLanguages(); + gr::LanguageIterator iL = aSupported.first; + while (iL != aSupported.second) + { + gr::isocode aSupportedLang = *iL; + // here we only expect full 3 letter codes + if (aLang.rgch[0] == aSupportedLang.rgch[0] && + aLang.rgch[1] == aSupportedLang.rgch[1] && + aLang.rgch[2] == aSupportedLang.rgch[2] && + aLang.rgch[3] == aSupportedLang.rgch[3]) break; + ++iL; + } + if (iL == aSupported.second) mbErrors = true; + else maLang = aLang; + } + } + else + { + if (isCharId(features, pos, nEquals - pos)) + maSettings[mnNumSettings].id = getCharId(features, pos, nEquals - pos); + else maSettings[mnNumSettings].id = getIntValue(features, pos, nEquals - pos); + pos = nEquals + 1; + nFeatEnd = features.find(FEAT_SEPARATOR, pos); + if (nFeatEnd == std::string::npos) + { + nFeatEnd = features.length(); + } + if (isCharId(features, pos, nFeatEnd - pos)) + maSettings[mnNumSettings].value = getCharId(features, pos, nFeatEnd - pos); + else + maSettings[mnNumSettings].value= getIntValue(features, pos, nFeatEnd - pos); + if (isValid(font, maSettings[mnNumSettings])) + mnNumSettings++; + else + mbErrors = true; + } + pos = nFeatEnd + 1; + } +} + +void GrFeatureParser::setLang(gr::Font & font, const std::string & lang) +{ + gr::isocode aLang = {{0,0,0,0}}; + if (lang.length() > 2) + { + for (size_t i = 0; i < lang.length() && i < 3; i++) + { + if (lang[i] == '-') break; + aLang.rgch[i] = lang[i]; + } + std::pair<gr::LanguageIterator,gr::LanguageIterator> aSupported + = font.getSupportedLanguages(); + gr::LanguageIterator iL = aSupported.first; + while (iL != aSupported.second) + { + gr::isocode aSupportedLang = *iL; + if (aLang.rgch[0] == aSupportedLang.rgch[0] && + aLang.rgch[1] == aSupportedLang.rgch[1] && + aLang.rgch[2] == aSupportedLang.rgch[2] && + aLang.rgch[3] == aSupportedLang.rgch[3]) break; + ++iL; + } + if (iL != aSupported.second) + maLang = aLang; +#ifdef DEBUG + else + printf("%s has no features\n", aLang.rgch); +#endif + } +} + +GrFeatureParser::GrFeatureParser(const GrFeatureParser & aCopy) + : maLang(aCopy.maLang), mbErrors(aCopy.mbErrors) +{ + mnNumSettings = aCopy.getFontFeatures(maSettings); +} + +GrFeatureParser::~GrFeatureParser() +{ +} + +size_t GrFeatureParser::getFontFeatures(gr::FeatureSetting settings[64]) const +{ + if (settings) + { + std::copy(maSettings, maSettings + mnNumSettings, settings); + } + return mnNumSettings; +} + +bool GrFeatureParser::isValid(gr::Font & font, gr::FeatureSetting & setting) +{ + gr::FeatureIterator i = font.featureWithID(setting.id); + if (font.getFeatures().second == i) + { + return false; + } + std::pair< gr::FeatureSettingIterator, gr::FeatureSettingIterator > + validValues = font.getFeatureSettings(i); + gr::FeatureSettingIterator j = validValues.first; + while (j != validValues.second) + { + if (*j == setting.value) return true; + ++j; + } + return false; +} + +bool GrFeatureParser::isCharId(const std::string & id, size_t offset, size_t length) +{ + if (length > 4) return false; + for (size_t i = 0; i < length; i++) + { + if (i > 0 && id[offset+i] == '\0') continue; + if ((id[offset+i]) < 0x20 || (id[offset+i]) < 0) + return false; + if (i==0 && id[offset+i] < 0x41) + return false; + } + return true; +} + +int GrFeatureParser::getCharId(const std::string & id, size_t offset, size_t length) +{ + FeatId charId; + charId.num = 0; +#ifdef WORDS_BIGENDIAN + for (size_t i = 0; i < length; i++) + { + charId.label[i] = id[offset+i]; + } +#else + for (size_t i = 0; i < length; i++) + { + charId.label[3-i] = id[offset+i]; + } +#endif + return charId.num; +} + +int GrFeatureParser::getIntValue(const std::string & id, size_t offset, size_t length) +{ + int value = 0; + int sign = 1; + for (size_t i = 0; i < length; i++) + { + switch (id[offset + i]) + { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + value *= 10; + if (sign < 0) + { + value = -(id[offset + i] - '0'); + sign = 1; + } + value += (id[offset + i] - '0'); + break; + case '-': + if (i == 0) + sign = -1; + else + { + mbErrors = true; + break; + } + default: + mbErrors = true; + break; + } + } + return value; +} + + +sal_Int32 GrFeatureParser::hashCode() const +{ + union IsoHash { sal_Int32 mInt; gr::isocode mCode; }; + IsoHash isoHash; + isoHash.mCode = maLang; + sal_Int32 hash = isoHash.mInt; + for (size_t i = 0; i < mnNumSettings; i++) + { + hash = (hash << 16) ^ ((maSettings[i].id << 8) | maSettings[i].value); + } + return hash; +} |