Changeset 120031a5 in mainline
- Timestamp:
- 2020-09-25T12:26:53Z (4 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 453f203b
- Parents:
- ea459d4
- git-author:
- Jiri Svoboda <jiri@…> (2020-09-24 17:26:44)
- git-committer:
- Jiri Svoboda <jiri@…> (2020-09-25 12:26:53)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/gfxfont/test/tpf.c
rea459d4 r120031a5 30 30 #include <gfx/font.h> 31 31 #include <gfx/glyph.h> 32 #include <gfx/glyph_bmp.h> 32 33 #include <gfx/typeface.h> 33 34 #include <pcut/pcut.h> 35 #include <str.h> 34 36 #include "../private/font.h" 35 37 #include "../private/typeface.h" … … 69 71 } testgc_bitmap_t; 70 72 73 enum { 74 test_font_size = 9, 75 test_font_flags = gff_bold_italic, 76 test_font_ascent = 4, 77 test_font_descent = 3, 78 test_font_leading = 2, 79 test_glyph_advance = 10 80 }; 81 82 static const char *test_glyph_pattern = "ff"; 83 71 84 /** Test saving typeface to and loading from TPF file */ 72 85 PCUT_TEST(save_load) … … 75 88 char *p; 76 89 gfx_font_props_t props; 90 gfx_font_props_t rprops; 77 91 gfx_font_metrics_t metrics; 92 gfx_font_metrics_t rmetrics; 78 93 gfx_glyph_metrics_t gmetrics; 94 gfx_glyph_metrics_t rgmetrics; 95 gfx_glyph_pattern_t *pat; 96 const char *str; 79 97 gfx_typeface_t *tface; 80 98 gfx_font_t *font; … … 82 100 gfx_context_t *gc; 83 101 gfx_glyph_t *glyph; 102 gfx_glyph_bmp_t *bmp; 103 int pix; 84 104 test_gc_t tgc; 85 105 errno_t rc; … … 91 111 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 92 112 113 rc = gfx_typeface_create(gc, &tface); 114 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 115 116 gfx_font_props_init(&props); 117 props.size = test_font_size; 118 props.flags = test_font_flags; 119 93 120 gfx_font_metrics_init(&metrics); 94 95 rc = gfx_typeface_create(gc, &tface); 96 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 97 98 gfx_font_props_init(&props); 99 gfx_font_metrics_init(&metrics); 121 metrics.ascent = test_font_ascent; 122 metrics.descent = test_font_descent; 123 metrics.leading = test_font_leading; 124 100 125 rc = gfx_font_create(tface, &props, &metrics, &font); 101 126 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 102 127 103 128 gfx_glyph_metrics_init(&gmetrics); 129 gmetrics.advance = test_glyph_advance; 130 104 131 rc = gfx_glyph_create(font, &gmetrics, &glyph); 105 132 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 133 134 rc = gfx_glyph_set_pattern(glyph, test_glyph_pattern); 135 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 136 137 rc = gfx_glyph_bmp_open(glyph, &bmp); 138 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 139 140 rc = gfx_glyph_bmp_setpix(bmp, 0, 0, 1); 141 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 142 143 rc = gfx_glyph_bmp_setpix(bmp, 1, 1, 1); 144 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 145 146 rc = gfx_glyph_bmp_save(bmp); 147 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 148 149 gfx_glyph_bmp_close(bmp); 106 150 107 151 rc = gfx_typeface_save(tface, fname); … … 118 162 PCUT_ASSERT_NOT_NULL(finfo); 119 163 164 gfx_font_get_props(finfo, &rprops); 165 PCUT_ASSERT_INT_EQUALS(props.size, rprops.size); 166 PCUT_ASSERT_INT_EQUALS(props.flags, rprops.flags); 167 120 168 rc = gfx_font_open(finfo, &font); 121 169 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 122 170 PCUT_ASSERT_NOT_NULL(font); 171 172 gfx_font_get_metrics(font, &rmetrics); 173 PCUT_ASSERT_INT_EQUALS(metrics.ascent, rmetrics.ascent); 174 PCUT_ASSERT_INT_EQUALS(metrics.descent, rmetrics.descent); 175 PCUT_ASSERT_INT_EQUALS(metrics.leading, rmetrics.leading); 123 176 124 177 glyph = gfx_font_first_glyph(font); 125 178 PCUT_ASSERT_NOT_NULL(glyph); 179 180 gfx_glyph_get_metrics(glyph, &rgmetrics); 181 PCUT_ASSERT_INT_EQUALS(gmetrics.advance, rgmetrics.advance); 182 183 pat = gfx_glyph_first_pattern(glyph); 184 str = gfx_glyph_pattern_str(pat); 185 PCUT_ASSERT_INT_EQUALS(0, str_cmp(test_glyph_pattern, str)); 186 187 rc = gfx_glyph_bmp_open(glyph, &bmp); 188 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 189 190 pix = gfx_glyph_bmp_getpix(bmp, 0, 0); 191 PCUT_ASSERT_INT_EQUALS(1, pix); 192 pix = gfx_glyph_bmp_getpix(bmp, 1, 1); 193 PCUT_ASSERT_INT_EQUALS(1, pix); 194 pix = gfx_glyph_bmp_getpix(bmp, 1, 0); 195 PCUT_ASSERT_INT_EQUALS(0, pix); 196 pix = gfx_glyph_bmp_getpix(bmp, 0, 1); 197 PCUT_ASSERT_INT_EQUALS(0, pix); 198 199 gfx_glyph_bmp_close(bmp); 126 200 127 201 gfx_typeface_destroy(tface);
Note:
See TracChangeset
for help on using the changeset viewer.