xref: /AOO41X/main/svtools/source/edit/sychconv.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_svtools.hxx"
30*cdf0e10cSrcweir #include <svtools/sychconv.hxx>
31*cdf0e10cSrcweir #include <vcl/outdev.hxx>
32*cdf0e10cSrcweir 
33*cdf0e10cSrcweir sal_Bool SymCharConverter::Convert( Font& rFont, UniString& rString, OutputDevice* pDev )
34*cdf0e10cSrcweir {
35*cdf0e10cSrcweir     // hibyte 0 = exact matching
36*cdf0e10cSrcweir     //		  1 = little differences,
37*cdf0e10cSrcweir     //		  2 = the converted character does not look like the original but got the same meaning
38*cdf0e10cSrcweir     //		  3 = the destination does not match looking and meaning of the original
39*cdf0e10cSrcweir 
40*cdf0e10cSrcweir 	static sal_uInt16 __READONLY_DATA aWingdingsToStarBatsTable[ 256 - 32 ] =
41*cdf0e10cSrcweir 	{
42*cdf0e10cSrcweir 		0x0020, 0x0238, 0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0174,	0x02BA,	0x017B,	0x017C,	0x037C,	0x037C,	0x037C,	0x037C,
43*cdf0e10cSrcweir 		0x0000, 0x0000, 0x0372,	0x0272,	0x0372,	0x0000,	0x0000,	0x0374,	0x0279,	0x0000,	0x027A,	0x0000,	0x0178,	0x0278,	0x0000,	0x0137,
44*cdf0e10cSrcweir 		0x027E, 0x0000, 0x0000,	0x0000,	0x0000,	0x0000,	0x017D,	0x0000,	0x0000,	0x0000,	0x0021,	0x03AC,	0x00AD,	0x0000,	0x0000,	0x0000,
45*cdf0e10cSrcweir 		0x0000, 0x0000, 0x01C0,	0x0000,	0x0000,	0x0286,	0x0286,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,
46*cdf0e10cSrcweir 		0x0000, 0x0000, 0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0022,	0x0023,	0x0024,	0x0025,
47*cdf0e10cSrcweir 		0x0026, 0x0027, 0x0028,	0x0029,	0x002A,	0x002B,	0x002C,	0x002D,	0x0133,	0x0000,	0x0000,	0x0000,	0x0000,	0x0193,	0x0194,	0x0000,
48*cdf0e10cSrcweir 		0x0067, 0x0068, 0x0069,	0x006A,	0x006B,	0x006C,	0x006D,	0x006E,	0x006F,	0x0070,	0x0071,	0x005C,	0x005D,	0x005E,	0x005F,	0x0060,
49*cdf0e10cSrcweir 		0x0061, 0x0062, 0x0063,	0x0064,	0x0065,	0x0066,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x01A5,	0x0095,
50*cdf0e10cSrcweir 		0x0000, 0x0000, 0x0000,	0x0000,	0x0000,	0x0000,	0x002E,	0x0024,	0x0125,	0x0000,	0x0000,	0x0000,	0x014B,	0x024D,	0x014E,	0x014A,
51*cdf0e10cSrcweir 		0x0000, 0x0000, 0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,
52*cdf0e10cSrcweir 		0x0000, 0x0000, 0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,
53*cdf0e10cSrcweir 		0x0000, 0x0000, 0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x002F,	0x0000,	0x0000,	0x0000,	0x0035,	0x0000,	0x0000,	0x0000,
54*cdf0e10cSrcweir 		0x0030, 0x0000, 0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0031,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x01B1,
55*cdf0e10cSrcweir 		0x01AF, 0x01B2, 0x01B0,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0150,	0x0032,	0x0033,	0x0034,	0x01C8
56*cdf0e10cSrcweir 	};
57*cdf0e10cSrcweir 
58*cdf0e10cSrcweir 	static sal_uInt16 __READONLY_DATA aMonotypeSortsToStarBatsTable[ 256 - 32 ]=
59*cdf0e10cSrcweir 	{
60*cdf0e10cSrcweir 		0x0020,	0x00cb,	0x00cb,	0x00cb,	0x00cb,	0x0074,	0x00ba,	0x0021,	0x00cc,	0x007b,	0x0036,	0x007d,	0x007e,	0x0037,	0x0038,	0x0038,
61*cdf0e10cSrcweir 		0x0039,	0x0038,	0x0038,	0x0039,	0x003a,	0x004f,	0x0050,	0x004f,	0x0050,	0x0051,	0x0052,	0x0053,	0x0054,	0x0086,	0x0086,	0x0086,
62*cdf0e10cSrcweir 		0x0052,	0x00cd,	0x0044,	0x0045,	0x0046,	0x0047,	0x0041,	0x0041,	0x0058,	0x0057,	0x0075,	0x0055,	0x0056,	0x0057,	0x0058,	0x0059,
63*cdf0e10cSrcweir 		0x005a,	0x004b,	0x004b,	0x0048,	0x0049,	0x004a,	0x004b,	0x004c,	0x004d,	0x004e,	0x004e,	0x004b,	0x004b,	0x00ce,	0x00ce,	0x00ce,
64*cdf0e10cSrcweir 		0x00ce,	0x00ce,	0x00ce,	0x00ce,	0x00cf,	0x00cf,	0x00cf,	0x00cf,	0x00cf,	0x00cf,	0x00b9,	0x00b9,	0x003b,	0x003c,	0x003d,	0x003e,
65*cdf0e10cSrcweir 		0x003f,	0x003e,	0x0040,	0x00c5,	0x00c4,	0x002b,	0x002c,	0x00d0,	0x00d1,	0x00d1,	0x00d1,	0x0091,	0x0092,	0x0093,	0x0094,	0x0000,
66*cdf0e10cSrcweir 		0x00d2,	0x00d3,	0x00d2,	0x00d3,	0x00d2,	0x00d3,	0x00d2,	0x00d3,	0x00d2,	0x00d3,	0x00d2,	0x00d3,	0x00d2,	0x00d3,	0x0000,	0x0000,
67*cdf0e10cSrcweir 		0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,
68*cdf0e10cSrcweir 		0x0000,	0x00d4,	0x00d4,	0x00d4,	0x00d6,	0x00d6,	0x00d4,	0x00d4,	0x00d5,	0x002a,	0x00d6,	0x00d7,	0x0068,	0x0069,	0x006a,	0x006b,
69*cdf0e10cSrcweir 		0x006c,	0x006d,	0x006e,	0x006f,	0x0070,	0x0071,	0x005d,	0x005e,	0x005f,	0x0060,	0x0061,	0x0062,	0x0063,	0x0064,	0x0065,	0x0066,
70*cdf0e10cSrcweir 		0x0068,	0x0069,	0x006a,	0x006b,	0x006c,	0x006d,	0x006e,	0x006f,	0x0070,	0x0071,	0x005d,	0x005e,	0x005f,	0x0060,	0x0061,	0x0062,
71*cdf0e10cSrcweir 		0x0063,	0x0064,	0x0065,	0x0066,	0x0030,	0x0031,	0x00d8,	0x00d9,	0x00da,	0x00bc,	0x00db,	0x00bc,	0x00bc,	0x00bc,	0x00bc,	0x0031,
72*cdf0e10cSrcweir 		0x0031,	0x0031,	0x002f,	0x002f,	0x002f,	0x00be,	0x00be,	0x0031,	0x0031,	0x00af,	0x00af,	0x00af,	0x00af,	0x00af,	0x00af,	0x00af,
73*cdf0e10cSrcweir 		0x0000,	0x00af,	0x0035,	0x00dc,	0x00da,	0x00dc,	0x00db,	0x00da,	0x00dc,	0x00db,	0x00dc,	0x00dc,	0x00dc,	0x00dc,	0x00af,	0x0000
74*cdf0e10cSrcweir 	};
75*cdf0e10cSrcweir 
76*cdf0e10cSrcweir 	const sal_uInt16* pTransTable = NULL;
77*cdf0e10cSrcweir 
78*cdf0e10cSrcweir 	sal_Bool bIsAvailable = ( pDev ) ? pDev->IsFontAvailable( rFont.GetName() ) : sal_False;
79*cdf0e10cSrcweir 	if ( !bIsAvailable )
80*cdf0e10cSrcweir 	{
81*cdf0e10cSrcweir 		if ( rFont.GetName().CompareToAscii( RTL_CONSTASCII_STRINGPARAM( "Wingdings" ) ) == COMPARE_EQUAL )
82*cdf0e10cSrcweir 			pTransTable = &aWingdingsToStarBatsTable[ 0 ];
83*cdf0e10cSrcweir 		else if ( rFont.GetName().CompareToAscii( RTL_CONSTASCII_STRINGPARAM( "Monotype Sorts" ) ) == COMPARE_EQUAL )
84*cdf0e10cSrcweir 			pTransTable = &aMonotypeSortsToStarBatsTable[ 0 ];
85*cdf0e10cSrcweir 	}
86*cdf0e10cSrcweir 	if ( pTransTable )
87*cdf0e10cSrcweir 	{
88*cdf0e10cSrcweir 		sal_Unicode c;
89*cdf0e10cSrcweir 		for ( sal_uInt16 i = rString.Len(); i--; )
90*cdf0e10cSrcweir 		{
91*cdf0e10cSrcweir 			c = rString.GetChar( i );
92*cdf0e10cSrcweir 			c -= 32;
93*cdf0e10cSrcweir 			c = ( ((sal_uInt16)c) >= 224 ) ? 0 : (sal_Unicode) pTransTable[ c ];
94*cdf0e10cSrcweir 			if ( !c )				// if character is out of range or not matching
95*cdf0e10cSrcweir 				c = 0xA5;			// we will default a StarBats-Bullet
96*cdf0e10cSrcweir 			rString.SetChar( i, c );
97*cdf0e10cSrcweir 		}
98*cdf0e10cSrcweir 		rFont.SetCharSet( RTL_TEXTENCODING_SYMBOL );
99*cdf0e10cSrcweir 		rFont.SetName( String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "StarBats" ) ) );
100*cdf0e10cSrcweir 		return sal_True;
101*cdf0e10cSrcweir 	}
102*cdf0e10cSrcweir 	else return sal_False;
103*cdf0e10cSrcweir };
104