1 // Copyright (C) 2000-2007, Luca Padovani <padovani@sti.uniurb.it>.
2 //
3 // This file is part of GtkMathView, a flexible, high-quality rendering
4 // engine for MathML documents.
5 //
6 // GtkMathView is free software; you can redistribute it and/or modify it
7 // under the terms of the GNU Lesser General Public License as published
8 // by the Free Software Foundation; either version 3 of the License, or
9 // (at your option) any later version.
10 //
11 // GtkMathView is distributed in the hope that it will be useful, but
12 // WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public License
17 // along with this program. If not, see <http://www.gnu.org/licenses/>.
18
19 #include <config.h>
20
21 #include <cassert>
22
23 #include "AbstractLogger.hh"
24 #include "Configuration.hh"
25 #include "FormattingContext.hh"
26 #include "MathMLElement.hh"
27 #include "PS_TFMComputerModernMathGraphicDevice.hh"
28 #include "PS_TFMGlyphArea.hh"
29 #include "TFMFont.hh"
30 #include "TFM.hh"
31
32
PS_TFMComputerModernMathGraphicDevice(const SmartPtr<AbstractLogger> & l,const SmartPtr<Configuration> &)33 PS_TFMComputerModernMathGraphicDevice::PS_TFMComputerModernMathGraphicDevice(const SmartPtr<AbstractLogger>& l,
34 const SmartPtr<Configuration>&)
35 : TFMComputerModernMathGraphicDevice(l)
36 { }
37
~PS_TFMComputerModernMathGraphicDevice()38 PS_TFMComputerModernMathGraphicDevice::~PS_TFMComputerModernMathGraphicDevice()
39 { }
40
41 SmartPtr<PS_TFMComputerModernMathGraphicDevice>
create(const SmartPtr<AbstractLogger> & logger,const SmartPtr<Configuration> & conf)42 PS_TFMComputerModernMathGraphicDevice::create(const SmartPtr<AbstractLogger>& logger,
43 const SmartPtr<Configuration>& conf)
44 { return new PS_TFMComputerModernMathGraphicDevice(logger, conf); }
45
46 AreaRef
script(const class FormattingContext & context,const AreaRef & base,const AreaRef & subScript,const Length & subScriptShift,const AreaRef & superScript,const Length & superScriptShift) const47 PS_TFMComputerModernMathGraphicDevice::script(const class FormattingContext& context,
48 const AreaRef& base,
49 const AreaRef& subScript,
50 const Length& subScriptShift,
51 const AreaRef& superScript,
52 const Length& superScriptShift) const
53 {
54 AreaRef nucleus = base;
55 while (nucleus && is_a<const BinContainerArea>(nucleus))
56 nucleus = smart_cast<const BinContainerArea>(nucleus)->getChild();
57
58 AreaRef newSuperScript = superScript;
59 if (superScript)
60 if (SmartPtr<const PS_TFMGlyphArea> glyph = smart_cast<const PS_TFMGlyphArea>(nucleus))
61 {
62 const SmartPtr<TFMFont> font = glyph->getFont();
63 const SmartPtr<TFM> tfm = font->getTFM();
64 const Char8 index = glyph->getIndex();
65 const scaled ic = tfm->getGlyphItalicCorrection(index) * tfm->getScale(font->getSize());
66 if (ic != scaled::zero())
67 {
68
69 std::vector<AreaRef> c;
70 c.reserve(2);
71 c.push_back(getFactory()->horizontalSpace(ic));
72 c.push_back(superScript);
73 newSuperScript = getFactory()->horizontalArray(c);
74 }
75 }
76
77 return MathGraphicDevice::script(context, base,
78 subScript, subScriptShift,
79 newSuperScript, superScriptShift);
80 }
81
82 AreaRef
multiScripts(const class FormattingContext & context,const AreaRef & base,const std::vector<AreaRef> & subScripts,const std::vector<AreaRef> & preSubScripts,const Length & subScriptShift,const std::vector<AreaRef> & superScripts,const std::vector<AreaRef> & preSuperScripts,const Length & superScriptShift) const83 PS_TFMComputerModernMathGraphicDevice::multiScripts(const class FormattingContext& context,
84 const AreaRef& base,
85 const std::vector<AreaRef>& subScripts,
86 const std::vector<AreaRef>& preSubScripts,
87 const Length& subScriptShift,
88 const std::vector<AreaRef>& superScripts,
89 const std::vector<AreaRef>& preSuperScripts,
90 const Length& superScriptShift) const
91 {
92 return MathGraphicDevice::multiScripts(context, base,
93 subScripts, preSubScripts, subScriptShift,
94 superScripts, preSuperScripts, superScriptShift);
95 }
96