1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_vcl.hxx"
31 #include <gcach_vdev.hxx>
33 #include <vcl/svapp.hxx>
34 #include <vcl/bitmap.hxx>
35 #include <vcl/outfont.hxx>
36 #include <vcl/virdev.hxx>
37 #include <vcl/metric.hxx>
39 // =======================================================================
41 // =======================================================================
43 // -----------------------------------------------------------------------
45 void VirtDevServerFont::AnnounceFonts( ImplDevFontList
* pToAdd
)
47 // TODO: get fonts on server but not on client,
48 // problem is that currently there is no serverside virtual device...
49 VirtualDevice
vdev( 1 );
50 long nCount
= vdev
.GetDevFontCount();
52 for( int i
= 0; i
< nCount
; ++i
)
54 const FontInfo aFontInfo
= vdev
.GetDevFont( i
);
56 ImplFontData
& rData
= *new ImplFontData
;
57 rData
.SetSysData( new FontSysData( (void*)SERVERFONT_MAGIC
) );
59 rData
.maName
= aFontInfo
.GetName();
60 rData
.maStyleName
= aFontInfo
.GetStyleName();
61 rData
.mnWidth
= aFontInfo
.GetWidth();
62 rData
.mnHeight
= aFontInfo
.GetHeight();
63 rData
.meFamily
= aFontInfo
.GetFamily();
64 rData
.meCharSet
= aFontInfo
.GetCharSet();
65 rData
.mePitch
= aFontInfo
.GetPitch();
66 rData
.meWidthType
= aFontInfo
.GetWidthType();
67 rData
.meWeight
= aFontInfo
.GetWeight();
68 rData
.meItalic
= aFontInfo
.GetItalic();
69 rData
.meType
= aFontInfo
.GetType();
70 rData
.meFamily
= aFontInfo
.GetFamily();
72 rData
.mbOrientation
= true; // TODO: where to get this info?
73 rData
.mbDevice
= false;
74 rData
.mnQuality
= 0; // prefer client-side fonts if available
76 pToAdd
->Add( &rData
);
80 // -----------------------------------------------------------------------
82 void VirtDevServerFont::ClearFontList()
87 // -----------------------------------------------------------------------
89 VirtDevServerFont
* VirtDevServerFont::CreateFont( const ImplFontSelectData
& rFSD
)
91 VirtDevServerFont
* pServerFont
= NULL
;
92 // TODO: search list of VirtDevServerFonts, return NULL if not found
93 // pServerFont = new VirtDevServerFont( rFSD );
97 // -----------------------------------------------------------------------
99 VirtDevServerFont::VirtDevServerFont( const ImplFontSelectData
& rFSD
)
103 // -----------------------------------------------------------------------
105 void VirtDevServerFont::FetchFontMetric( ImplFontMetricData
& rTo
, long& rFactor
) const
107 const ImplFontSelectData
& aFSD
= GetFontSelData();
110 aFont
.SetName ( aFSD
.maName
);
111 aFont
.SetStyleName ( aFSD
.maStyleName
);
112 aFont
.SetHeight ( aFSD
.mnHeight
);
113 aFont
.SetWidth ( aFSD
.mnWidth
);
114 aFont
.SetOrientation( aFSD
.mnOrientation
);
115 aFont
.SetVertical ( GetFontSelData().mbVertical
);
117 VirtualDevice
vdev( 1 );
118 FontMetric
aMetric( vdev
.GetFontMetric( aFont
) );
122 rTo
.mnAscent
= aMetric
.GetAscent();
123 rTo
.mnDescent
= aMetric
.GetDescent();
124 rTo
.mnIntLeading
= aMetric
.GetIntLeading();
125 rTo
.mnExtLeading
= aMetric
.GetExtLeading();
126 rTo
.mnSlant
= aMetric
.GetSlant();
127 rTo
.meType
= aMetric
.GetType();
128 rTo
.mnFirstChar
= 0x0020; // TODO: where to get this info?
129 rTo
.mnLastChar
= 0xFFFE; // TODO: where to get this info?
131 rTo
.mnWidth
= aFSD
.mnWidth
;
132 rTo
.maName
= aFSD
.maName
;
133 rTo
.maStyleName
= aFSD
.maStyleName
;
134 rTo
.mnOrientation
= aFSD
.mnOrientation
;
135 rTo
.meFamily
= aFSD
.meFamily
;
136 rTo
.meCharSet
= aFSD
.meCharSet
;
137 rTo
.meWeight
= aFSD
.meWeight
;
138 rTo
.meItalic
= aFSD
.meItalic
;
139 rTo
.mePitch
= aFSD
.mePitch
;
140 rTo
.mbDevice
= FALSE
;
143 // -----------------------------------------------------------------------
145 int VirtDevServerFont::GetGlyphIndex( sal_Unicode aChar
) const
150 // -----------------------------------------------------------------------
152 void VirtDevServerFont::InitGlyphData( int nGlyphIndex
, GlyphData
& rGD
) const
155 aFont
.SetName ( GetFontSelData().maName
);
156 aFont
.SetStyleName ( GetFontSelData().maStyleName
);
157 aFont
.SetHeight ( GetFontSelData().mnHeight
);
158 aFont
.SetWidth ( GetFontSelData().mnWidth
);
159 aFont
.SetOrientation( GetFontSelData().mnOrientation
);
160 aFont
.SetVertical ( GetFontSelData().mbVertical
);
162 VirtualDevice
vdev( 1 );
163 vdev
.SetFont( aFont
);
166 sal_Int32 nCharWidth
= 10;
167 // TODO: vdev.GetCharWidth( nGlyphIndex, nGlyphIndex, &nCharWidth );
168 rGD
.SetCharWidth( nCharWidth
);
170 sal_Unicode aChar
= nGlyphIndex
;
171 String
aGlyphStr( &aChar
, 1 );
173 if( vdev
.GetTextBoundRect( aRect
, aGlyphStr
, 0, 1 ) )
175 rGD
.SetOffset( aRect
.Top(), aRect
.Left() );
176 rGD
.SetDelta( vdev
.GetTextWidth( nGlyphIndex
), 0 );
177 rGD
.SetSize( aRect
.GetSize() );
181 // -----------------------------------------------------------------------
183 bool VirtDevServerFont::GetAntialiasAdvice( void ) const
188 // -----------------------------------------------------------------------
190 bool VirtDevServerFont::GetGlyphBitmap1( int nGlyphIndex
, RawBitmap
& ) const
193 sal_Unicode aChar = nGlyphIndex;
194 String aGlyphStr( &aChar, 1 );
197 vdev.SetOutputSizePixel( aSize, TRUE );
198 vdev.DrawText( Point(0,0)-rGD.GetMetric().GetOffset(), aGlyphStr );
200 // create new glyph item
202 const Bitmap& rBitmap = vdev.GetBitmap( Point(0,0), aSize );
203 rGD.SetBitmap( new Bitmap( rBitmap ) );
209 // -----------------------------------------------------------------------
211 bool VirtDevServerFont::GetGlyphBitmap8( int nGlyphIndex
, RawBitmap
& ) const
216 // -----------------------------------------------------------------------
218 int VirtDevServerFont::GetGlyphKernValue( int, int ) const
223 // -----------------------------------------------------------------------
225 ULONG
VirtDevServerFont::GetKernPairs( ImplKernPairData
** ppImplKernPairs
) const
228 aFont
.SetName ( GetFontSelData().maName
);
229 aFont
.SetStyleName ( GetFontSelData().maStyleName
);
230 aFont
.SetHeight ( GetFontSelData().mnHeight
);
231 aFont
.SetWidth ( GetFontSelData().mnWidth
);
232 aFont
.SetOrientation( GetFontSelData().mnOrientation
);
233 aFont
.SetVertical ( GetFontSelData().mbVertical
);
235 VirtualDevice
vdev( 1 );
236 vdev
.SetFont( aFont
);
238 ULONG nPairs
= vdev
.GetKerningPairCount();
241 KerningPair
* const pKernPairs
= new KerningPair
[ nPairs
];
242 vdev
.GetKerningPairs( nPairs
, pKernPairs
);
244 *ppImplKernPairs
= new ImplKernPairData
[ nPairs
];
245 ImplKernPairData
* pTo
= *ppImplKernPairs
;
246 KerningPair
* pFrom
= pKernPairs
;
247 for ( ULONG n
= 0; n
< nPairs
; n
++ )
249 pTo
->mnChar1
= pFrom
->nChar1
;
250 pTo
->mnChar2
= pFrom
->nChar2
;
251 pTo
->mnKern
= pFrom
->nKern
;
262 // -----------------------------------------------------------------------
264 bool VirtDevServerFont::GetGlyphOutline( int nGlyphIndex
, PolyPolygon
& rPolyPoly
) const
269 aFont.SetName ( GetFontSelData().maName );
270 aFont.SetStyleName ( GetFontSelData().maStyleName );
271 aFont.SetHeight ( GetFontSelData().mnHeight );
272 aFont.SetWidth ( GetFontSelData().mnWidth );
273 aFont.SetOrientation( GetFontSelData().mnOrientation );
274 aFont.SetVertical ( GetFontSelData().mbVertical );
276 VirtualDevice vdev( 1 );
277 vdev.SetFont( aFont );
279 const bool bOptimize = true;
281 sal_Unicode aChar = nGlyphIndex;
282 String aGlyphStr( &aChar, 1 );
283 return vdev.GetTextOutline( rPolyPoly, aGlyphStr, 0, 1, bOptimize );
287 // =======================================================================