xref: /aoo41x/main/sw/source/core/inc/fntcache.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
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.
14  *
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).
20  *
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.
25  *
26  ************************************************************************/
27 #ifndef _FNTCACHE_HXX
28 #define _FNTCACHE_HXX
29 
30 #include <vcl/font.hxx>
31 #include <tools/mempool.hxx>
32 
33 #include "swtypes.hxx"
34 #include "swcache.hxx"
35 
36 class Printer;
37 class OutputDevice;
38 class FontMetric;
39 class SwFntObj;
40 class SwDrawTextInfo;	// DrawText
41 class ViewShell;
42 class SwSubFont;
43 class MapMode;
44 
45 /*************************************************************************
46  *                      class SwFntCache
47  *************************************************************************/
48 
49 class SwFntCache : public SwCache
50 {
51 public:
52 
53 	inline SwFntCache() : SwCache(50,50
54 #ifdef DBG_UTIL
55 	, ByteString( RTL_CONSTASCII_STRINGPARAM(
56 						"Globaler Font-Cache pFntCache" ))
57 #endif
58 	) {}
59 
60 	inline SwFntObj *First( ) { return (SwFntObj *)SwCache::First(); }
61 	inline SwFntObj *Next( SwFntObj *pFntObj)
62 		{ return (SwFntObj *)SwCache::Next( (SwCacheObj *)pFntObj ); }
63 	void Flush();
64 };
65 
66 // Font-Cache, globale Variable, in txtinit.Cxx angelegt/zerstoert
67 extern SwFntCache *pFntCache;
68 extern SwFntObj *pLastFont;
69 extern sal_uInt8 *pMagicNo;
70 extern Color *pWaveCol;
71 
72 /*************************************************************************
73  *                      class SwFntObj
74  *************************************************************************/
75 
76 class SwFntObj : public SwCacheObj
77 {
78 	friend class SwFntAccess;
79 	friend void _InitCore();
80 	friend void _FinitCore();
81 
82 	Font aFont;
83 	Font *pScrFont;
84 	Font *pPrtFont;
85     OutputDevice* pPrinter;
86     sal_uInt16 nGuessedLeading;
87     sal_uInt16 nExtLeading;
88 	sal_uInt16 nScrAscent;
89 	sal_uInt16 nPrtAscent;
90 	sal_uInt16 nScrHeight;
91 	sal_uInt16 nPrtHeight;
92 	sal_uInt16 nPropWidth;
93 	sal_uInt16 nZoom;
94 	sal_Bool bSymbol : 1;
95 	sal_Bool bPaintBlank : 1;
96 
97 	static long nPixWidth;
98 	static MapMode *pPixMap;
99 	static OutputDevice *pPixOut;
100 
101     // SMARTTAGS
102     void calcLinePos(SwDrawTextInfo& rInf, Point& aStart, Point& aEnd, xub_StrLen nStart,
103        xub_StrLen nWrLen, xub_StrLen nCnt, const sal_Bool bSwitchH2V, const sal_Bool bSwitchL2R,
104        long nHalfSpace, long* pKernArray, const sal_Bool bBidiPor);
105 
106 public:
107 	DECL_FIXEDMEMPOOL_NEWDEL(SwFntObj)
108 
109 	SwFntObj( const SwSubFont &rFont, const void* pOwner,
110 			  ViewShell *pSh );
111 
112 	virtual ~SwFntObj();
113 
114 	inline 		 Font *GetScrFont()		{ return pScrFont; }
115 	inline 		 Font *GetFont()		{ return &aFont; }
116 	inline const Font *GetFont() const  { return &aFont; }
117 
118     inline sal_uInt16 GetGuessedLeading() const  { return nGuessedLeading; }
119     inline sal_uInt16 GetExtLeading() const  { return nExtLeading; }
120 
121     sal_uInt16 GetFontAscent( const ViewShell *pSh, const OutputDevice& rOut );
122     sal_uInt16 GetFontHeight( const ViewShell *pSh, const OutputDevice& rOut );
123     sal_uInt16 GetFontLeading( const ViewShell *pSh, const OutputDevice& rOut );
124 
125     void GuessLeading( const ViewShell& rSh, const FontMetric& rMet );
126 
127     void SetDevFont( const ViewShell *pSh, OutputDevice& rOut );
128     inline OutputDevice* GetPrt() const { return pPrinter; }
129 	inline sal_uInt16	GetZoom() const { return nZoom; }
130 	inline sal_uInt16	GetPropWidth() const { return nPropWidth; }
131 	inline sal_Bool		IsSymbol() const { return bSymbol; }
132 
133 	void   DrawText( SwDrawTextInfo &rInf );
134 	Size  GetTextSize( SwDrawTextInfo &rInf );
135 	xub_StrLen GetCrsrOfst( SwDrawTextInfo &rInf );
136 
137     void CreateScrFont( const ViewShell& rSh, const OutputDevice& rOut );
138     void CreatePrtFont( const OutputDevice& rOut );
139 };
140 
141 /*************************************************************************
142  *                      class SwFntAccess
143  *************************************************************************/
144 
145 
146 class SwFntAccess : public SwCacheAccess
147 {
148 	ViewShell *pShell;
149 protected:
150 	virtual SwCacheObj *NewObj( );
151 
152 public:
153 	SwFntAccess( const void * &rMagic, sal_uInt16 &rIndex, const void *pOwner,
154 				 ViewShell *pShell,
155 				 sal_Bool bCheck = sal_False  );
156     inline SwFntObj* Get() { return (SwFntObj*) SwCacheAccess::Get(); };
157 };
158 
159 
160 #endif
161