xref: /trunk/main/svtools/source/edit/sychconv.cxx (revision 5900e8ec)
1*5900e8ecSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*5900e8ecSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*5900e8ecSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*5900e8ecSAndrew Rist  * distributed with this work for additional information
6*5900e8ecSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*5900e8ecSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*5900e8ecSAndrew Rist  * "License"); you may not use this file except in compliance
9*5900e8ecSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*5900e8ecSAndrew Rist  *
11*5900e8ecSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*5900e8ecSAndrew Rist  *
13*5900e8ecSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*5900e8ecSAndrew Rist  * software distributed under the License is distributed on an
15*5900e8ecSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*5900e8ecSAndrew Rist  * KIND, either express or implied.  See the License for the
17*5900e8ecSAndrew Rist  * specific language governing permissions and limitations
18*5900e8ecSAndrew Rist  * under the License.
19*5900e8ecSAndrew Rist  *
20*5900e8ecSAndrew Rist  *************************************************************/
21*5900e8ecSAndrew Rist 
22*5900e8ecSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svtools.hxx"
26cdf0e10cSrcweir #include <svtools/sychconv.hxx>
27cdf0e10cSrcweir #include <vcl/outdev.hxx>
28cdf0e10cSrcweir 
Convert(Font & rFont,UniString & rString,OutputDevice * pDev)29cdf0e10cSrcweir sal_Bool SymCharConverter::Convert( Font& rFont, UniString& rString, OutputDevice* pDev )
30cdf0e10cSrcweir {
31cdf0e10cSrcweir     // hibyte 0 = exact matching
32cdf0e10cSrcweir     //		  1 = little differences,
33cdf0e10cSrcweir     //		  2 = the converted character does not look like the original but got the same meaning
34cdf0e10cSrcweir     //		  3 = the destination does not match looking and meaning of the original
35cdf0e10cSrcweir 
36cdf0e10cSrcweir 	static sal_uInt16 __READONLY_DATA aWingdingsToStarBatsTable[ 256 - 32 ] =
37cdf0e10cSrcweir 	{
38cdf0e10cSrcweir 		0x0020, 0x0238, 0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0174,	0x02BA,	0x017B,	0x017C,	0x037C,	0x037C,	0x037C,	0x037C,
39cdf0e10cSrcweir 		0x0000, 0x0000, 0x0372,	0x0272,	0x0372,	0x0000,	0x0000,	0x0374,	0x0279,	0x0000,	0x027A,	0x0000,	0x0178,	0x0278,	0x0000,	0x0137,
40cdf0e10cSrcweir 		0x027E, 0x0000, 0x0000,	0x0000,	0x0000,	0x0000,	0x017D,	0x0000,	0x0000,	0x0000,	0x0021,	0x03AC,	0x00AD,	0x0000,	0x0000,	0x0000,
41cdf0e10cSrcweir 		0x0000, 0x0000, 0x01C0,	0x0000,	0x0000,	0x0286,	0x0286,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,
42cdf0e10cSrcweir 		0x0000, 0x0000, 0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0022,	0x0023,	0x0024,	0x0025,
43cdf0e10cSrcweir 		0x0026, 0x0027, 0x0028,	0x0029,	0x002A,	0x002B,	0x002C,	0x002D,	0x0133,	0x0000,	0x0000,	0x0000,	0x0000,	0x0193,	0x0194,	0x0000,
44cdf0e10cSrcweir 		0x0067, 0x0068, 0x0069,	0x006A,	0x006B,	0x006C,	0x006D,	0x006E,	0x006F,	0x0070,	0x0071,	0x005C,	0x005D,	0x005E,	0x005F,	0x0060,
45cdf0e10cSrcweir 		0x0061, 0x0062, 0x0063,	0x0064,	0x0065,	0x0066,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x01A5,	0x0095,
46cdf0e10cSrcweir 		0x0000, 0x0000, 0x0000,	0x0000,	0x0000,	0x0000,	0x002E,	0x0024,	0x0125,	0x0000,	0x0000,	0x0000,	0x014B,	0x024D,	0x014E,	0x014A,
47cdf0e10cSrcweir 		0x0000, 0x0000, 0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,
48cdf0e10cSrcweir 		0x0000, 0x0000, 0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,
49cdf0e10cSrcweir 		0x0000, 0x0000, 0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x002F,	0x0000,	0x0000,	0x0000,	0x0035,	0x0000,	0x0000,	0x0000,
50cdf0e10cSrcweir 		0x0030, 0x0000, 0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0031,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x01B1,
51cdf0e10cSrcweir 		0x01AF, 0x01B2, 0x01B0,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0150,	0x0032,	0x0033,	0x0034,	0x01C8
52cdf0e10cSrcweir 	};
53cdf0e10cSrcweir 
54cdf0e10cSrcweir 	static sal_uInt16 __READONLY_DATA aMonotypeSortsToStarBatsTable[ 256 - 32 ]=
55cdf0e10cSrcweir 	{
56cdf0e10cSrcweir 		0x0020,	0x00cb,	0x00cb,	0x00cb,	0x00cb,	0x0074,	0x00ba,	0x0021,	0x00cc,	0x007b,	0x0036,	0x007d,	0x007e,	0x0037,	0x0038,	0x0038,
57cdf0e10cSrcweir 		0x0039,	0x0038,	0x0038,	0x0039,	0x003a,	0x004f,	0x0050,	0x004f,	0x0050,	0x0051,	0x0052,	0x0053,	0x0054,	0x0086,	0x0086,	0x0086,
58cdf0e10cSrcweir 		0x0052,	0x00cd,	0x0044,	0x0045,	0x0046,	0x0047,	0x0041,	0x0041,	0x0058,	0x0057,	0x0075,	0x0055,	0x0056,	0x0057,	0x0058,	0x0059,
59cdf0e10cSrcweir 		0x005a,	0x004b,	0x004b,	0x0048,	0x0049,	0x004a,	0x004b,	0x004c,	0x004d,	0x004e,	0x004e,	0x004b,	0x004b,	0x00ce,	0x00ce,	0x00ce,
60cdf0e10cSrcweir 		0x00ce,	0x00ce,	0x00ce,	0x00ce,	0x00cf,	0x00cf,	0x00cf,	0x00cf,	0x00cf,	0x00cf,	0x00b9,	0x00b9,	0x003b,	0x003c,	0x003d,	0x003e,
61cdf0e10cSrcweir 		0x003f,	0x003e,	0x0040,	0x00c5,	0x00c4,	0x002b,	0x002c,	0x00d0,	0x00d1,	0x00d1,	0x00d1,	0x0091,	0x0092,	0x0093,	0x0094,	0x0000,
62cdf0e10cSrcweir 		0x00d2,	0x00d3,	0x00d2,	0x00d3,	0x00d2,	0x00d3,	0x00d2,	0x00d3,	0x00d2,	0x00d3,	0x00d2,	0x00d3,	0x00d2,	0x00d3,	0x0000,	0x0000,
63cdf0e10cSrcweir 		0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,	0x0000,
64cdf0e10cSrcweir 		0x0000,	0x00d4,	0x00d4,	0x00d4,	0x00d6,	0x00d6,	0x00d4,	0x00d4,	0x00d5,	0x002a,	0x00d6,	0x00d7,	0x0068,	0x0069,	0x006a,	0x006b,
65cdf0e10cSrcweir 		0x006c,	0x006d,	0x006e,	0x006f,	0x0070,	0x0071,	0x005d,	0x005e,	0x005f,	0x0060,	0x0061,	0x0062,	0x0063,	0x0064,	0x0065,	0x0066,
66cdf0e10cSrcweir 		0x0068,	0x0069,	0x006a,	0x006b,	0x006c,	0x006d,	0x006e,	0x006f,	0x0070,	0x0071,	0x005d,	0x005e,	0x005f,	0x0060,	0x0061,	0x0062,
67cdf0e10cSrcweir 		0x0063,	0x0064,	0x0065,	0x0066,	0x0030,	0x0031,	0x00d8,	0x00d9,	0x00da,	0x00bc,	0x00db,	0x00bc,	0x00bc,	0x00bc,	0x00bc,	0x0031,
68cdf0e10cSrcweir 		0x0031,	0x0031,	0x002f,	0x002f,	0x002f,	0x00be,	0x00be,	0x0031,	0x0031,	0x00af,	0x00af,	0x00af,	0x00af,	0x00af,	0x00af,	0x00af,
69cdf0e10cSrcweir 		0x0000,	0x00af,	0x0035,	0x00dc,	0x00da,	0x00dc,	0x00db,	0x00da,	0x00dc,	0x00db,	0x00dc,	0x00dc,	0x00dc,	0x00dc,	0x00af,	0x0000
70cdf0e10cSrcweir 	};
71cdf0e10cSrcweir 
72cdf0e10cSrcweir 	const sal_uInt16* pTransTable = NULL;
73cdf0e10cSrcweir 
74cdf0e10cSrcweir 	sal_Bool bIsAvailable = ( pDev ) ? pDev->IsFontAvailable( rFont.GetName() ) : sal_False;
75cdf0e10cSrcweir 	if ( !bIsAvailable )
76cdf0e10cSrcweir 	{
77cdf0e10cSrcweir 		if ( rFont.GetName().CompareToAscii( RTL_CONSTASCII_STRINGPARAM( "Wingdings" ) ) == COMPARE_EQUAL )
78cdf0e10cSrcweir 			pTransTable = &aWingdingsToStarBatsTable[ 0 ];
79cdf0e10cSrcweir 		else if ( rFont.GetName().CompareToAscii( RTL_CONSTASCII_STRINGPARAM( "Monotype Sorts" ) ) == COMPARE_EQUAL )
80cdf0e10cSrcweir 			pTransTable = &aMonotypeSortsToStarBatsTable[ 0 ];
81cdf0e10cSrcweir 	}
82cdf0e10cSrcweir 	if ( pTransTable )
83cdf0e10cSrcweir 	{
84cdf0e10cSrcweir 		sal_Unicode c;
85cdf0e10cSrcweir 		for ( sal_uInt16 i = rString.Len(); i--; )
86cdf0e10cSrcweir 		{
87cdf0e10cSrcweir 			c = rString.GetChar( i );
88cdf0e10cSrcweir 			c -= 32;
89cdf0e10cSrcweir 			c = ( ((sal_uInt16)c) >= 224 ) ? 0 : (sal_Unicode) pTransTable[ c ];
90cdf0e10cSrcweir 			if ( !c )				// if character is out of range or not matching
91cdf0e10cSrcweir 				c = 0xA5;			// we will default a StarBats-Bullet
92cdf0e10cSrcweir 			rString.SetChar( i, c );
93cdf0e10cSrcweir 		}
94cdf0e10cSrcweir 		rFont.SetCharSet( RTL_TEXTENCODING_SYMBOL );
95cdf0e10cSrcweir 		rFont.SetName( String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "StarBats" ) ) );
96cdf0e10cSrcweir 		return sal_True;
97cdf0e10cSrcweir 	}
98cdf0e10cSrcweir 	else return sal_False;
99cdf0e10cSrcweir };
100