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 "SVG_TFMComputerModernMathGraphicDevice.hh"
28 #include "SVG_WrapperArea.hh"
29 #include "SVG_TFMGlyphArea.hh"
30 #include "TFMFont.hh"
31 #include "TFM.hh"
32 
33 
SVG_TFMComputerModernMathGraphicDevice(const SmartPtr<AbstractLogger> & l,const SmartPtr<Configuration> &)34 SVG_TFMComputerModernMathGraphicDevice::SVG_TFMComputerModernMathGraphicDevice(const SmartPtr<AbstractLogger>& l,
35 									       const SmartPtr<Configuration>&)
36   : TFMComputerModernMathGraphicDevice(l)
37 { }
38 
~SVG_TFMComputerModernMathGraphicDevice()39 SVG_TFMComputerModernMathGraphicDevice::~SVG_TFMComputerModernMathGraphicDevice()
40 { }
41 
42 SmartPtr<SVG_TFMComputerModernMathGraphicDevice>
create(const SmartPtr<AbstractLogger> & logger,const SmartPtr<Configuration> & conf)43 SVG_TFMComputerModernMathGraphicDevice::create(const SmartPtr<AbstractLogger>& logger,
44 					       const SmartPtr<Configuration>& conf)
45 { return new SVG_TFMComputerModernMathGraphicDevice(logger, conf); }
46 
47 AreaRef
wrapper(const FormattingContext & ctxt,const AreaRef & area) const48 SVG_TFMComputerModernMathGraphicDevice::wrapper(const FormattingContext& ctxt, const AreaRef& area) const
49 { return SVG_WrapperArea::create(area, area->box(), ctxt.getMathMLElement()); }
50 
51 AreaRef
script(const class FormattingContext & context,const AreaRef & base,const AreaRef & subScript,const Length & subScriptShift,const AreaRef & superScript,const Length & superScriptShift) const52 SVG_TFMComputerModernMathGraphicDevice::script(const class FormattingContext& context,
53 					       const AreaRef& base,
54 					       const AreaRef& subScript, const Length& subScriptShift,
55 					       const AreaRef& superScript, const Length& superScriptShift) const
56 {
57   AreaRef nucleus = base;
58   while (nucleus && is_a<const BinContainerArea>(nucleus))
59     nucleus = smart_cast<const BinContainerArea>(nucleus)->getChild();
60 
61   AreaRef newSuperScript = superScript;
62   if (superScript)
63     if (SmartPtr<const SVG_TFMGlyphArea> glyph = smart_cast<const SVG_TFMGlyphArea>(nucleus))
64       {
65 	const SmartPtr<TFMFont> font = glyph->getFont();
66 	const SmartPtr<TFM> tfm = font->getTFM();
67 	const Char8 index = glyph->getIndex();
68 	const scaled ic = tfm->getGlyphItalicCorrection(index) * tfm->getScale(font->getSize());
69 	if (ic != scaled::zero())
70 	  {
71 	    std::vector<AreaRef> c;
72 	    c.reserve(2);
73 	    c.push_back(getFactory()->horizontalSpace(ic));
74 	    c.push_back(superScript);
75 	    newSuperScript = getFactory()->horizontalArray(c);
76 	  }
77       }
78 
79   return MathGraphicDevice::script(context, base,
80 				   subScript, subScriptShift,
81 				   newSuperScript, superScriptShift);
82 }
83 
84 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) const85 SVG_TFMComputerModernMathGraphicDevice::multiScripts(const class FormattingContext& context,
86 						     const AreaRef& base,
87 						     const std::vector<AreaRef>& subScripts,
88 						     const std::vector<AreaRef>& preSubScripts,
89 						     const Length& subScriptShift,
90 						     const std::vector<AreaRef>& superScripts,
91 						     const std::vector<AreaRef>& preSuperScripts,
92 						     const Length& superScriptShift) const
93 {
94   return MathGraphicDevice::multiScripts(context, base,
95 					 subScripts, preSubScripts, subScriptShift,
96 					 superScripts, preSuperScripts, superScriptShift);
97 }
98