bump product version to 4.1.6.2
[LibreOffice.git] / vcl / generic / glyphs / graphite_serverfont.cxx
blob42d98ad287d56a94d9c55316e34ccf2697851bd6
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 // Header files
23 // Platform
24 #include <i18nlangtag/languagetag.hxx>
25 #include <sallayout.hxx>
26 // Module
27 #include "gcach_ftyp.hxx"
28 #include "generic/glyphcache.hxx"
29 #include <graphite_features.hxx>
30 #include <graphite_serverfont.hxx>
32 float freetypeServerFontAdvance(const void* appFontHandle, gr_uint16 glyphId)
34 ServerFont * pServerFont =
35 const_cast<ServerFont*>
36 (reinterpret_cast<const ServerFont*>(appFontHandle));
37 if (pServerFont)
39 return static_cast<float>(pServerFont->GetGlyphMetric(glyphId).GetCharWidth());
41 return .0f;
45 // An implementation of the GraphiteLayout interface to enable Graphite enabled fonts to be used.
48 GraphiteServerFontLayout::GraphiteServerFontLayout(ServerFont& rServerFont) throw()
49 : ServerFontLayout(rServerFont),
50 maImpl(rServerFont.GetGraphiteFace()->face(),
51 rServerFont),
52 mpFeatures(NULL)
54 gr_font * pFont = rServerFont.GetGraphiteFace()->font(rServerFont.GetFontSelData().mnHeight);
55 if (!pFont)
57 pFont = gr_make_font_with_advance_fn(
58 // need to use mnHeight here, mfExactHeight can give wrong values
59 static_cast<float>(rServerFont.GetFontSelData().mnHeight),
60 &rServerFont,
61 freetypeServerFontAdvance,
62 rServerFont.GetGraphiteFace()->face());
63 rServerFont.GetGraphiteFace()->addFont(rServerFont.GetFontSelData().mnHeight, pFont);
65 maImpl.SetFont(pFont);
66 OString aLang("");
67 if (rServerFont.GetFontSelData().meLanguage != LANGUAGE_DONTKNOW)
69 aLang = OUStringToOString( LanguageTag( rServerFont.GetFontSelData().meLanguage ).getBcp47(),
70 RTL_TEXTENCODING_UTF8 );
72 OString name = OUStringToOString(
73 rServerFont.GetFontSelData().maTargetName, RTL_TEXTENCODING_UTF8 );
74 #ifdef DEBUG
75 printf("GraphiteServerFontLayout %lx %s size %d %f\n", (long unsigned int)this, name.getStr(),
76 rServerFont.GetMetricsFT().x_ppem,
77 rServerFont.GetFontSelData().mfExactHeight);
78 #endif
79 sal_Int32 nFeat = name.indexOf(grutils::GrFeatureParser::FEAT_PREFIX) + 1;
80 if (nFeat > 0)
82 OString aFeat = name.copy(nFeat, name.getLength() - nFeat);
83 mpFeatures = new grutils::GrFeatureParser(
84 rServerFont.GetGraphiteFace()->face(), aFeat, aLang);
85 #ifdef DEBUG
86 if (mpFeatures)
87 printf("GraphiteServerFontLayout %s/%s/%s %x language %d features %d errors\n",
88 OUStringToOString( rServerFont.GetFontSelData().GetFamilyName(),
89 RTL_TEXTENCODING_UTF8 ).getStr(),
90 OUStringToOString( rServerFont.GetFontSelData().maTargetName,
91 RTL_TEXTENCODING_UTF8 ).getStr(),
92 OUStringToOString( rServerFont.GetFontSelData().maSearchName,
93 RTL_TEXTENCODING_UTF8 ).getStr(),
94 rServerFont.GetFontSelData().meLanguage,
95 (int)mpFeatures->numFeatures(), mpFeatures->parseErrors());
96 #endif
98 else
100 mpFeatures = new grutils::GrFeatureParser(
101 rServerFont.GetGraphiteFace()->face(), aLang);
103 maImpl.SetFeatures(mpFeatures);
106 GraphiteServerFontLayout::~GraphiteServerFontLayout() throw()
108 delete mpFeatures;
109 mpFeatures = NULL;
112 bool GraphiteServerFontLayout::IsGraphiteEnabledFont(ServerFont& rServerFont)
114 if (rServerFont.GetGraphiteFace())
116 #ifdef DEBUG
117 printf("IsGraphiteEnabledFont\n");
118 #endif
119 return true;
121 return false;
124 sal_GlyphId GraphiteLayoutImpl::getKashidaGlyph(int & width)
126 int nKashidaIndex = mrServerFont.GetGlyphIndex( 0x0640 );
127 if( nKashidaIndex != 0 )
129 const GlyphMetric& rGM = mrServerFont.GetGlyphMetric( nKashidaIndex );
130 width = rGM.GetCharWidth();
132 else
134 width = 0;
136 return nKashidaIndex;
139 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */