Changeset 06b8383 in mainline for uspace/lib/gfxfont/src/font.c
- Timestamp:
- 2020-08-18T11:32:59Z (5 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 20d0098
- Parents:
- d2100e2
- git-author:
- Jiri Svoboda <jiri@…> (2020-08-17 18:32:40)
- git-committer:
- Jiri Svoboda <jiri@…> (2020-08-18 11:32:59)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/gfxfont/src/font.c
rd2100e2 r06b8383 44 44 #include "../private/font.h" 45 45 #include "../private/glyph.h" 46 #include "../private/typeface.h" 46 47 47 48 /** Initialize font metrics structure. … … 57 58 } 58 59 59 /** Create font in graphics context. 60 * 61 * @param gc Graphic context 60 /** Initialize font properties structure. 61 * 62 * Font properties structure must always be initialized using this function 63 * first. 64 * 65 * @param props Font properties structure 66 */ 67 void gfx_font_props_init(gfx_font_props_t *props) 68 { 69 memset(props, 0, sizeof(gfx_font_props_t)); 70 } 71 72 /** Get font properties. 73 * 74 * @param finfo Font info 75 * @param props Place to store font properties 76 */ 77 void gfx_font_get_props(gfx_font_info_t *finfo, gfx_font_props_t *props) 78 { 79 *props = finfo->props; 80 } 81 82 /** Create font. 83 * 84 * @param tface Typeface 62 85 * @param metrics Font metrics 63 86 * @param rfont Place to store pointer to new font … … 67 90 * was lost 68 91 */ 69 errno_t gfx_font_create(gfx_context_t *gc, gfx_font_metrics_t *metrics, 70 gfx_font_t **rfont) 71 { 72 gfx_font_t *font; 92 errno_t gfx_font_create(gfx_typeface_t *tface, gfx_font_props_t *props, 93 gfx_font_metrics_t *metrics, gfx_font_t **rfont) 94 { 95 gfx_font_info_t *finfo = NULL; 96 gfx_font_t *font = NULL; 73 97 gfx_bitmap_params_t params; 74 98 errno_t rc; 75 99 100 finfo = calloc(1, sizeof(gfx_font_info_t)); 101 if (finfo == NULL) { 102 rc = ENOMEM; 103 goto error; 104 } 105 76 106 font = calloc(1, sizeof(gfx_font_t)); 77 if (font == NULL) 78 return ENOMEM; 79 80 font->gc = gc; 107 if (font == NULL) { 108 rc = ENOMEM; 109 goto error; 110 } 111 112 finfo->typeface = tface; 113 finfo->props = *props; 114 finfo->font = font; 115 font->typeface = tface; 81 116 82 117 rc = gfx_font_set_metrics(font, metrics); 83 118 if (rc != EOK) { 84 119 assert(rc == EINVAL); 85 free(font); 86 return rc; 120 goto error; 87 121 } 88 122 … … 91 125 params.rect = font->rect; 92 126 93 rc = gfx_bitmap_create(font->gc, ¶ms, NULL, &font->bitmap); 94 if (rc != EOK) { 95 free(font); 96 return rc; 97 } 127 rc = gfx_bitmap_create(tface->gc, ¶ms, NULL, &font->bitmap); 128 if (rc != EOK) 129 goto error; 98 130 99 131 font->metrics = *metrics; 100 132 list_initialize(&font->glyphs); 133 list_append(&finfo->lfonts, &tface->fonts); 101 134 *rfont = font; 102 135 return EOK; 103 } 104 105 /** Destroy font. 106 * 107 * @param font Font 108 */ 109 void gfx_font_destroy(gfx_font_t *font) 136 error: 137 if (finfo != NULL) 138 free(finfo); 139 if (font != NULL) 140 free(font); 141 return rc; 142 } 143 144 /** Open font. 145 * 146 * @param finfo Font info 147 * @param rfont Place to store pointer to open font 148 * @return EOK on success or an error code 149 */ 150 errno_t gfx_font_open(gfx_font_info_t *finfo, gfx_font_t **rfont) 151 { 152 if (finfo->font == NULL) { 153 /* 154 * We cannot load an absent font yet. 155 * This should not happen. 156 */ 157 assert(false); 158 return ENOTSUP; 159 } 160 161 *rfont = finfo->font; 162 return EOK; 163 } 164 165 /** Close font. 166 * 167 * @param font Font 168 */ 169 void gfx_font_close(gfx_font_t *font) 110 170 { 111 171 gfx_glyph_t *glyph; … … 232 292 params.rect.p1.y = height; 233 293 234 rc = gfx_bitmap_create(font-> gc, ¶ms, NULL, &nbitmap);294 rc = gfx_bitmap_create(font->typeface->gc, ¶ms, NULL, &nbitmap); 235 295 if (rc != EOK) 236 296 goto error;
Note:
See TracChangeset
for help on using the changeset viewer.