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 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> |
40#include <err.h> |
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 |
50#define VFNT_MAP_BOLD 2 |
51#define VFNT_MAP_BOLD_RH 3 |
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 |
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 |
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); |
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} |