1 // -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; c-brace-offset: 0; -*-
3 * Copyright (c) 1994 Paul Vojta. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 #include "dviRenderer.h"
31 #include "kvs_debug.h"
40 extern void oops(const QString
& message
);
43 *** VF font reading routines.
44 *** Public routine is read_index---because virtual characters are presumed
45 *** to be short, we read the whole virtual font in at once, instead of
46 *** faulting in characters as needed.
52 * These are parameters which determine whether macros are combined for
53 * storage allocation purposes. Small macros ( <= VF_PARM_1 bytes) are
54 * combined into chunks of size VF_PARM_2.
68 void TeXFontDefinition::read_VF_index()
71 kDebug(kvs::dvi
) << "font::read_VF_index()";
75 // available space for macros
76 unsigned char *avail
, *availend
;
78 flags
|= FONT_VIRTUAL
;
79 set_char_p
= &dviRenderer::set_vf_char
;
81 kDebug(kvs::dvi
) << "TeXFontDefinition::read_VF_index: reading VF pixel file " << filename
;
84 fseek(VF_file
, (long) one(VF_file
), 1); /* skip comment */
85 quint32
const file_checksum
= four(VF_file
);
87 if (file_checksum
&& checksum
&& file_checksum
!= checksum
)
88 kError(kvs::dvi
) << "Checksum mismatch dvi = " << checksum
<< "u, vf = " << file_checksum
<<
89 "u) in font file" << filename
<< endl
;
90 (void) four(VF_file
); /* skip design size */
94 while ((cmnd
= one(VF_file
)) >= FNTDEF1
&& cmnd
<= FNTDEF4
) {
95 int TeXnumber
= num(VF_file
, (int) cmnd
- FNTDEF1
+ 1);
96 quint32 checksum
= four(VF_file
);
97 quint32 scale
= four(VF_file
);
98 quint32 design
= four(VF_file
);
100 quint16 len
= one(VF_file
) + one(VF_file
); /* sequence point in the middle */
101 char *fontname
= new char[len
+ 1];
102 fread(fontname
, sizeof(char), len
, VF_file
);
103 fontname
[len
] = '\0';
106 kDebug(kvs::dvi
) << "Virtual font defines subfont \"" << fontname
<< "\" scale=" << scale
<< " design=" << design
;
109 // According to Knuth's documentation found in the web source code
110 // of the "vftovp" program (which seems to be the standard
111 // definition of virtual fonts), the "scale" is a fixed point
112 // number which describes extra enlargement that the virtual font
113 // imposes. One obtains the enlargement by dividing 2^20.
114 double enlargement_factor
= double(scale
)/(1<<20) * enlargement
;
116 // TeXFontDefinition *newfontp = font_pool->appendx(fontname, checksum, (quint32)(scaled_size_in_DVI_units*enlargement_factor), enlargement_factor);
117 TeXFontDefinition
*newfontp
= font_pool
->appendx(fontname
, checksum
, (quint32
)((double(scale
)/(1<<20))*scaled_size_in_DVI_units
), enlargement_factor
);
119 // Insert font in dictionary and make sure the dictionary is big
121 if (vf_table
.size()-2 <= vf_table
.count())
122 // Not quite optimal. The size of the dictionary should be a
123 // prime. I don't care.
124 vf_table
.resize(vf_table
.size()*2);
125 vf_table
.insert(TeXnumber
, newfontp
);
127 if (first_font
== NULL
)
128 first_font
= newfontp
;
131 // Prepare macro array.
132 macrotable
= new macro
[max_num_of_chars_in_font
];
133 if (macrotable
== 0) {
134 kError(kvs::dvi
) << "Could not allocate memory for a macro table.";
139 avail
= availend
= NULL
;
140 for (; cmnd
<= LONG_CHAR
; cmnd
= one(VF_file
)) {
146 if (cmnd
== LONG_CHAR
) { /* long form packet */
149 width
= four(VF_file
);
151 kError(kvs::dvi
) << "Virtual character" << cc
<< "in font"
152 << fontname
<< "ignored.";
153 fseek(VF_file
, (long) len
, 1);
156 } else { /* short form packet */
159 width
= num(VF_file
, 3);
163 m
->dvi_advance_in_units_of_design_size_by_2e20
= width
;
165 if (len
<= availend
- avail
) {
170 if (len
<= VF_PARM_1
) {
171 m
->pos
= avail
= new unsigned char [VF_PARM_2
];
172 availend
= avail
+ VF_PARM_2
;
175 m
->pos
= new unsigned char[len
];
177 fread((char *) m
->pos
, 1, len
, VF_file
);
178 m
->end
= m
->pos
+ len
;
182 oops(i18n("Wrong command byte found in VF macro list: %1", cmnd
));