Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : // We need this to enable namespace support in libgrengine headers.
31 : : #define GR_NAMESPACE
32 : :
33 : : // Header files
34 : : //
35 : :
36 : : // Platform
37 : : #include <i18npool/mslangid.hxx>
38 : : #include <sallayout.hxx>
39 : : // Module
40 : : #include "gcach_ftyp.hxx"
41 : : #include "generic/glyphcache.hxx"
42 : : #include <graphite_features.hxx>
43 : : #include <graphite_serverfont.hxx>
44 : :
45 : 0 : float freetypeServerFontAdvance(const void* appFontHandle, gr_uint16 glyphId)
46 : : {
47 : : ServerFont * pServerFont =
48 : : const_cast<ServerFont*>
49 : 0 : (reinterpret_cast<const ServerFont*>(appFontHandle));
50 [ # # ]: 0 : if (pServerFont)
51 : : {
52 : 0 : return static_cast<float>(pServerFont->GetGlyphMetric(glyphId).GetCharWidth());
53 : : }
54 : 0 : return .0f;
55 : : }
56 : :
57 : : //
58 : : // An implementation of the GraphiteLayout interface to enable Graphite enabled fonts to be used.
59 : : //
60 : :
61 : 0 : GraphiteServerFontLayout::GraphiteServerFontLayout(ServerFont& rServerFont) throw()
62 : : : ServerFontLayout(rServerFont),
63 : 0 : maImpl(rServerFont.GetGraphiteFace()->face(),
64 : : rServerFont),
65 [ # # ]: 0 : mpFeatures(NULL)
66 : : {
67 [ # # ][ # # ]: 0 : gr_font * pFont = rServerFont.GetGraphiteFace()->font(rServerFont.GetFontSelData().mnHeight);
68 [ # # ]: 0 : if (!pFont)
69 : : {
70 : : pFont = gr_make_font_with_advance_fn(
71 : : // need to use mnHeight here, mfExactHeight can give wrong values
72 : 0 : static_cast<float>(rServerFont.GetFontSelData().mnHeight),
73 : : &rServerFont,
74 : : freetypeServerFontAdvance,
75 [ # # ][ # # ]: 0 : rServerFont.GetGraphiteFace()->face());
76 [ # # ][ # # ]: 0 : rServerFont.GetGraphiteFace()->addFont(rServerFont.GetFontSelData().mnHeight, pFont);
77 : : }
78 : 0 : maImpl.SetFont(pFont);
79 : 0 : rtl::OString aLang("");
80 [ # # ]: 0 : if (rServerFont.GetFontSelData().meLanguage != LANGUAGE_DONTKNOW)
81 : : {
82 : : aLang = MsLangId::convertLanguageToIsoByteString(
83 [ # # ]: 0 : rServerFont.GetFontSelData().meLanguage );
84 : : }
85 : : rtl::OString name = rtl::OUStringToOString(
86 [ # # ][ # # ]: 0 : rServerFont.GetFontSelData().maTargetName, RTL_TEXTENCODING_UTF8 );
87 : : #ifdef DEBUG
88 : : printf("GraphiteServerFontLayout %lx %s size %d %f\n", (long unsigned int)this, name.getStr(),
89 : : rServerFont.GetMetricsFT().x_ppem,
90 : : rServerFont.GetFontSelData().mfExactHeight);
91 : : #endif
92 : 0 : sal_Int32 nFeat = name.indexOf(grutils::GrFeatureParser::FEAT_PREFIX) + 1;
93 [ # # ]: 0 : if (nFeat > 0)
94 : : {
95 : 0 : rtl::OString aFeat = name.copy(nFeat, name.getLength() - nFeat);
96 : : mpFeatures = new grutils::GrFeatureParser(
97 [ # # ][ # # ]: 0 : rServerFont.GetGraphiteFace()->face(), aFeat, aLang);
[ # # ]
98 : : #ifdef DEBUG
99 : : if (mpFeatures)
100 : : printf("GraphiteServerFontLayout %s/%s/%s %x language %d features %d errors\n",
101 : : rtl::OUStringToOString( rServerFont.GetFontSelData().maName,
102 : : RTL_TEXTENCODING_UTF8 ).getStr(),
103 : : rtl::OUStringToOString( rServerFont.GetFontSelData().maTargetName,
104 : : RTL_TEXTENCODING_UTF8 ).getStr(),
105 : : rtl::OUStringToOString( rServerFont.GetFontSelData().maSearchName,
106 : : RTL_TEXTENCODING_UTF8 ).getStr(),
107 : : rServerFont.GetFontSelData().meLanguage,
108 : : (int)mpFeatures->numFeatures(), mpFeatures->parseErrors());
109 : : #endif
110 : : }
111 : : else
112 : : {
113 : : mpFeatures = new grutils::GrFeatureParser(
114 [ # # ][ # # ]: 0 : rServerFont.GetGraphiteFace()->face(), aLang);
[ # # ]
115 : : }
116 : 0 : maImpl.SetFeatures(mpFeatures);
117 : 0 : }
118 : :
119 : 0 : GraphiteServerFontLayout::~GraphiteServerFontLayout() throw()
120 : : {
121 [ # # ][ # # ]: 0 : delete mpFeatures;
122 : 0 : mpFeatures = NULL;
123 [ # # ]: 0 : }
124 : :
125 : 10272 : bool GraphiteServerFontLayout::IsGraphiteEnabledFont(ServerFont& rServerFont)
126 : : {
127 [ - + ]: 10272 : if (rServerFont.GetGraphiteFace())
128 : : {
129 : : #ifdef DEBUG
130 : : printf("IsGraphiteEnabledFont\n");
131 : : #endif
132 : 0 : return true;
133 : : }
134 : 10272 : return false;
135 : : }
136 : :
137 : 0 : sal_GlyphId GraphiteLayoutImpl::getKashidaGlyph(int & width)
138 : : {
139 : 0 : int nKashidaIndex = mrServerFont.GetGlyphIndex( 0x0640 );
140 [ # # ]: 0 : if( nKashidaIndex != 0 )
141 : : {
142 : 0 : const GlyphMetric& rGM = mrServerFont.GetGlyphMetric( nKashidaIndex );
143 : 0 : width = rGM.GetCharWidth();
144 : : }
145 : : else
146 : : {
147 : 0 : width = 0;
148 : : }
149 : 0 : return nKashidaIndex;
150 : : }
151 : :
152 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|