xref: /trunk/main/vcl/inc/graphite_adaptors.hxx (revision 161f4cd1)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _SV_GRAPHITEADAPTORS_HXX
25 #define _SV_GRAPHITEADAPTORS_HXX
26 
27 // We need this to enable namespace support in libgrengine headers.
28 #define GR_NAMESPACE
29 
30 // Standard Library
31 #include <stdexcept>
32 // Platform
33 
34 #ifndef _SVWIN_H
35 #include <tools/svwin.h>
36 #endif
37 
38 #ifndef _SV_SVSYS_HXX
39 #include <svsys.h>
40 #endif
41 
42 #ifndef _SV_SALGDI_HXX
43 #include <salgdi.hxx>
44 #endif
45 
46 #ifndef _SV_SALLAYOUT_HXX
47 #include <sallayout.hxx>
48 #endif
49 
50 // Module
51 #include "vcl/dllapi.h"
52 
53 // Libraries
54 #include <preextstl.h>
55 #include <graphite/GrClient.h>
56 #include <graphite/Font.h>
57 #include <graphite/ITextSource.h>
58 #include <postextstl.h>
59 
60 // Module type definitions and forward declarations.
61 //
62 #ifndef MSC
63 // SAL/VCL types
64 class ServerFont;
65 class FreetypeServerFont;
66 
67 // Graphite types
68 
69 struct FontProperties : gr::FontProps
70 {
71     FontProperties(const FreetypeServerFont & font) throw();
72 };
73 
74 namespace grutils
75 {
76     class GrFeatureParser;
77 }
78 
79 // This class adapts the Sal font and graphics services to form required by
80 // the Graphite engine.
81 // @author tse
82 //
83 class VCL_PLUGIN_PUBLIC GraphiteFontAdaptor : public gr::Font
84 {
85     typedef std::map<const gr::gid16, std::pair<gr::Rect, gr::Point> > GlyphMetricMap;
86     friend class GrFontHasher;
87 public:
88     static bool    IsGraphiteEnabledFont(ServerFont &) throw();
89 
90     GraphiteFontAdaptor(ServerFont & font, const sal_Int32 dpi_x, const sal_Int32 dpi_y);
91     GraphiteFontAdaptor(const GraphiteFontAdaptor &) throw();
92     ~GraphiteFontAdaptor() throw();
93 
94      gr::Font    * copyThis();
95 
96     // Basic attribute accessors.
97     virtual float        ascent();
98     virtual float        descent();
99     virtual bool        bold();
100     virtual bool        italic();
101     virtual float        height();
102     virtual unsigned int    getDPIx();
103     virtual unsigned int    getDPIy();
104 
105     // Font access methods.
106     virtual const void    * getTable(gr::fontTableId32 tableID, size_t * pcbSize);
107     virtual void          getFontMetrics(float * ascent_out, float * descent_out = 0, float * em_square_out = 0);
108 
109     // Glyph metrics.
110     virtual void      getGlyphMetrics(gr::gid16 glyphID, gr::Rect & boundingBox, gr::Point & advances);
111 
112     // Adaptor attributes.
113     const FontProperties    & fontProperties() const throw();
114     FreetypeServerFont        & font() const throw();
features() const115     const grutils::GrFeatureParser * features() const { return mpFeatures; };
116 
117 private:
118     virtual void UniqueCacheInfo(ext_std::wstring &, bool &, bool &);
119 
120     FreetypeServerFont& mrFont;
121     FontProperties        maFontProperties;
122     const unsigned int    mnDpiX, mnDpiY;
123     const float           mfAscent,
124                     mfDescent,
125                     mfEmUnits;
126     grutils::GrFeatureParser * mpFeatures;
127     GlyphMetricMap maGlyphMetricMap;
128 };
129 
130 // Partial implementation of class GraphiteFontAdaptor.
131 //
fontProperties() const132 inline const FontProperties & GraphiteFontAdaptor::fontProperties() const throw() {
133     return maFontProperties;
134 }
135 
font() const136 inline FreetypeServerFont & GraphiteFontAdaptor::font() const throw() {
137     return mrFont;
138 }
139 #endif // not MFC
140 
141 // Partial implementation of class TextSourceAdaptor.
142 //
143 //inline const ImplLayoutArgs & TextSourceAdaptor::layoutArgs() const throw() {
144 //  return _layout_args;
145 //}
146 
147 
148 #endif // _SV_GRAPHITEADAPTORS_HXX
149