Branch libreoffice-5-0-4
[LibreOffice.git] / vcl / generic / glyphs / graphite_serverfont.cxx
blob84cdcf8ce044066143cd72dcda03b9be08940313
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
22 // Platform
23 #include <i18nlangtag/languagetag.hxx>
24 #include <sallayout.hxx>
25 // Module
26 #include "gcach_ftyp.hxx"
27 #include "generic/glyphcache.hxx"
28 #include <graphite_features.hxx>
29 #include <graphite_serverfont.hxx>
31 float freetypeServerFontAdvance(const void* appFontHandle, gr_uint16 glyphId)
33 ServerFont * pServerFont =
34 const_cast<ServerFont*>
35 (static_cast<const ServerFont*>(appFontHandle));
36 if (pServerFont)
38 return static_cast<float>(pServerFont->GetGlyphMetric(glyphId).GetCharWidth());
40 return .0f;
43 // An implementation of the GraphiteLayout interface to enable Graphite enabled fonts to be used.
45 GraphiteServerFontLayout::GraphiteServerFontLayout(ServerFont& rServerFont) throw()
46 : ServerFontLayout(rServerFont),
47 maImpl(rServerFont.GetGraphiteFace()->face(), rServerFont)
48 , mpFeatures(NULL)
49 , mpStr(NULL)
51 gr_font * pFont = rServerFont.GetGraphiteFace()->font(rServerFont.GetFontSelData().mnHeight, rServerFont.NeedsArtificialBold(), rServerFont.NeedsArtificialItalic());
52 if (!pFont)
54 pFont = gr_make_font_with_advance_fn(
55 // need to use mnHeight here, mfExactHeight can give wrong values
56 static_cast<float>(rServerFont.GetFontSelData().mnHeight),
57 &rServerFont,
58 freetypeServerFontAdvance,
59 rServerFont.GetGraphiteFace()->face());
60 rServerFont.GetGraphiteFace()->addFont(rServerFont.GetFontSelData().mnHeight, pFont, rServerFont.NeedsArtificialBold(), rServerFont.NeedsArtificialItalic());
62 maImpl.SetFont(pFont);
63 OString aLang("");
64 if (rServerFont.GetFontSelData().meLanguage != LANGUAGE_DONTKNOW)
66 aLang = OUStringToOString( LanguageTag( rServerFont.GetFontSelData().meLanguage ).getBcp47(),
67 RTL_TEXTENCODING_UTF8 );
69 OString name = OUStringToOString(
70 rServerFont.GetFontSelData().maTargetName, RTL_TEXTENCODING_UTF8 );
71 #ifdef DEBUG
72 printf("GraphiteServerFontLayout %lx %s size %d %f\n", (long unsigned int)this, name.getStr(),
73 rServerFont.GetMetricsFT().x_ppem,
74 rServerFont.GetFontSelData().mfExactHeight);
75 #endif
76 sal_Int32 nFeat = name.indexOf(grutils::GrFeatureParser::FEAT_PREFIX) + 1;
77 if (nFeat > 0)
79 OString aFeat = name.copy(nFeat, name.getLength() - nFeat);
80 mpFeatures = new grutils::GrFeatureParser(
81 rServerFont.GetGraphiteFace()->face(), aFeat, aLang);
82 #ifdef DEBUG
83 if (mpFeatures)
84 printf("GraphiteServerFontLayout %s/%s/%s %x language %d features %d errors\n",
85 OUStringToOString( rServerFont.GetFontSelData().GetFamilyName(),
86 RTL_TEXTENCODING_UTF8 ).getStr(),
87 OUStringToOString( rServerFont.GetFontSelData().maTargetName,
88 RTL_TEXTENCODING_UTF8 ).getStr(),
89 OUStringToOString( rServerFont.GetFontSelData().maSearchName,
90 RTL_TEXTENCODING_UTF8 ).getStr(),
91 rServerFont.GetFontSelData().meLanguage,
92 (int)mpFeatures->numFeatures(), mpFeatures->parseErrors());
93 #endif
95 else
97 mpFeatures = new grutils::GrFeatureParser(
98 rServerFont.GetGraphiteFace()->face(), aLang);
100 maImpl.SetFeatures(mpFeatures);
103 GraphiteServerFontLayout::~GraphiteServerFontLayout() throw()
105 delete mpFeatures;
106 mpFeatures = NULL;
109 bool GraphiteServerFontLayout::IsGraphiteEnabledFont(ServerFont& rServerFont)
111 if (rServerFont.GetGraphiteFace())
113 #ifdef DEBUG
114 printf("IsGraphiteEnabledFont\n");
115 #endif
116 return true;
118 return false;
121 sal_GlyphId GraphiteLayoutImpl::getKashidaGlyph(int & width)
123 int nKashidaIndex = mrServerFont.GetGlyphIndex( 0x0640 );
124 if( nKashidaIndex != 0 )
126 const GlyphMetric& rGM = mrServerFont.GetGlyphMetric( nKashidaIndex );
127 width = rGM.GetCharWidth();
129 else
131 width = 0;
133 return nKashidaIndex;
136 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */