summaryrefslogtreecommitdiff
path: root/unotools/inc
diff options
context:
space:
mode:
authorMathias Bauer <mba@openoffice.org>2009-10-19 13:22:39 +0200
committerMathias Bauer <mba@openoffice.org>2009-10-19 13:22:39 +0200
commit942dbe34b9a1400c926a81f88e849d248b58ed55 (patch)
tree0fe108618106e42e0a25074782c160c393b45ffb /unotools/inc
parentc5ddee96afdc3ceb5bcc023b36185122a16b283d (diff)
#i103496#: move some fontsubstitution stuff from vcl to unotools to get xmloff vcl free
Diffstat (limited to 'unotools/inc')
-rw-r--r--unotools/inc/unotools/fontcfg.hxx230
-rw-r--r--unotools/inc/unotools/fontcvt.hxx82
-rw-r--r--unotools/inc/unotools/fontdefs.hxx110
3 files changed, 422 insertions, 0 deletions
diff --git a/unotools/inc/unotools/fontcfg.hxx b/unotools/inc/unotools/fontcfg.hxx
new file mode 100644
index 000000000000..4d0ed4036328
--- /dev/null
+++ b/unotools/inc/unotools/fontcfg.hxx
@@ -0,0 +1,230 @@
+/*************************************************************************
+ *
+ * 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: fontcfg.hxx,v $
+ * $Revision: 1.3 $
+ *
+ * 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.
+ *
+ ************************************************************************/
+#ifndef _UNOTOOLS_FONTCFG_HXX
+#define _UNOTOOLS_FONTCFG_HXX
+
+#include <unotools/unotoolsdllapi.h>
+#include <tools/string.hxx>
+#include <tools/fontenum.hxx>
+#include <com/sun/star/lang/Locale.hpp>
+#include <com/sun/star/lang/XMultiServiceFactory.hpp>
+#include <com/sun/star/container/XNameAccess.hpp>
+
+#include <hash_map>
+#include <hash_set>
+#include <vector>
+
+namespace com {
+namespace sun {
+namespace star {
+namespace lang {
+
+// equality operator needed for hash_map;
+// (-> why does this need to be in the namespace of Locale ? g++ fails to compile else)
+inline bool operator==( const com::sun::star::lang::Locale& rLeft, const com::sun::star::lang::Locale& rRight )
+{
+ return
+ rLeft.Language.equals( rRight.Language ) &&
+ rLeft.Country.equals( rRight.Country ) &&
+ rLeft.Variant.equals( rRight.Variant )
+ ;
+}
+}}}}
+
+namespace utl
+{
+
+struct LocaleHash
+{
+ size_t operator()( const com::sun::star::lang::Locale& rLocale ) const
+ {
+ return
+ (size_t)rLocale.Language.hashCode() ^
+ (size_t)rLocale.Country.hashCode() ^
+ (size_t)rLocale.Variant.hashCode();
+ }
+};
+
+class UNOTOOLS_DLLPUBLIC DefaultFontConfiguration
+{
+ com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >
+ m_xConfigProvider;
+ com::sun::star::uno::Reference< com::sun::star::container::XNameAccess >
+ m_xConfigAccess;
+
+ struct LocaleAccess
+ {
+ // the real string used in the configuration
+ // used to get rid of upper/lower case problems
+ rtl::OUString aConfigLocaleString;
+ // xAccess is mutable to be able to be filled on demand
+ mutable com::sun::star::uno::Reference< com::sun::star::container::XNameAccess > xAccess;
+ };
+
+ std::hash_map< com::sun::star::lang::Locale,
+ LocaleAccess,
+ utl::LocaleHash >
+ m_aConfig;
+
+ rtl::OUString tryLocale( const com::sun::star::lang::Locale& rLocale, const rtl::OUString& rType ) const;
+
+ DefaultFontConfiguration();
+ public:
+ ~DefaultFontConfiguration();
+
+ static DefaultFontConfiguration* get();
+
+ rtl::OUString getDefaultFont( const com::sun::star::lang::Locale& rLocale, int nType ) const;
+ rtl::OUString getUserInterfaceFont( const com::sun::star::lang::Locale& rLocale ) const;
+};
+
+// IMPL_FONT_ATTR_DEFAULT - Default-Font like Andale Sans UI, Palace Script, Albany, Thorndale, Cumberland, ...
+// IMPL_FONT_ATTR_STANDARD - Standard-Font like Arial, Times, Courier, ...
+// IMPL_FONT_ATTR_NORMAL - normal Font for writing text like Arial, Verdana, Arial Narrow, Trebuchet, Times, Courier, ...
+// IMPL_FONT_ATTR_SYMBOL - Font with symbols
+// IMPL_FONT_ATTR_DECORATIVE - Readable and normally used for drawings
+// IMPL_FONT_ATTR_SPECIAL - very special design
+// IMPL_FONT_ATTR_TITLING - only uppercase characters
+// IMPL_FONT_ATTR_FULL - Font with normally all characters
+// IMPL_FONT_ATTR_CAPITALS - only uppercase characters, but lowercase characters smaller as the uppercase characters
+// IMPL_FONT_ATTR_TYPEWRITER - like a typewriter: Courier, ...
+// IMPL_FONT_ATTR_SCRIPT - Handwriting or Script
+// IMPL_FONT_ATTR_HANDWRITING - More Handwriting with normal letters
+// IMPL_FONT_ATTR_CHANCERY - Like Zapf Chancery
+// IMPL_FONT_ATTR_COMIC - Like Comic Sans MS
+// IMPL_FONT_ATTR_BRUSHSCRIPT - More Script
+// IMPL_FONT_ATTR_OTHERSTYLE - OldStyle, ... so negativ points
+#define IMPL_FONT_ATTR_DEFAULT ((ULONG)0x00000001)
+#define IMPL_FONT_ATTR_STANDARD ((ULONG)0x00000002)
+#define IMPL_FONT_ATTR_NORMAL ((ULONG)0x00000004)
+#define IMPL_FONT_ATTR_SYMBOL ((ULONG)0x00000008)
+#define IMPL_FONT_ATTR_FIXED ((ULONG)0x00000010)
+#define IMPL_FONT_ATTR_SANSSERIF ((ULONG)0x00000020)
+#define IMPL_FONT_ATTR_SERIF ((ULONG)0x00000040)
+#define IMPL_FONT_ATTR_DECORATIVE ((ULONG)0x00000080)
+#define IMPL_FONT_ATTR_SPECIAL ((ULONG)0x00000100)
+#define IMPL_FONT_ATTR_ITALIC ((ULONG)0x00000200)
+#define IMPL_FONT_ATTR_TITLING ((ULONG)0x00000400)
+#define IMPL_FONT_ATTR_CAPITALS ((ULONG)0x00000800)
+#define IMPL_FONT_ATTR_CJK ((ULONG)0x00001000)
+#define IMPL_FONT_ATTR_CJK_JP ((ULONG)0x00002000)
+#define IMPL_FONT_ATTR_CJK_SC ((ULONG)0x00004000)
+#define IMPL_FONT_ATTR_CJK_TC ((ULONG)0x00008000)
+#define IMPL_FONT_ATTR_CJK_KR ((ULONG)0x00010000)
+#define IMPL_FONT_ATTR_CTL ((ULONG)0x00020000)
+#define IMPL_FONT_ATTR_NONELATIN ((ULONG)0x00040000)
+#define IMPL_FONT_ATTR_FULL ((ULONG)0x00080000)
+#define IMPL_FONT_ATTR_OUTLINE ((ULONG)0x00100000)
+#define IMPL_FONT_ATTR_SHADOW ((ULONG)0x00200000)
+#define IMPL_FONT_ATTR_ROUNDED ((ULONG)0x00400000)
+#define IMPL_FONT_ATTR_TYPEWRITER ((ULONG)0x00800000)
+#define IMPL_FONT_ATTR_SCRIPT ((ULONG)0x01000000)
+#define IMPL_FONT_ATTR_HANDWRITING ((ULONG)0x02000000)
+#define IMPL_FONT_ATTR_CHANCERY ((ULONG)0x04000000)
+#define IMPL_FONT_ATTR_COMIC ((ULONG)0x08000000)
+#define IMPL_FONT_ATTR_BRUSHSCRIPT ((ULONG)0x10000000)
+#define IMPL_FONT_ATTR_GOTHIC ((ULONG)0x20000000)
+#define IMPL_FONT_ATTR_SCHOOLBOOK ((ULONG)0x40000000)
+#define IMPL_FONT_ATTR_OTHERSTYLE ((ULONG)0x80000000)
+
+#define IMPL_FONT_ATTR_CJK_ALLLANG (IMPL_FONT_ATTR_CJK_JP | IMPL_FONT_ATTR_CJK_SC | IMPL_FONT_ATTR_CJK_TC | IMPL_FONT_ATTR_CJK_KR)
+#define IMPL_FONT_ATTR_ALLSCRIPT (IMPL_FONT_ATTR_SCRIPT | IMPL_FONT_ATTR_HANDWRITING | IMPL_FONT_ATTR_CHANCERY | IMPL_FONT_ATTR_COMIC | IMPL_FONT_ATTR_BRUSHSCRIPT)
+#define IMPL_FONT_ATTR_ALLSUBSCRIPT (IMPL_FONT_ATTR_HANDWRITING | IMPL_FONT_ATTR_CHANCERY | IMPL_FONT_ATTR_COMIC | IMPL_FONT_ATTR_BRUSHSCRIPT)
+#define IMPL_FONT_ATTR_ALLSERIFSTYLE (IMPL_FONT_ATTR_ALLSCRIPT |\
+ IMPL_FONT_ATTR_SANSSERIF | IMPL_FONT_ATTR_SERIF |\
+ IMPL_FONT_ATTR_FIXED | IMPL_FONT_ATTR_ITALIC |\
+ IMPL_FONT_ATTR_GOTHIC | IMPL_FONT_ATTR_SCHOOLBOOK |\
+ IMPL_FONT_ATTR_SHADOW | IMPL_FONT_ATTR_OUTLINE)
+
+struct UNOTOOLS_DLLPUBLIC FontNameAttr
+{
+ String Name;
+ ::std::vector< String > Substitutions;
+ ::std::vector< String > MSSubstitutions;
+ ::std::vector< String > PSSubstitutions;
+ ::std::vector< String > HTMLSubstitutions;
+ FontWeight Weight;
+ FontWidth Width;
+ unsigned long Type; // bitfield of IMPL_FONT_ATTR_*
+};
+
+class UNOTOOLS_DLLPUBLIC FontSubstConfiguration
+{
+private:
+ com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >
+ m_xConfigProvider;
+ com::sun::star::uno::Reference< com::sun::star::container::XNameAccess >
+ m_xConfigAccess;
+ struct LocaleSubst
+ {
+ rtl::OUString aConfigLocaleString;
+ mutable bool bConfigRead;
+ // note: aSubstAttributes must be sorted alphabetically by Name
+ // searches on the substitutes are done with Name as key, where
+ // a minimal match is sufficient (that is e.g. "Thorndale" will match
+ // "Thorndale BlaBlub"). Also names must be lower case.
+ mutable std::vector< FontNameAttr > aSubstAttributes;
+
+ LocaleSubst() : bConfigRead( false ) {}
+ };
+ std::hash_map< com::sun::star::lang::Locale, LocaleSubst, utl::LocaleHash > m_aSubst;
+ typedef std::hash_set< rtl::OUString, rtl::OUStringHash > UniqueSubstHash;
+ mutable UniqueSubstHash maSubstHash;
+
+
+ void fillSubstVector( const com::sun::star::uno::Reference< com::sun::star::container::XNameAccess > xFont,
+ const rtl::OUString& rType,
+ std::vector< String >& rSubstVector ) const;
+ FontWeight getSubstWeight( const com::sun::star::uno::Reference< com::sun::star::container::XNameAccess > xFont,
+ const rtl::OUString& rType ) const;
+ FontWidth getSubstWidth( const com::sun::star::uno::Reference< com::sun::star::container::XNameAccess > xFont,
+ const rtl::OUString& rType ) const;
+ unsigned long getSubstType( const com::sun::star::uno::Reference< com::sun::star::container::XNameAccess > xFont,
+ const rtl::OUString& rType ) const;
+ void readLocaleSubst( const com::sun::star::lang::Locale& rLocale ) const;
+ FontSubstConfiguration();
+public:
+ ~FontSubstConfiguration();
+
+ static FontSubstConfiguration* get();
+
+ const FontNameAttr* getSubstInfo(
+ const String& rFontName,
+ const com::sun::star::lang::Locale& rLocale =
+ com::sun::star::lang::Locale( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "en" ) ),
+ rtl::OUString(),
+ rtl::OUString() )
+ ) const;
+ static void getMapName( const String& rOrgName, String& rShortName, String& rFamilyName, FontWeight& rWeight, FontWidth& rWidth, ULONG& rType );
+};
+
+} // namespace utl
+
+#endif // _UNOTOOLS_FONTCFG_HXX
diff --git a/unotools/inc/unotools/fontcvt.hxx b/unotools/inc/unotools/fontcvt.hxx
new file mode 100644
index 000000000000..679a2dc5a6d9
--- /dev/null
+++ b/unotools/inc/unotools/fontcvt.hxx
@@ -0,0 +1,82 @@
+/*************************************************************************
+ *
+ * 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: fontcvt.hxx,v $
+ * $Revision: 1.3 $
+ *
+ * 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.
+ *
+ ************************************************************************/
+
+#ifndef _UNOTOOLS_FONTCVT_HXX
+#define _UNOTOOLS_FONTCVT_HXX
+
+#include <unotools/unotoolsdllapi.h>
+#include <tools/string.hxx>
+
+// ------------------
+// - FontToSubsFont -
+// ------------------
+
+#define FONTTOSUBSFONT_IMPORT ((ULONG)0x00000001)
+#define FONTTOSUBSFONT_EXPORT ((ULONG)0x00000002)
+#define FONTTOSUBSFONT_ONLYOLDSOSYMBOLFONTS ((ULONG)0x00000004)
+
+typedef void* FontToSubsFontConverter;
+UNOTOOLS_DLLPUBLIC FontToSubsFontConverter CreateFontToSubsFontConverter( const String& rFontName, ULONG nFlags );
+UNOTOOLS_DLLPUBLIC void DestroyFontToSubsFontConverter( FontToSubsFontConverter hConverter );
+UNOTOOLS_DLLPUBLIC sal_Unicode ConvertFontToSubsFontChar( FontToSubsFontConverter hConverter, sal_Unicode c );
+UNOTOOLS_DLLPUBLIC String GetFontToSubsFontName( FontToSubsFontConverter hConverter );
+
+// ---------------------------
+// - StarSymbolToMSMultiFont -
+// ---------------------------
+
+class UNOTOOLS_DLLPUBLIC StarSymbolToMSMultiFont
+{
+public:
+ //Returns the name of the best windows symbol font which this char can be
+ //mapped to. Sets rChar to the correct position for that font. If no
+ //match found, then no name is returned, and rChar is unchanged. If you
+ //want to convert a string, you don't want to use this.
+ virtual String ConvertChar(sal_Unicode &rChar) = 0;
+
+ //Starts converting the string at position rIndex. It converts as much of
+ //the string that can be converted to the same symbol font and returns the
+ //name of that font. rIndex is modified to the last index that was
+ //converted. Typically you call if continously until rIndex ==
+ //rString.Len() and handle each section as seperate 8bit strings using
+ //seperate fonts. Will return an empty string for a continous section
+ //that has no possible mapping.
+ virtual String ConvertString(String &rString, xub_StrLen &rIndex) = 0;
+ virtual ~StarSymbolToMSMultiFont() {}
+};
+
+//with bPerfect set the converter will only try and convert symbols which have
+//perfect mappings to the windows symbols fonts. With it not set, it will
+//allow somewhat more dubious transformations that are nevertheless
+//recognizably similiar. Even in this mode there will be characters that fail.
+//The users of this might want to make a distinction between failed characters
+//which were inside and those outside the unicode private area.
+UNOTOOLS_DLLPUBLIC StarSymbolToMSMultiFont *CreateStarSymbolToMSMultiFont(bool bPerfectOnly=false);
+#endif // _UNOTOOLS_FONTCVT_HXX
diff --git a/unotools/inc/unotools/fontdefs.hxx b/unotools/inc/unotools/fontdefs.hxx
new file mode 100644
index 000000000000..e595fe45400d
--- /dev/null
+++ b/unotools/inc/unotools/fontdefs.hxx
@@ -0,0 +1,110 @@
+/*************************************************************************
+ *
+ * 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
+ *
+ * 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.
+ *
+ ************************************************************************/
+#ifndef _UNOTOOLS_FONTDEFS_HXX
+#define _UNOTOOLS_FONTDEFS_HXX
+
+#include <unotools/unotoolsdllapi.h>
+#include <sal/types.h>
+#include <tools/string.hxx>
+
+namespace utl {
+ class FontSubstConfiguration;
+ class FontNameAttr;
+}
+
+// ----------------
+// - SubsFontName -
+// ----------------
+
+#define SUBSFONT_ONLYONE ((ULONG)0x00000001)
+#define SUBSFONT_MS ((ULONG)0x00000002)
+#define SUBSFONT_PS ((ULONG)0x00000004)
+#define SUBSFONT_HTML ((ULONG)0x00000008)
+
+UNOTOOLS_DLLPUBLIC String GetSubsFontName( const String& rName, ULONG nFlags );
+
+// -----------------
+// - FontTokenName -
+// -----------------
+
+UNOTOOLS_DLLPUBLIC String GetFontToken( const String& rName, xub_StrLen nToken, xub_StrLen& rIndex );
+inline String GetFontToken( const String& rName, xub_StrLen nToken )
+{
+ xub_StrLen nTempIndex = 0;
+ return GetFontToken( rName, nToken, nTempIndex );
+}
+
+UNOTOOLS_DLLPUBLIC void AddTokenFontName( String& rName, const String& rNewToken );
+
+struct UNOTOOLS_DLLPUBLIC FontNameHash { int operator()(const String&) const; };
+
+// ---------------
+// - ConvertChar -
+// ---------------
+
+class UNOTOOLS_DLLPUBLIC ConvertChar
+{
+public:
+ const sal_Unicode* mpCvtTab;
+ const char* mpSubsFontName;
+ sal_Unicode (*mpCvtFunc)( sal_Unicode );
+ sal_Unicode RecodeChar( sal_Unicode c ) const;
+ void RecodeString( String& rStra, xub_StrLen nIndex, xub_StrLen nLen ) const;
+ static const ConvertChar* GetRecodeData( const String& rOrgFontName, const String& rMapFontName );
+};
+
+
+// Default-Font
+#define DEFAULTFONT_SANS_UNICODE ((USHORT)1)
+#define DEFAULTFONT_SANS ((USHORT)2)
+#define DEFAULTFONT_SERIF ((USHORT)3)
+#define DEFAULTFONT_FIXED ((USHORT)4)
+#define DEFAULTFONT_SYMBOL ((USHORT)5)
+#define DEFAULTFONT_UI_SANS ((USHORT)1000)
+#define DEFAULTFONT_UI_FIXED ((USHORT)1001)
+#define DEFAULTFONT_LATIN_TEXT ((USHORT)2000)
+#define DEFAULTFONT_LATIN_PRESENTATION ((USHORT)2001)
+#define DEFAULTFONT_LATIN_SPREADSHEET ((USHORT)2002)
+#define DEFAULTFONT_LATIN_HEADING ((USHORT)2003)
+#define DEFAULTFONT_LATIN_DISPLAY ((USHORT)2004)
+#define DEFAULTFONT_LATIN_FIXED ((USHORT)2005)
+#define DEFAULTFONT_CJK_TEXT ((USHORT)3000)
+#define DEFAULTFONT_CJK_PRESENTATION ((USHORT)3001)
+#define DEFAULTFONT_CJK_SPREADSHEET ((USHORT)3002)
+#define DEFAULTFONT_CJK_HEADING ((USHORT)3003)
+#define DEFAULTFONT_CJK_DISPLAY ((USHORT)3004)
+#define DEFAULTFONT_CTL_TEXT ((USHORT)4000)
+#define DEFAULTFONT_CTL_PRESENTATION ((USHORT)4001)
+#define DEFAULTFONT_CTL_SPREADSHEET ((USHORT)4002)
+#define DEFAULTFONT_CTL_HEADING ((USHORT)4003)
+#define DEFAULTFONT_CTL_DISPLAY ((USHORT)4004)
+
+UNOTOOLS_DLLPUBLIC String GetNextFontToken( const String& rTokenStr, xub_StrLen& rIndex );
+
+UNOTOOLS_DLLPUBLIC void GetEnglishSearchFontName( String& rName );
+
+#endif