1 // -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; c-brace-offset: 0; -*-
4 #include "TeXFontDefinition.h"
5 #include "dviRenderer.h"
8 # include "TeXFont_PFB.h"
10 #include "TeXFont_PK.h"
11 #include "TeXFont_TFM.h"
18 extern const int MFResolutions
[];
22 #define PK_MAGIC (PK_PRE << 8) + PK_ID
25 #define GF_MAGIC (GF_PRE << 8) + GF_ID
27 #define VF_ID_BYTE 202
28 #define VF_MAGIC (VF_PRE << 8) + VF_ID_BYTE
33 TeXFontDefinition::TeXFontDefinition(const QString
&nfontname
, double _displayResolution_in_dpi
, quint32 chk
, qint32 _scaled_size_in_DVI_units
,
34 class fontPool
*pool
, double _enlargement
)
37 kDebug(kvs::dvi
) << "TeXFontDefinition::TeXFontDefinition(...); fontname=" << nfontname
<< ", enlargement=" << _enlargement
;
40 enlargement
= _enlargement
;
44 displayResolution_in_dpi
= _displayResolution_in_dpi
;
46 flags
= TeXFontDefinition::FONT_IN_USE
;
49 scaled_size_in_DVI_units
= _scaled_size_in_DVI_units
;
53 // By default, this font contains only empty characters. After the
54 // font has been loaded, this function pointer will be replaced by
56 set_char_p
= &dviRenderer::set_empty_char
;
60 TeXFontDefinition::~TeXFontDefinition()
63 kDebug(kvs::dvi
) << "discarding font " << fontname
<< " at " << (int)(enlargement
* MFResolutions
[font_pool
->getMetafontMode()] + 0.5) << " dpi";
70 if (macrotable
!= 0) {
75 if (flags
& FONT_LOADED
) {
80 if (flags
& FONT_VIRTUAL
)
86 void TeXFontDefinition::fontNameReceiver(const QString
& fname
)
89 kDebug(kvs::dvi
) << "void TeXFontDefinition::fontNameReceiver( " << fname
<< " )";
92 flags
|= TeXFontDefinition::FONT_LOADED
;
96 fullEncodingName
.clear();
99 file
= fopen(QFile::encodeName(filename
), "r");
100 // Check if the file could be opened. If not, try to find the file
101 // in the DVI file's directory. If that works, modify the filename
102 // accordingly and go on.
104 QString
filename_test(font_pool
->getExtraSearchPath() + '/' + filename
);
105 file
= fopen( QFile::encodeName(filename_test
), "r");
107 kError(kvs::dvi
) << i18n("Cannot find font %1, file %2.", fontname
, filename
) << endl
;
110 filename
= filename_test
;
113 set_char_p
= &dviRenderer::set_char
;
114 int magic
= two(file
);
116 if (fname
.endsWith("pk"))
117 if (magic
== PK_MAGIC
) {
120 font
= new TeXFont_PK(this);
121 set_char_p
= &dviRenderer::set_char
;
122 if ((checksum
!= 0) && (checksum
!= font
->checksum
))
123 kWarning(kvs::dvi
) << i18n("Checksum mismatch for font file %1", filename
) ;
124 fontTypeName
= "TeX PK";
128 if (fname
.endsWith(".vf"))
129 if (magic
== VF_MAGIC
) {
131 set_char_p
= &dviRenderer::set_vf_char
;
132 fontTypeName
= i18n("TeX virtual");
136 if (fname
.endsWith(".tfm")) {
139 font
= new TeXFont_TFM(this);
140 set_char_p
= &dviRenderer::set_char
;
141 fontTypeName
= i18n("TeX Font Metric");
145 // None of these known types? Then it should be one of the font
146 // formats that are handled by the FreeType library
150 // Find the encoding for that font
151 const QString
&enc
= font_pool
->fontsByTeXName
.findEncoding(fontname
);
153 if (enc
.isEmpty() == false) {
155 kDebug(kvs::dvi
) << "Font " << fontname
<< " uses encoding " << enc
;
157 font
= new TeXFont_PFB(this, font_pool
->encodingPool
.findByName(enc
), font_pool
->fontsByTeXName
.findSlant(fontname
) );
160 kDebug(kvs::dvi
) << "Font " << fontname
<< " does not have an encoding.";
162 font
= new TeXFont_PFB(this);
165 set_char_p
= &dviRenderer::set_char
;
166 fontTypeName
= i18n("FreeType");
169 // If we don't have the FreeType library, we should never have
170 // reached this point. Complain, and leave this font blank
171 kError(kvs::dvi
) << i18n("Cannot recognize format for font file %1", filename
) << endl
;
176 void TeXFontDefinition::reset()
183 if (macrotable
!= 0) {
184 delete [] macrotable
;
188 if (flags
& FONT_LOADED
) {
193 if (flags
& FONT_VIRTUAL
)
198 flags
= TeXFontDefinition::FONT_IN_USE
;
199 set_char_p
= &dviRenderer::set_empty_char
;
203 void TeXFontDefinition::setDisplayResolution(double _displayResolution_in_dpi
)
205 displayResolution_in_dpi
= _displayResolution_in_dpi
;
207 font
->setDisplayResolution();
211 /** mark_as_used marks the font, and all the fonts it referrs to, as
212 used, i.e. their FONT_IN_USE-flag is set. */
214 void TeXFontDefinition::mark_as_used()
217 kDebug(kvs::dvi
) << "TeXFontDefinition::mark_as_used()";
220 if (flags
& TeXFontDefinition::FONT_IN_USE
)
223 flags
|= TeXFontDefinition::FONT_IN_USE
;
225 // For virtual fonts, also go through the list of referred fonts
226 if (flags
& TeXFontDefinition::FONT_VIRTUAL
) {
227 Q3IntDictIterator
<TeXFontDefinition
> it(vf_table
);
228 while( it
.current() ) {
229 it
.current()->flags
|= TeXFontDefinition::FONT_IN_USE
;
238 pos
= 0; /* address of first byte of macro */
239 end
= 0; /* address of last+1 byte */
240 dvi_advance_in_units_of_design_size_by_2e20
= 0; /* DVI units to move reference point */
247 if ((pos
!= 0L) && (free_me
== true))