2 #include "dl-dvi-fontdefinition.hh"
4 using DviLib::DviFontdefinition;
5 using DviLib::DviFontMap;
6 using DviLib::AbstractCharacter;
10 DviPainter::paint_bitmap (const unsigned char *data,
11 uint width, uint height,
12 int hoffset, int voffset)
15 gdk_pixbuf_new_from_data (data,
21 width * 4, // rowstride
23 NULL); // destroy_fn_data
25 uint x = dvi_to_pixels (current_frame->h);
26 uint y = dvi_to_pixels (current_frame->v);
28 gdk_pixbuf_render_to_drawable (pixbuf,
34 //y+(height - voffset),
43 DviPainter::set_char (int ch)
45 AbstractCharacter *character = current_frame->font->get_char (ch);
46 character->paint (* this);
48 int tfm_width = character->get_tfm_width ();
49 int at_size = current_frame->font->get_at_size ();
50 int dvi_width = tfm_to_dvi (tfm_width, at_size);
52 current_frame->h += dvi_width;
55 // typeset ch, don't move
57 DviPainter::put_char (int ch)
59 AbstractCharacter *character = current_frame->font->get_char (ch);
60 character->paint (* this);
64 // rule, move (height, width)
65 DviPainter::set_rule (int height,
68 int width_p = dvi_to_pixels_no_offset (width);
69 int height_p = dvi_to_pixels_no_offset (height);
70 int x = dvi_to_pixels (current_frame->h);
71 int y = dvi_to_pixels (current_frame->v);
74 cout << "BIRNAN\n" << endl;
77 gdk_draw_rectangle (pixmap, gc, TRUE,
79 width_p + 1, height_p + 1);
81 current_frame->h += width;
86 DviPainter::put_rule (int height,
89 cout << "w h " << width << " " << height << " " << endl;
91 int width_p = dvi_to_pixels_no_offset (width);
92 int height_p = dvi_to_pixels_no_offset (height);
93 int x = dvi_to_pixels (current_frame->h);
94 int y = dvi_to_pixels (current_frame->v);
96 cout << "EMFLE\n" << endl;
98 cout << "x y h w " << x << " " << y << " " << height_p << " "
101 gdk_draw_rectangle (pixmap, gc, TRUE,
103 width_p + 1, height_p + 1);
106 // push current context
108 DviFrame::copy (void)
110 DviFrame *frame = new DviFrame ();
112 frame->fontmap = this->fontmap;
114 frame->fontmap->ref();
121 frame->font = this->font;
128 DviFrame::~DviFrame()
131 this->fontmap->unref();
137 DviPainter::push (void)
139 DviFrame *new_frame = current_frame->copy();
140 new_frame->next = current_frame;
141 current_frame = new_frame;
142 if (current_frame->font)
143 cout << "push: there is a font" << endl;
145 cout << "push: there is not a font" << endl;
150 DviPainter::pop (void)
152 DviFrame *old_frame = current_frame;
154 // FIXME: dvi assumes that fonts survive pops
155 // FIXME: however, do they also survive the final pop of a vfchar?
157 current_frame = current_frame->next;
159 if (current_frame && current_frame->font)
160 cout << "pop: there is a font" << endl;
161 else if (current_frame)
162 cout << "pop: there is not font" << endl;
164 cout << "no current" << endl;
171 DviPainter::right (int len)
173 current_frame->h += len;
176 // move right len, set w = len
178 DviPainter::w (int len)
181 current_frame->w = len;
188 right (current_frame->w);
191 // move right len, set x = len
193 DviPainter::x (int len)
196 current_frame->x = len;
203 right (current_frame->x);
208 DviPainter::down (int len)
210 current_frame->v += len;
213 // move down len, set y = len
215 DviPainter::y (int len)
218 current_frame->y = len;
225 down (current_frame->y);
228 // move down len, set z = len
230 DviPainter::z (int len)
233 current_frame->z = len;
240 down (current_frame->z);
245 DviPainter::font_num (int font_num)
247 DviFontdefinition *fd = current_frame->fontmap->get_fontdefinition (font_num);
253 int dpi = (int)floor( 0.5 + 1.0 * base_dpi *
254 dvi_file->get_magnification() * fd->at_size /
255 ( 1000.0 * fd->design_size));
257 cout << fd->name << " design size: " << fd->design_size << " at size " << fd->at_size << endl;
259 if (current_frame->font)
260 current_frame->font->unref();
262 current_frame->font =
263 font_factory->create_font (fd->name, dpi, fd->at_size);
265 g_assert (current_frame->font);
266 cout << "there is now a font"<< endl;
271 // do something special
273 DviPainter::special (string spc)
275 cout << "warning: special " << spc << " " << "not handled" << endl;
279 DviPainter::tfm_to_dvi (uint tfm, int at_size)
281 // this is from gtkdvi:
282 int alpha, z, beta, b0, b1, b2, b3, r;
295 b0 = tfm & (0xFF << 24);
296 b1 = tfm & (0xFF << 16);
297 b2 = tfm & (0xFF << 8);
298 b3 = tfm & (0xFF << 0);
302 b1 = (tfm >> 16) & 255;
303 b2 = (tfm >> 8) & 255;
307 r = (((((b3 * z) / 256) + (b2 * z)) / 256) + (b1 * z))/beta;
314 r = (((b3 / 256 + b2) / 256) + b1) / beta;
318 if ((b0 > 0) != (tfm > 0))
319 cout << "b0: " << b0 << "tfm: " << tfm << endl;
326 DviPainter::DviPainter (GdkPixmap *pixmap_arg,
328 DviLib::DviFile *dvi_file_arg,
330 AbstractFontFactory *font_factory_arg)
332 pixmap = (GdkPixmap *)g_object_ref (pixmap_arg);
333 gc = (GdkGC *)g_object_ref (gc_arg);
334 dvi_file = dvi_file_arg;
335 base_dpi = base_dpi_arg;
336 font_factory = font_factory_arg;
341 current_frame = new DviFrame;
342 current_frame->h = 0;
343 current_frame->v = 0;
344 current_frame->w = 0;
345 current_frame->x = 0;
346 current_frame->y = 0;
347 current_frame->z = 0;
348 current_frame->fontmap = NULL;
349 current_frame->font = NULL;
352 scale = dvi_file->get_numerator() / 254000.0;
353 scale *= 1.0 * base_dpi / dvi_file->get_denominator ();
354 scale *= dvi_file->get_magnification () / 1000.0;
357 DviPainter::~DviPainter ()
359 g_object_unref (pixmap);
362 font_factory->unref();
363 while (current_frame)
368 DviPainter::fontmap (DviFontMap *fontmap)
372 if (current_frame->fontmap)
373 current_frame->fontmap->unref();
375 current_frame->fontmap = fontmap;