~ubuntu-branches/ubuntu/jaunty/plotutils/jaunty

« back to all changes in this revision

Viewing changes to libplot/h_font.c

  • Committer: Bazaar Package Importer
  • Author(s): Floris Bruynooghe
  • Date: 2007-05-10 19:48:54 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20070510194854-mrr3lgwzpxd8hovo
Tags: 2.5-2
Upload to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* This file is part of the GNU plotutils package.  Copyright (C) 1995,
 
2
   1996, 1997, 1998, 1999, 2000, 2005, Free Software Foundation, Inc.
 
3
 
 
4
   The GNU plotutils package is free software.  You may redistribute it
 
5
   and/or modify it under the terms of the GNU General Public License as
 
6
   published by the Free Software foundation; either version 2, or (at your
 
7
   option) any later version.
 
8
 
 
9
   The GNU plotutils package is distributed in the hope that it will be
 
10
   useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
12
   General Public License for more details.
 
13
 
 
14
   You should have received a copy of the GNU General Public License along
 
15
   with the GNU plotutils package; see the file COPYING.  If not, write to
 
16
   the Free Software Foundation, Inc., 51 Franklin St., Fifth Floor,
 
17
   Boston, MA 02110-1301, USA. */
 
18
 
1
19
/* This file contains a low-level method for adjusting the font of an HP-GL
2
20
   or PCL device to agree with an HPGL or PCL Plotter's notion of what it
3
21
   should be, prior to plotting a label.  Note: The `PCL 5' output by any
37
55
 
38
56
/* NOTE: This code assumes that P1 and P2 have different x coordinates, and
39
57
   different y coordinates.  If that isn't the case, it'll divide by zero.
40
 
   So we check for that possibility in _h_paint_text_string() before
 
58
   So we check for that possibility in _pl_h_paint_text_string() before
41
59
   calling this function.  See comment in h_text.c. */
42
60
 
43
61
#include "sys-defines.h"
48
66
#define SHEAR (2.0/7.0)
49
67
 
50
68
void
51
 
#ifdef _HAVE_PROTOS
52
 
_h_set_font (S___(Plotter *_plotter))
53
 
#else
54
 
_h_set_font (S___(_plotter))
55
 
     S___(Plotter *_plotter;)
56
 
#endif
 
