Deleted Added
full compact
vtfontcvt.c (267298) vtfontcvt.c (267301)
1/*-
2 * Copyright (c) 2009, 2014 The FreeBSD Foundation
3 * All rights reserved.
4 *
5 * This software was developed by Ed Schouten under sponsorship from the
6 * FreeBSD Foundation.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 14 unchanged lines hidden (view full) ---

23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 */
29
30#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2009, 2014 The FreeBSD Foundation
3 * All rights reserved.
4 *
5 * This software was developed by Ed Schouten under sponsorship from the
6 * FreeBSD Foundation.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 14 unchanged lines hidden (view full) ---

23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 */
29
30#include <sys/cdefs.h>
31__FBSDID("$FreeBSD: head/tools/tools/vt/fontcvt/fontcvt.c 267298 2014-06-09 20:49:13Z emaste $");
31__FBSDID("$FreeBSD: head/tools/tools/vt/fontcvt/fontcvt.c 267301 2014-06-09 20:52:35Z emaste $");
32
33#include <sys/types.h>
34#include <sys/fnv_hash.h>
35#include <sys/endian.h>
36#include <sys/param.h>
37#include <sys/queue.h>
38
39#include <assert.h>
32
33#include <sys/types.h>
34#include <sys/fnv_hash.h>
35#include <sys/endian.h>
36#include <sys/param.h>
37#include <sys/queue.h>
38
39#include <assert.h>
40#include <err.h>
40#include <stdint.h>
41#include <stdio.h>
42#include <stdlib.h>
43#include <string.h>
44#include <unistd.h>
45
46#define VFNT_MAPS 4
47#define VFNT_MAP_NORMAL 0
41#include <stdint.h>
42#include <stdio.h>
43#include <stdlib.h>
44#include <string.h>
45#include <unistd.h>
46
47#define VFNT_MAPS 4
48#define VFNT_MAP_NORMAL 0
49#define VFNT_MAP_NORMAL_RH 1
48#define VFNT_MAP_BOLD 2
50#define VFNT_MAP_BOLD 2
51#define VFNT_MAP_BOLD_RH 3
49
50static unsigned int width = 8, wbytes, height = 16;
51
52struct glyph {
53 TAILQ_ENTRY(glyph) g_list;
54 SLIST_ENTRY(glyph) g_hash;
55 uint8_t *g_data;
56 unsigned int g_index;

--- 39 unchanged lines hidden (view full) ---

96static int
97add_mapping(struct glyph *gl, unsigned int c, unsigned int map_idx)
98{
99 struct mapping *mp;
100 struct mapping_list *ml;
101
102 mapping_total++;
103
52
53static unsigned int width = 8, wbytes, height = 16;
54
55struct glyph {
56 TAILQ_ENTRY(glyph) g_list;
57 SLIST_ENTRY(glyph) g_hash;
58 uint8_t *g_data;
59 unsigned int g_index;

--- 39 unchanged lines hidden (view full) ---

99static int
100add_mapping(struct glyph *gl, unsigned int c, unsigned int map_idx)
101{
102 struct mapping *mp;
103 struct mapping_list *ml;
104
105 mapping_total++;
106
104 if (map_idx >= VFNT_MAP_BOLD) {
105 int found = 0;
106 unsigned normal_map_idx = map_idx - VFNT_MAP_BOLD;
107
108 TAILQ_FOREACH(mp, &maps[normal_map_idx], m_list) {
109 if (mp->m_char < c)
110 continue;
111 else if (mp->m_char > c)
112 break;
113 found = 1;
114
115 /*
116 * No mapping is needed if it's equal to the
117 * normal mapping.
118 */
119 if (mp->m_glyph == gl) {
120 mapping_dupe++;
121 return (0);
122 }
123 }
124
125 if (!found) {
126 fprintf(stderr,
127 "Character %u not in normal font!\n", c);
128 return (1);
129 }
130 }
131
132 mp = malloc(sizeof *mp);
133 mp->m_char = c;
134 mp->m_glyph = gl;
135 mp->m_length = 0;
136
137 ml = &maps[map_idx];
138 if (TAILQ_LAST(ml, mapping_list) != NULL &&
139 TAILQ_LAST(ml, mapping_list)->m_char >= c) {
140 errx(1, "Bad ordering at character %u\n", c);
141 return (1);
142 }
143 TAILQ_INSERT_TAIL(ml, mp, m_list);
144
145 map_count[map_idx]++;
146 mapping_unique++;
147
148 return (0);
149}
150
107 mp = malloc(sizeof *mp);
108 mp->m_char = c;
109 mp->m_glyph = gl;
110 mp->m_length = 0;
111
112 ml = &maps[map_idx];
113 if (TAILQ_LAST(ml, mapping_list) != NULL &&
114 TAILQ_LAST(ml, mapping_list)->m_char >= c) {
115 errx(1, "Bad ordering at character %u\n", c);
116 return (1);
117 }
118 TAILQ_INSERT_TAIL(ml, mp, m_list);
119
120 map_count[map_idx]++;
121 mapping_unique++;
122
123 return (0);
124}
125
126static int
127dedup_mapping(unsigned int map_idx)
128{
129 struct mapping *mp_bold, *mp_normal, *mp_temp;
130 unsigned normal_map_idx = map_idx - VFNT_MAP_BOLD;
131
132 assert(map_idx == VFNT_MAP_BOLD || map_idx == VFNT_MAP_BOLD_RH);
133 mp_normal = TAILQ_FIRST(&maps[normal_map_idx]);
134 TAILQ_FOREACH_SAFE(mp_bold, &maps[map_idx], m_list, mp_temp) {
135 while (mp_normal->m_char < mp_bold->m_char)
136 mp_normal = TAILQ_NEXT(mp_normal, m_list);
137 if (mp_bold->m_char != mp_normal->m_char) {
138 errx(1, "Character %u not in normal font!\n",
139 mp_bold->m_char);
140 return (1);
141 }
142 if (mp_bold->m_glyph != mp_normal->m_glyph)
143 continue;
144
145 /* No mapping is needed if it's equal to the normal mapping. */
146 TAILQ_REMOVE(&maps[map_idx], mp_bold, m_list);
147 free(mp_bold);
148 mapping_dupe++;
149 }
150 return (0);
151}
152
151static struct glyph *
152add_glyph(const uint8_t *bytes, unsigned int map_idx, int fallback)
153{
154 struct glyph *gl;
155 int hash;
156
157 glyph_total++;
158 glyph_count[map_idx]++;

--- 376 unchanged lines hidden (view full) ---

535 argv++;
536 if (argc == 2) {
537 if (parse_file(argv[0], VFNT_MAP_BOLD) != 0)
538 return (1);
539 argc--;
540 argv++;
541 }
542 number_glyphs();
153static struct glyph *
154add_glyph(const uint8_t *bytes, unsigned int map_idx, int fallback)
155{
156 struct glyph *gl;
157 int hash;
158
159 glyph_total++;
160 glyph_count[map_idx]++;

--- 376 unchanged lines hidden (view full) ---

537 argv++;
538 if (argc == 2) {
539 if (parse_file(argv[0], VFNT_MAP_BOLD) != 0)
540 return (1);
541 argc--;
542 argv++;
543 }
544 number_glyphs();
545 dedup_mapping(VFNT_MAP_BOLD);
546 dedup_mapping(VFNT_MAP_BOLD_RH);
543 fold_mappings(0);
544 fold_mappings(1);
545 fold_mappings(2);
546 fold_mappings(3);
547 if (write_fnt(argv[0]) != 0)
548 return (1);
549
550 if (verbose)
551 print_font_info();
552
553 return (0);
554}
547 fold_mappings(0);
548 fold_mappings(1);
549 fold_mappings(2);
550 fold_mappings(3);
551 if (write_fnt(argv[0]) != 0)
552 return (1);
553
554 if (verbose)
555 print_font_info();
556
557 return (0);
558}