/TeXmacs-1.0.7.11-src/src/Graphics/Bitmap_fonts/bitmap_font.cpp
C++ | 100 lines | 56 code | 23 blank | 21 comment | 4 complexity | bd21db06375ebdf3d561fa67645b0383 MD5 | raw file
Possible License(s): GPL-3.0, GPL-2.0, MPL-2.0-no-copyleft-exception
1
2/******************************************************************************
3* MODULE : bitmap_font.cpp
4* DESCRIPTION: bitmap fonts
5* COPYRIGHT : (C) 1999 Joris van der Hoeven
6*******************************************************************************
7* This software falls under the GNU general public license version 3 or later.
8* It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
9* in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
10******************************************************************************/
11
12#include "bitmap_font.hpp"
13
14RESOURCE_CODE(font_metric);
15RESOURCE_CODE(font_glyphs);
16
17/******************************************************************************
18* font_metrics
19******************************************************************************/
20
21font_metric_rep::font_metric_rep (string name):
22 rep<font_metric> (name), bad_font_metric (false) {}
23
24font_metric_rep::~font_metric_rep () {
25 FAILED ("not yet implemented"); }
26
27/******************************************************************************
28* Standard bitmap metrics
29******************************************************************************/
30
31static metric error_metric;
32
33struct std_font_metric_rep: public font_metric_rep {
34 int bc, ec;
35 metric* fnm;
36
37 std_font_metric_rep (string name, metric* fnm, int bc, int ec);
38 metric& get (int char_code);
39};
40
41std_font_metric_rep::std_font_metric_rep (
42 string name, metric* fnm2, int bc2, int ec2):
43 font_metric_rep (name), bc (bc2), ec (ec2), fnm (fnm2)
44{
45 error_metric->x1= error_metric->y1= 0;
46 error_metric->x2= error_metric->y2= 0;
47 error_metric->x3= error_metric->y3= 0;
48 error_metric->x4= error_metric->y4= 0;
49}
50
51metric&
52std_font_metric_rep::get (int c) {
53 if ((c<bc) || (c>ec)) return error_metric;
54 return fnm [c-bc];
55}
56
57font_metric
58std_font_metric (string name, metric* fnm, int bc, int ec) {
59 return make (font_metric, name,
60 tm_new<std_font_metric_rep> (name, fnm, bc, ec));
61}
62
63/******************************************************************************
64* font_glyphs
65******************************************************************************/
66
67font_glyphs_rep::font_glyphs_rep (string name):
68 rep<font_glyphs> (name), bad_font_glyphs (false) {}
69
70font_glyphs_rep::~font_glyphs_rep () {
71 FAILED ("not yet implemented"); }
72
73/******************************************************************************
74* Standard bitmap fonts
75******************************************************************************/
76
77static glyph error_glyph;
78
79struct std_font_glyphs_rep: public font_glyphs_rep {
80 int bc, ec;
81 glyph* fng; // definitions of the characters
82
83 std_font_glyphs_rep (string name, glyph* fng, int bc, int ec);
84 glyph& get (int char_code);
85};
86
87std_font_glyphs_rep::std_font_glyphs_rep (
88 string name, glyph* fng2, int bc2, int ec2):
89 font_glyphs_rep (name), bc (bc2), ec (ec2), fng (fng2) {}
90
91glyph&
92std_font_glyphs_rep::get (int c) {
93 if ((c<bc) || (c>ec)) return error_glyph;
94 return fng [c-bc];
95}
96
97font_glyphs
98std_font_glyphs (string name, glyph* fng, int bc, int ec) {
99 return make (font_glyphs, name, tm_new<std_font_glyphs_rep> (name, fng, bc, ec));
100}