69
_pl_h_set_font (S___(Plotter *_plotter))
57
70
{
58
71
  bool font_changed = false;
59
72
  bool oblique;
64
77
  double base_native_len, up_native_len, tan_slant;
65
78
  
66
79
  /* sanity check, should be unnecessary */
67
 
  if (_plotter->drawstate->font_type == F_HERSHEY)
 
80
  if (_plotter->drawstate->font_type == PL_F_HERSHEY)
68
81
    return;
69
82
 
70
 
  if (_plotter->drawstate->font_type == F_STICK)
 
83
  if (_plotter->drawstate->font_type == PL_F_STICK)
71
84
    /* check whether obliquing of this font is called for */
72
85
    {
73
86
      int master_font_index;
74
87
 
75
88
      /* compute index of font in master table of fonts, in g_fontdb.c */
76
89
      master_font_index =
77
 
        (_stick_typeface_info[_plotter->drawstate->typeface_index].fonts)[_plotter->drawstate->font_index];
78
 
      oblique = _stick_font_info[master_font_index].obliquing;
 
90
        (_pl_g_stick_typeface_info[_plotter->drawstate->typeface_index].fonts)[_plotter->drawstate->font_index];
 
91
      oblique = _pl_g_stick_font_info[master_font_index].obliquing;
79
92
    }
80
93
  else
81
94
    oblique = false;
114
127
 
115
128
  /* emit command to select new font, if needed (see below) */
116
129
  if (_plotter->hpgl_version == 2)
117
 
    font_changed = _hpgl2_maybe_update_font (S___(_plotter));
 
130
    font_changed = _pl_h_hpgl2_maybe_update_font (S___(_plotter));
118
131
  else                          /* 0 or 1, i.e. generic HP-GL or HP7550A */
119
 
    font_changed = _hpgl_maybe_update_font (S___(_plotter));
 
132
    font_changed = _pl_h_hpgl_maybe_update_font (S___(_plotter));
120
133
 
121
134
  /* Compute image, in the device frame, of a so-called `up vector': a
122
135
     vector which in the user frame is perpendicular to the above `base'
246
259
   Return value indicates whether font was changed. */
247
260
 
248
261
bool
249
 
#ifdef _HAVE_PROTOS
250
 
_hpgl2_maybe_update_font (S___(Plotter *_plotter))
251
 
#else
252
 
_hpgl2_maybe_update_font (S___(_plotter))
253
 
     S___(Plotter *_plotter;)
254
 
#endif
 
262
_pl_h_hpgl2_maybe_update_font (S___(Plotter *_plotter))
255
263
{
256
264
  bool font_change = false;
257
265
  bool font_is_iso_latin_1;
265
273
 
266
274
  switch (_plotter->drawstate->font_type)
267
275
    {
268
 
    case F_PCL:
 
276
    case PL_F_PCL:
269
277
    default:
270
278
      /* compute index of font in master table of fonts, in g_fontdb.c */
271
279
      master_font_index =
272
 
        (_pcl_typeface_info[_plotter->drawstate->typeface_index].fonts)[_plotter->drawstate->font_index];
273
 
      
274
 
      /* #1: symbol set */
275
 
      symbol_set = _pcl_font_info[master_font_index].hpgl_symbol_set;
276
 
      /* #2: spacing */
277
 
      spacing = _pcl_font_info[master_font_index].hpgl_spacing;
278
 
      /* #3, #4 are pitch and height (we use defaults) */
279
 
      /* #5: posture */
280
 
      posture = _pcl_font_info[master_font_index].hpgl_posture;
281
 
      /* #6: stroke weight */
282
 
      stroke_weight = _pcl_font_info[master_font_index].hpgl_stroke_weight;
283
 
      /* #7: typeface */
284
 
      typeface = _pcl_font_info[master_font_index].pcl_typeface;  
285
 
      /* ISO-Latin-1 after reencoding (if any)? */
286
 
      font_is_iso_latin_1 = _pcl_font_info[master_font_index].iso8859_1;
287
 
      break;
288
 
    case F_POSTSCRIPT:
289
 
      /* compute index of font in master table of fonts, in g_fontdb.c */
290
 
      master_font_index =
291
 
        (_ps_typeface_info[_plotter->drawstate->typeface_index].fonts)[_plotter->drawstate->font_index];
292
 
      
293
 
      /* #1: symbol set */
294
 
      symbol_set = _ps_font_info[master_font_index].hpgl_symbol_set;
295
 
      /* #2: spacing */
296
 
      spacing = _ps_font_info[master_font_index].hpgl_spacing;
297
 
      /* #3, #4 are pitch and height (we use defaults) */
298
 
      /* #5: posture */
299
 
      posture = _ps_font_info[master_font_index].hpgl_posture;
300
 
      /* #6: stroke weight */
301
 
      stroke_weight = _ps_font_info[master_font_index].hpgl_stroke_weight;
302
 
      /* #7: typeface */
303
 
      typeface = _ps_font_info[master_font_index].pcl_typeface;  
304
 
      /* ISO-Latin-1 after reencoding (if any)? */
305
 
      font_is_iso_latin_1 = _ps_font_info[master_font_index].iso8859_1;
306
 
      break;
307
 
    case F_STICK:
308
 
      /* compute index of font in master table of fonts, in g_fontdb.c */
309
 
      master_font_index =
310
 
        (_stick_typeface_info[_plotter->drawstate->typeface_index].fonts)[_plotter->drawstate->font_index];
311
 
      
312
 
      /* #1: symbol set */
313
 
      symbol_set = _stick_font_info[master_font_index].hpgl_symbol_set;
314
 
      /* #2: spacing */
315
 
      spacing = _stick_font_info[master_font_index].hpgl_spacing;
316
 
      /* #3, #4 are pitch and height (we use defaults) */
317
 
      /* #5: posture */
318
 
      posture = _stick_font_info[master_font_index].hpgl_posture;
319
 
      /* #6: stroke weight */
320
 
      stroke_weight = _stick_font_info[master_font_index].hpgl_stroke_weight;
321
 
      /* #7: typeface */
322
 
      typeface = _stick_font_info[master_font_index].pcl_typeface;  
323
 
      /* ISO-Latin-1 after reencoding (if any)? */
324
 
      font_is_iso_latin_1 = _stick_font_info[master_font_index].iso8859_1;
 
280
        (_pl_g_pcl_typeface_info[_plotter->drawstate->typeface_index].fonts)[_plotter->drawstate->font_index];
 
281
      
 
282
      /* #1: symbol set */
 
283
      symbol_set = _pl_g_pcl_font_info[master_font_index].hpgl_symbol_set;
 
284
      /* #2: spacing */
 
285
      spacing = _pl_g_pcl_font_info[master_font_index].hpgl_spacing;
 
286
      /* #3, #4 are pitch and height (we use defaults) */
 
287
      /* #5: posture */
 
288
      posture = _pl_g_pcl_font_info[master_font_index].hpgl_posture;
 
289
      /* #6: stroke weight */
 
290
      stroke_weight = _pl_g_pcl_font_info[master_font_index].hpgl_stroke_weight;
 
291
      /* #7: typeface */
 
292
      typeface = _pl_g_pcl_font_info[master_font_index].pcl_typeface;  
 
293
      /* ISO-Latin-1 after reencoding (if any)? */
 
294
      font_is_iso_latin_1 = _pl_g_pcl_font_info[master_font_index].iso8859_1;
 
295
      break;
 
296
    case PL_F_POSTSCRIPT:
 
297
      /* compute index of font in master table of fonts, in g_fontdb.c */
 
298
      master_font_index =
 
299
        (_pl_g_ps_typeface_info[_plotter->drawstate->typeface_index].fonts)[_plotter->drawstate->font_index];
 
300
      
 
301
      /* #1: symbol set */
 
302
      symbol_set = _pl_g_ps_font_info[master_font_index].hpgl_symbol_set;
 
303
      /* #2: spacing */
 
304
      spacing = _pl_g_ps_font_info[master_font_index].hpgl_spacing;
 
305
      /* #3, #4 are pitch and height (we use defaults) */
 
306
      /* #5: posture */
 
307
      posture = _pl_g_ps_font_info[master_font_index].hpgl_posture;
 
308
      /* #6: stroke weight */
 
309
      stroke_weight = _pl_g_ps_font_info[master_font_index].hpgl_stroke_weight;
 
310
      /* #7: typeface */
 
311
      typeface = _pl_g_ps_font_info[master_font_index].pcl_typeface;  
 
312
      /* ISO-Latin-1 after reencoding (if any)? */
 
313
      font_is_iso_latin_1 = _pl_g_ps_font_info[master_font_index].iso8859_1;
 
314
      break;
 
315
    case PL_F_STICK:
 
316
      /* compute index of font in master table of fonts, in g_fontdb.c */
 
317
      master_font_index =
 
318
        (_pl_g_stick_typeface_info[_plotter->drawstate->typeface_index].fonts)[_plotter->drawstate->font_index];
 
319
      
 
320
      /* #1: symbol set */
 
321
      symbol_set = _pl_g_stick_font_info[master_font_index].hpgl_symbol_set;
 
322
      /* #2: spacing */
 
323
      spacing = _pl_g_stick_font_info[master_font_index].hpgl_spacing;
 
324
      /* #3, #4 are pitch and height (we use defaults) */
 
325
      /* #5: posture */
 
326
      posture = _pl_g_stick_font_info[master_font_index].hpgl_posture;
 
327
      /* #6: stroke weight */
 
328
      stroke_weight = _pl_g_stick_font_info[master_font_index].hpgl_stroke_weight;
 
329
      /* #7: typeface */
 
330
      typeface = _pl_g_stick_font_info[master_font_index].pcl_typeface;  
 
331
      /* ISO-Latin-1 after reencoding (if any)? */
 
332
      font_is_iso_latin_1 = _pl_g_stick_font_info[master_font_index].iso8859_1;
325
333
      break;
326
334
    }
327
335
  
334
342
  
335
343
  if (font_change)
336
344
    {
337
 
      if (spacing == FIXED_SPACING)
 
345
      if (spacing == HPGL2_FIXED_SPACING)
338
346
        /* fixed-width font */
339
347
        sprintf (_plotter->data->page->point, 
340
348
                 /* #4 (nominal point size) not needed but included anyway */
341
349
                 "SD1,%d,2,%d,3,%.3f,4,%.3f,5,%d,6,%d,7,%d;",
342
350
                 symbol_set, spacing, 
343
 
                 (double)NOMINAL_CHARS_PER_INCH, (double)NOMINAL_POINT_SIZE, 
 
351
                 (double)HPGL2_NOMINAL_CHARS_PER_INCH, (double)HPGL2_NOMINAL_POINT_SIZE, 
344
352
                 posture, stroke_weight, typeface);
345
353
      else
346
354
        /* variable-width font */
348
356
                 /* #3 (nominal chars per inch) not needed but incl'd anyway */
349
357
                 "SD1,%d,2,%d,3,%.3f,4,%.3f,5,%d,6,%d,7,%d;",
350
358
                 symbol_set, spacing, 
351
 
                 (double)NOMINAL_CHARS_PER_INCH, (double)NOMINAL_POINT_SIZE, 
 
359
                 (double)HPGL2_NOMINAL_CHARS_PER_INCH, (double)HPGL2_NOMINAL_POINT_SIZE, 
352
360
                 posture, stroke_weight, typeface);
353
361
      _update_buffer (_plotter->data->page);
354
362
 
359
367
         encoding.  We implement this by using two fonts: standard and
360
368
         alternative.  See h_text.c for the DFA that switches back and
361
369
         forth (if necessary) when the label is rendered. */
362
 
      if (_plotter->drawstate->font_type == F_PCL
 
370
      if (_plotter->drawstate->font_type == PL_F_PCL
363
371
          && font_is_iso_latin_1
364
372
          && symbol_set == PCL_ROMAN_8)
365
373
        {
366
 
          if (spacing == FIXED_SPACING)
 
374
          if (spacing == HPGL2_FIXED_SPACING)
367
375
            /* fixed-width font */
368
376
            sprintf (_plotter->data->page->point, 
369
377
                     /* #4 (nominal point size) not needed but included anyway */
370
378
                     "AD1,%d,2,%d,3,%.3f,4,%.3f,5,%d,6,%d,7,%d;",
371
379
                     PCL_ISO_8859_1, spacing, 
372
 
                     (double)NOMINAL_CHARS_PER_INCH, (double)NOMINAL_POINT_SIZE, 
 
380
                     (double)HPGL2_NOMINAL_CHARS_PER_INCH, (double)HPGL2_NOMINAL_POINT_SIZE, 
373
381
                     posture, stroke_weight, typeface);
374
382
          else
375
383
            /* variable-width font */
377
385
                    /* #3 (nominal chars per inch) not needed but included anyway */
378
386
                     "AD1,%d,2,%d,3,%.3f,4,%.3f,5,%d,6,%d,7,%d;",
379
387
                     PCL_ISO_8859_1, spacing, 
380
 
                     (double)NOMINAL_CHARS_PER_INCH, (double)NOMINAL_POINT_SIZE, 
 
388
                     (double)HPGL2_NOMINAL_CHARS_PER_INCH, (double)HPGL2_NOMINAL_POINT_SIZE, 
381
389
                     posture, stroke_weight, typeface);
382
390
          _update_buffer (_plotter->data->page);
383
391
        }
399
407
   pre-HP/GL-2 HP-GL devices had.)  */
400
408
 
401
409
bool
402
 
#ifdef _HAVE_PROTOS
403
 
_hpgl_maybe_update_font (S___(Plotter *_plotter))
404
 
#else
405
 
_hpgl_maybe_update_font (S___(_plotter))
406
 
     S___(Plotter *_plotter;)
407
 
#endif
 
410
_pl_h_hpgl_maybe_update_font (S___(Plotter *_plotter))
408
411
{
409
412
  bool font_change = false;
410
413
  int new_hpgl_charset_lower, new_hpgl_charset_upper, master_font_index;
411
414
 
412
415
  /* compute index of font in master table of fonts, in g_fontdb.c */
413
416
  master_font_index =
414
 
    (_stick_typeface_info[_plotter->drawstate->typeface_index].fonts)[_plotter->drawstate->font_index];
 
417
    (_pl_g_stick_typeface_info[_plotter->drawstate->typeface_index].fonts)[_plotter->drawstate->font_index];
415
418
  
416
419
  /* determine HP character set numbers (old style, pre-HP-GL/2) */
417
 
  new_hpgl_charset_lower = _stick_font_info[master_font_index].hpgl_charset_lower;
418
 
  new_hpgl_charset_upper = _stick_font_info[master_font_index].hpgl_charset_upper;
 
420
  new_hpgl_charset_lower = _pl_g_stick_font_info[master_font_index].hpgl_charset_lower;
 
421
  new_hpgl_charset_upper = _pl_g_stick_font_info[master_font_index].hpgl_charset_upper;
419
422
 
420
423
  /* using `CS', select charset for lower half of font */
421
424
  if (new_hpgl_charset_lower != _plotter->hpgl_charset_lower)