2009-01-13 16:34:26 +00:00
|
|
|
/*
|
|
|
|
* GRUB -- GRand Unified Bootloader
|
2010-01-01 20:32:30 +00:00
|
|
|
* Copyright (C) 2009,2010 Free Software Foundation, Inc.
|
2009-01-13 16:34:26 +00:00
|
|
|
*
|
|
|
|
* GRUB is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* GRUB is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
#include <grub/types.h>
|
2010-05-06 06:04:04 +00:00
|
|
|
#include <grub/misc.h>
|
|
|
|
#include <grub/emu/misc.h>
|
2009-01-13 16:34:26 +00:00
|
|
|
#include <grub/util/misc.h>
|
2010-03-24 21:33:00 +00:00
|
|
|
#include <grub/misc.h>
|
2009-11-25 23:10:02 +00:00
|
|
|
#include <grub/i18n.h>
|
2010-01-26 20:16:08 +00:00
|
|
|
#include <grub/fontformat.h>
|
2010-03-24 21:33:00 +00:00
|
|
|
#include <grub/font.h>
|
2010-03-29 00:06:40 +00:00
|
|
|
#include <grub/unicode.h>
|
2009-01-13 16:34:26 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2012-02-03 20:45:43 +00:00
|
|
|
|
2013-08-22 15:00:59 +00:00
|
|
|
#ifndef GRUB_BUILD
|
2012-02-03 20:45:43 +00:00
|
|
|
#define _GNU_SOURCE 1
|
|
|
|
#include <argp.h>
|
2013-08-22 15:00:59 +00:00
|
|
|
#endif
|
2012-02-03 20:45:43 +00:00
|
|
|
#include <assert.h>
|
2009-01-13 16:34:26 +00:00
|
|
|
|
2013-08-22 15:00:59 +00:00
|
|
|
#include <errno.h>
|
|
|
|
|
2009-01-13 16:34:26 +00:00
|
|
|
#include <ft2build.h>
|
|
|
|
#include FT_FREETYPE_H
|
2010-03-24 21:33:00 +00:00
|
|
|
#include FT_TRUETYPE_TAGS_H
|
|
|
|
#include FT_TRUETYPE_TABLES_H
|
2009-01-13 16:34:26 +00:00
|
|
|
#include <freetype/ftsynth.h>
|
|
|
|
|
2010-03-25 10:56:19 +00:00
|
|
|
#undef __FTERRORS_H__
|
|
|
|
#define FT_ERROR_START_LIST const char *ft_errmsgs[] = {
|
|
|
|
#define FT_ERRORDEF(e, v, s) [e] = s,
|
|
|
|
#define FT_ERROR_END_LIST };
|
|
|
|
#include FT_ERRORS_H
|
|
|
|
|
2013-08-22 15:00:59 +00:00
|
|
|
#ifndef GRUB_BUILD
|
2009-11-25 23:10:02 +00:00
|
|
|
#include "progname.h"
|
2013-08-22 15:00:59 +00:00
|
|
|
#endif
|
2009-11-25 23:10:02 +00:00
|
|
|
|
2009-01-13 16:34:26 +00:00
|
|
|
#define GRUB_FONT_DEFAULT_SIZE 16
|
|
|
|
|
|
|
|
#define GRUB_FONT_RANGE_BLOCK 1024
|
|
|
|
|
|
|
|
struct grub_glyph_info
|
|
|
|
{
|
|
|
|
struct grub_glyph_info *next;
|
|
|
|
grub_uint32_t char_code;
|
|
|
|
int width;
|
|
|
|
int height;
|
|
|
|
int x_ofs;
|
|
|
|
int y_ofs;
|
|
|
|
int device_width;
|
|
|
|
int bitmap_size;
|
2010-03-24 21:33:00 +00:00
|
|
|
grub_uint8_t *bitmap;
|
2009-01-13 16:34:26 +00:00
|
|
|
};
|
|
|
|
|
2010-01-10 23:33:57 +00:00
|
|
|
enum file_formats
|
|
|
|
{
|
2013-08-21 17:53:59 +00:00
|
|
|
PF2
|
2010-01-10 23:33:57 +00:00
|
|
|
};
|
|
|
|
|
2013-04-05 09:13:37 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
GRUB_FONT_FLAG_BOLD = 1,
|
|
|
|
GRUB_FONT_FLAG_NOBITMAP = 2,
|
|
|
|
GRUB_FONT_FLAG_NOHINTING = 4,
|
|
|
|
GRUB_FONT_FLAG_FORCEHINT = 8
|
|
|
|
};
|
2009-01-13 16:34:26 +00:00
|
|
|
|
|
|
|
struct grub_font_info
|
|
|
|
{
|
2012-02-10 12:31:43 +00:00
|
|
|
const char *name;
|
2009-01-13 16:34:26 +00:00
|
|
|
int style;
|
|
|
|
int desc;
|
2010-01-06 22:25:57 +00:00
|
|
|
int asce;
|
2009-01-13 16:34:26 +00:00
|
|
|
int size;
|
|
|
|
int max_width;
|
|
|
|
int max_height;
|
|
|
|
int min_y;
|
2010-01-06 22:25:57 +00:00
|
|
|
int max_y;
|
2009-01-13 16:34:26 +00:00
|
|
|
int flags;
|
|
|
|
int num_range;
|
|
|
|
grub_uint32_t *ranges;
|
2010-03-24 21:33:00 +00:00
|
|
|
struct grub_glyph_info *glyphs_unsorted;
|
|
|
|
struct grub_glyph_info *glyphs_sorted;
|
|
|
|
int num_glyphs;
|
2009-01-13 16:34:26 +00:00
|
|
|
};
|
|
|
|
|
2012-02-03 20:45:43 +00:00
|
|
|
static int font_verbosity;
|
2009-01-13 16:34:26 +00:00
|
|
|
|
2012-02-10 12:31:43 +00:00
|
|
|
static void
|
2009-01-13 16:34:26 +00:00
|
|
|
add_pixel (grub_uint8_t **data, int *mask, int not_blank)
|
|
|
|
{
|
|
|
|
if (*mask == 0)
|
|
|
|
{
|
|
|
|
(*data)++;
|
|
|
|
**data = 0;
|
|
|
|
*mask = 128;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (not_blank)
|
|
|
|
**data |= *mask;
|
|
|
|
|
|
|
|
*mask >>= 1;
|
|
|
|
}
|
|
|
|
|
2010-03-24 21:33:00 +00:00
|
|
|
static void
|
|
|
|
add_glyph (struct grub_font_info *font_info, FT_UInt glyph_idx, FT_Face face,
|
2010-03-29 01:13:59 +00:00
|
|
|
grub_uint32_t char_code, int nocut)
|
2009-01-13 16:34:26 +00:00
|
|
|
{
|
2010-03-24 21:33:00 +00:00
|
|
|
struct grub_glyph_info *glyph_info;
|
2009-01-13 16:34:26 +00:00
|
|
|
int width, height;
|
2010-03-29 01:13:59 +00:00
|
|
|
int cuttop, cutbottom, cutleft, cutright;
|
2009-01-13 16:34:26 +00:00
|
|
|
grub_uint8_t *data;
|
|
|
|
int mask, i, j, bitmap_size;
|
|
|
|
FT_GlyphSlot glyph;
|
|
|
|
int flag = FT_LOAD_RENDER | FT_LOAD_MONOCHROME;
|
2010-03-25 10:56:19 +00:00
|
|
|
FT_Error err;
|
2009-01-13 16:34:26 +00:00
|
|
|
|
|
|
|
if (font_info->flags & GRUB_FONT_FLAG_NOBITMAP)
|
|
|
|
flag |= FT_LOAD_NO_BITMAP;
|
|
|
|
|
|
|
|
if (font_info->flags & GRUB_FONT_FLAG_NOHINTING)
|
|
|
|
flag |= FT_LOAD_NO_HINTING;
|
|
|
|
else if (font_info->flags & GRUB_FONT_FLAG_FORCEHINT)
|
|
|
|
flag |= FT_LOAD_FORCE_AUTOHINT;
|
|
|
|
|
2010-03-25 10:56:19 +00:00
|
|
|
err = FT_Load_Glyph (face, glyph_idx, flag);
|
|
|
|
if (err)
|
2010-03-24 21:33:00 +00:00
|
|
|
{
|
2011-11-11 23:34:14 +00:00
|
|
|
printf (_("Freetype Error %d loading glyph 0x%x for U+0x%x%s"),
|
2010-03-29 00:06:40 +00:00
|
|
|
err, glyph_idx, char_code & GRUB_FONT_CODE_CHAR_MASK,
|
|
|
|
char_code & GRUB_FONT_CODE_RIGHT_JOINED
|
2012-03-06 13:11:10 +00:00
|
|
|
/* TRANSLATORS: These qualifiers are used for cursive typography,
|
|
|
|
mainly Arabic. Note that the terms refer to the visual position
|
|
|
|
and not logical order and if used in left-to-right script then
|
|
|
|
leftmost is initial but with right-to-left script like Arabic
|
|
|
|
rightmost is the initial. */
|
2011-11-11 23:34:14 +00:00
|
|
|
? ((char_code & GRUB_FONT_CODE_LEFT_JOINED) ? _(" (medial)"):
|
|
|
|
_(" (leftmost)"))
|
|
|
|
: ((char_code & GRUB_FONT_CODE_LEFT_JOINED) ? _(" (rightmost)"):
|
2010-03-29 00:06:40 +00:00
|
|
|
""));
|
|
|
|
|
|
|
|
if (err > 0 && err < (signed) ARRAY_SIZE (ft_errmsgs))
|
|
|
|
printf (": %s\n", ft_errmsgs[err]);
|
2010-03-25 10:56:19 +00:00
|
|
|
else
|
2010-03-29 00:06:40 +00:00
|
|
|
printf ("\n");
|
2010-03-24 21:33:00 +00:00
|
|
|
return;
|
|
|
|
}
|
2009-01-13 16:34:26 +00:00
|
|
|
|
|
|
|
glyph = face->glyph;
|
|
|
|
|
|
|
|
if (font_info->flags & GRUB_FONT_FLAG_BOLD)
|
|
|
|
FT_GlyphSlot_Embolden (glyph);
|
|
|
|
|
2010-01-07 15:37:53 +00:00
|
|
|
if (glyph->next)
|
|
|
|
printf ("%x\n", char_code);
|
|
|
|
|
2010-03-29 01:13:59 +00:00
|
|
|
if (nocut)
|
|
|
|
cuttop = cutbottom = cutleft = cutright = 0;
|
|
|
|
else
|
2009-01-13 16:34:26 +00:00
|
|
|
{
|
2010-03-29 01:13:59 +00:00
|
|
|
for (cuttop = 0; cuttop < glyph->bitmap.rows; cuttop++)
|
|
|
|
{
|
|
|
|
for (j = 0; j < glyph->bitmap.width; j++)
|
|
|
|
if (glyph->bitmap.buffer[j / 8 + cuttop * glyph->bitmap.pitch]
|
|
|
|
& (1 << (7 - (j & 7))))
|
|
|
|
break;
|
|
|
|
if (j != glyph->bitmap.width)
|
|
|
|
break;
|
|
|
|
}
|
2009-01-13 16:34:26 +00:00
|
|
|
|
2010-03-29 01:13:59 +00:00
|
|
|
for (cutbottom = glyph->bitmap.rows - 1; cutbottom >= 0; cutbottom--)
|
|
|
|
{
|
|
|
|
for (j = 0; j < glyph->bitmap.width; j++)
|
|
|
|
if (glyph->bitmap.buffer[j / 8 + cutbottom * glyph->bitmap.pitch]
|
|
|
|
& (1 << (7 - (j & 7))))
|
|
|
|
break;
|
|
|
|
if (j != glyph->bitmap.width)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
cutbottom = glyph->bitmap.rows - 1 - cutbottom;
|
|
|
|
if (cutbottom + cuttop >= glyph->bitmap.rows)
|
|
|
|
cutbottom = 0;
|
|
|
|
|
|
|
|
for (cutleft = 0; cutleft < glyph->bitmap.width; cutleft++)
|
|
|
|
{
|
|
|
|
for (j = 0; j < glyph->bitmap.rows; j++)
|
|
|
|
if (glyph->bitmap.buffer[cutleft / 8 + j * glyph->bitmap.pitch]
|
|
|
|
& (1 << (7 - (cutleft & 7))))
|
|
|
|
break;
|
|
|
|
if (j != glyph->bitmap.rows)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
for (cutright = glyph->bitmap.width - 1; cutright >= 0; cutright--)
|
|
|
|
{
|
|
|
|
for (j = 0; j < glyph->bitmap.rows; j++)
|
|
|
|
if (glyph->bitmap.buffer[cutright / 8 + j * glyph->bitmap.pitch]
|
|
|
|
& (1 << (7 - (cutright & 7))))
|
|
|
|
break;
|
|
|
|
if (j != glyph->bitmap.rows)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
cutright = glyph->bitmap.width - 1 - cutright;
|
|
|
|
if (cutright + cutleft >= glyph->bitmap.width)
|
|
|
|
cutright = 0;
|
|
|
|
}
|
2009-01-13 16:34:26 +00:00
|
|
|
|
2010-03-29 01:13:59 +00:00
|
|
|
width = glyph->bitmap.width - cutleft - cutright;
|
|
|
|
height = glyph->bitmap.rows - cutbottom - cuttop;
|
2009-01-13 16:34:26 +00:00
|
|
|
|
|
|
|
bitmap_size = ((width * height + 7) / 8);
|
2010-03-24 21:33:00 +00:00
|
|
|
glyph_info = xmalloc (sizeof (struct grub_glyph_info));
|
|
|
|
glyph_info->bitmap = xmalloc (bitmap_size);
|
2009-01-13 16:34:26 +00:00
|
|
|
glyph_info->bitmap_size = bitmap_size;
|
|
|
|
|
2010-03-24 21:33:00 +00:00
|
|
|
glyph_info->next = font_info->glyphs_unsorted;
|
|
|
|
font_info->glyphs_unsorted = glyph_info;
|
|
|
|
font_info->num_glyphs++;
|
2009-01-13 16:34:26 +00:00
|
|
|
|
|
|
|
glyph_info->char_code = char_code;
|
|
|
|
glyph_info->width = width;
|
|
|
|
glyph_info->height = height;
|
2010-03-29 01:13:59 +00:00
|
|
|
glyph_info->x_ofs = glyph->bitmap_left + cutleft;
|
|
|
|
glyph_info->y_ofs = glyph->bitmap_top - height - cuttop;
|
2009-01-13 16:34:26 +00:00
|
|
|
glyph_info->device_width = glyph->metrics.horiAdvance / 64;
|
|
|
|
|
|
|
|
if (width > font_info->max_width)
|
|
|
|
font_info->max_width = width;
|
|
|
|
|
|
|
|
if (height > font_info->max_height)
|
|
|
|
font_info->max_height = height;
|
|
|
|
|
2010-01-06 22:25:57 +00:00
|
|
|
if (glyph_info->y_ofs < font_info->min_y && glyph_info->y_ofs > -font_info->size)
|
2009-01-13 16:34:26 +00:00
|
|
|
font_info->min_y = glyph_info->y_ofs;
|
|
|
|
|
2010-01-06 22:25:57 +00:00
|
|
|
if (glyph_info->y_ofs + height > font_info->max_y)
|
|
|
|
font_info->max_y = glyph_info->y_ofs + height;
|
|
|
|
|
2009-01-13 16:34:26 +00:00
|
|
|
mask = 0;
|
|
|
|
data = &glyph_info->bitmap[0] - 1;
|
2010-03-29 01:13:59 +00:00
|
|
|
for (j = cuttop; j < height + cuttop; j++)
|
|
|
|
for (i = cutleft; i < width + cutleft; i++)
|
2009-01-13 16:34:26 +00:00
|
|
|
add_pixel (&data, &mask,
|
|
|
|
glyph->bitmap.buffer[i / 8 + j * glyph->bitmap.pitch] &
|
|
|
|
(1 << (7 - (i & 7))));
|
|
|
|
}
|
|
|
|
|
2010-03-24 21:33:00 +00:00
|
|
|
struct glyph_replace *subst_rightjoin, *subst_leftjoin, *subst_medijoin;
|
|
|
|
|
|
|
|
struct glyph_replace
|
|
|
|
{
|
|
|
|
struct glyph_replace *next;
|
|
|
|
grub_uint32_t from, to;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* TODO: sort glyph_replace and use binary search if necessary. */
|
|
|
|
static void
|
|
|
|
add_char (struct grub_font_info *font_info, FT_Face face,
|
2010-03-29 01:13:59 +00:00
|
|
|
grub_uint32_t char_code, int nocut)
|
2010-03-24 21:33:00 +00:00
|
|
|
{
|
|
|
|
FT_UInt glyph_idx;
|
|
|
|
struct glyph_replace *cur;
|
|
|
|
|
|
|
|
glyph_idx = FT_Get_Char_Index (face, char_code);
|
|
|
|
if (!glyph_idx)
|
|
|
|
return;
|
2010-03-29 01:13:59 +00:00
|
|
|
add_glyph (font_info, glyph_idx, face, char_code, nocut);
|
2010-03-24 21:33:00 +00:00
|
|
|
for (cur = subst_rightjoin; cur; cur = cur->next)
|
|
|
|
if (cur->from == glyph_idx)
|
|
|
|
{
|
|
|
|
add_glyph (font_info, cur->to, face,
|
2010-03-29 01:13:59 +00:00
|
|
|
char_code | GRUB_FONT_CODE_RIGHT_JOINED, nocut);
|
2010-03-24 21:33:00 +00:00
|
|
|
break;
|
|
|
|
}
|
2010-03-29 00:06:40 +00:00
|
|
|
if (!cur && char_code >= GRUB_UNICODE_ARABIC_START
|
|
|
|
&& char_code < GRUB_UNICODE_ARABIC_END)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = 0; grub_unicode_arabic_shapes[i].code; i++)
|
|
|
|
if (grub_unicode_arabic_shapes[i].code == char_code
|
|
|
|
&& grub_unicode_arabic_shapes[i].right_linked)
|
|
|
|
{
|
|
|
|
FT_UInt idx2;
|
|
|
|
idx2 = FT_Get_Char_Index (face, grub_unicode_arabic_shapes[i]
|
|
|
|
.right_linked);
|
|
|
|
if (idx2)
|
|
|
|
add_glyph (font_info, idx2, face,
|
2010-03-29 01:13:59 +00:00
|
|
|
char_code | GRUB_FONT_CODE_RIGHT_JOINED, nocut);
|
2010-03-29 00:06:40 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-03-24 21:33:00 +00:00
|
|
|
for (cur = subst_leftjoin; cur; cur = cur->next)
|
|
|
|
if (cur->from == glyph_idx)
|
|
|
|
{
|
|
|
|
add_glyph (font_info, cur->to, face,
|
2010-03-29 01:13:59 +00:00
|
|
|
char_code | GRUB_FONT_CODE_LEFT_JOINED, nocut);
|
2010-03-24 21:33:00 +00:00
|
|
|
break;
|
|
|
|
}
|
2010-03-29 00:06:40 +00:00
|
|
|
if (!cur && char_code >= GRUB_UNICODE_ARABIC_START
|
|
|
|
&& char_code < GRUB_UNICODE_ARABIC_END)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = 0; grub_unicode_arabic_shapes[i].code; i++)
|
|
|
|
if (grub_unicode_arabic_shapes[i].code == char_code
|
|
|
|
&& grub_unicode_arabic_shapes[i].left_linked)
|
|
|
|
{
|
|
|
|
FT_UInt idx2;
|
|
|
|
idx2 = FT_Get_Char_Index (face, grub_unicode_arabic_shapes[i]
|
|
|
|
.left_linked);
|
|
|
|
if (idx2)
|
|
|
|
add_glyph (font_info, idx2, face,
|
2010-03-29 01:13:59 +00:00
|
|
|
char_code | GRUB_FONT_CODE_LEFT_JOINED, nocut);
|
2010-03-29 00:06:40 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2010-03-24 21:33:00 +00:00
|
|
|
for (cur = subst_medijoin; cur; cur = cur->next)
|
|
|
|
if (cur->from == glyph_idx)
|
|
|
|
{
|
|
|
|
add_glyph (font_info, cur->to, face,
|
|
|
|
char_code | GRUB_FONT_CODE_LEFT_JOINED
|
2010-03-29 01:13:59 +00:00
|
|
|
| GRUB_FONT_CODE_RIGHT_JOINED, nocut);
|
2010-03-24 21:33:00 +00:00
|
|
|
break;
|
|
|
|
}
|
2010-03-29 00:06:40 +00:00
|
|
|
if (!cur && char_code >= GRUB_UNICODE_ARABIC_START
|
|
|
|
&& char_code < GRUB_UNICODE_ARABIC_END)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = 0; grub_unicode_arabic_shapes[i].code; i++)
|
|
|
|
if (grub_unicode_arabic_shapes[i].code == char_code
|
|
|
|
&& grub_unicode_arabic_shapes[i].both_linked)
|
|
|
|
{
|
|
|
|
FT_UInt idx2;
|
|
|
|
idx2 = FT_Get_Char_Index (face, grub_unicode_arabic_shapes[i]
|
|
|
|
.both_linked);
|
|
|
|
if (idx2)
|
|
|
|
add_glyph (font_info, idx2, face,
|
|
|
|
char_code | GRUB_FONT_CODE_LEFT_JOINED
|
2010-03-29 01:13:59 +00:00
|
|
|
| GRUB_FONT_CODE_RIGHT_JOINED, nocut);
|
2010-03-29 00:06:40 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2010-03-24 21:33:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct gsub_header
|
|
|
|
{
|
|
|
|
grub_uint32_t version;
|
|
|
|
grub_uint16_t scripts_off;
|
|
|
|
grub_uint16_t features_off;
|
|
|
|
grub_uint16_t lookups_off;
|
|
|
|
} __attribute__ ((packed));
|
|
|
|
|
|
|
|
struct gsub_features
|
|
|
|
{
|
|
|
|
grub_uint16_t count;
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
#define FEATURE_FINA 0x66696e61
|
|
|
|
#define FEATURE_INIT 0x696e6974
|
|
|
|
#define FEATURE_MEDI 0x6d656469
|
|
|
|
#define FEATURE_AALT 0x61616c74
|
2010-03-25 10:26:50 +00:00
|
|
|
#define FEATURE_LIGA 0x6c696761
|
|
|
|
#define FEATURE_RLIG 0x726c6967
|
2010-03-24 21:33:00 +00:00
|
|
|
grub_uint32_t feature_tag;
|
|
|
|
grub_uint16_t offset;
|
|
|
|
} __attribute__ ((packed)) features[0];
|
|
|
|
} __attribute__ ((packed));
|
|
|
|
|
|
|
|
struct gsub_feature
|
|
|
|
{
|
|
|
|
grub_uint16_t params;
|
|
|
|
grub_uint16_t lookupcount;
|
|
|
|
grub_uint16_t lookupindices[0];
|
|
|
|
} __attribute__ ((packed));
|
|
|
|
|
|
|
|
struct gsub_lookup_list
|
|
|
|
{
|
|
|
|
grub_uint16_t count;
|
|
|
|
grub_uint16_t offsets[0];
|
|
|
|
} __attribute__ ((packed));
|
|
|
|
|
|
|
|
struct gsub_lookup
|
|
|
|
{
|
|
|
|
grub_uint16_t type;
|
|
|
|
grub_uint16_t flag;
|
|
|
|
grub_uint16_t subtablecount;
|
|
|
|
grub_uint16_t subtables[0];
|
|
|
|
} __attribute__ ((packed));
|
|
|
|
|
|
|
|
struct gsub_substitution
|
|
|
|
{
|
|
|
|
grub_uint16_t type;
|
|
|
|
grub_uint16_t coverage_off;
|
|
|
|
union
|
|
|
|
{
|
|
|
|
grub_int16_t delta;
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
grub_int16_t count;
|
|
|
|
grub_uint16_t repl[0];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
} __attribute__ ((packed));
|
|
|
|
|
|
|
|
struct gsub_coverage_list
|
|
|
|
{
|
|
|
|
grub_uint16_t type;
|
|
|
|
grub_uint16_t count;
|
|
|
|
grub_uint16_t glyphs[0];
|
|
|
|
} __attribute__ ((packed));
|
|
|
|
|
|
|
|
struct gsub_coverage_ranges
|
|
|
|
{
|
|
|
|
grub_uint16_t type;
|
|
|
|
grub_uint16_t count;
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
grub_uint16_t start;
|
|
|
|
grub_uint16_t end;
|
|
|
|
grub_uint16_t start_index;
|
|
|
|
} __attribute__ ((packed)) ranges[0];
|
|
|
|
} __attribute__ ((packed));
|
|
|
|
|
|
|
|
#define GSUB_SINGLE_SUBSTITUTION 1
|
|
|
|
|
|
|
|
#define GSUB_SUBSTITUTION_DELTA 1
|
|
|
|
#define GSUB_SUBSTITUTION_MAP 2
|
|
|
|
|
|
|
|
#define GSUB_COVERAGE_LIST 1
|
|
|
|
#define GSUB_COVERAGE_RANGE 2
|
|
|
|
|
|
|
|
#define GSUB_RTL_CHAR 1
|
|
|
|
|
|
|
|
static void
|
|
|
|
add_subst (grub_uint32_t from, grub_uint32_t to, struct glyph_replace **target)
|
|
|
|
{
|
|
|
|
struct glyph_replace *new = xmalloc (sizeof (*new));
|
|
|
|
new->next = *target;
|
|
|
|
new->from = from;
|
|
|
|
new->to = to;
|
|
|
|
*target = new;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
process_cursive (struct gsub_feature *feature,
|
|
|
|
struct gsub_lookup_list *lookups,
|
|
|
|
grub_uint32_t feattag)
|
|
|
|
{
|
|
|
|
int j, k;
|
|
|
|
int i;
|
|
|
|
struct glyph_replace **target;
|
|
|
|
struct gsub_substitution *sub;
|
|
|
|
|
|
|
|
auto inline void subst (grub_uint32_t glyph);
|
|
|
|
void subst (grub_uint32_t glyph)
|
|
|
|
{
|
|
|
|
grub_uint16_t substtype;
|
|
|
|
substtype = grub_be_to_cpu16 (sub->type);
|
|
|
|
|
|
|
|
if (substtype == GSUB_SUBSTITUTION_DELTA)
|
|
|
|
add_subst (glyph, glyph + grub_be_to_cpu16 (sub->delta), target);
|
|
|
|
else if (i >= grub_be_to_cpu16 (sub->count))
|
2011-11-11 23:34:14 +00:00
|
|
|
printf (_("Out of range substitution (%d, %d)\n"), i,
|
2010-03-24 21:33:00 +00:00
|
|
|
grub_be_to_cpu16 (sub->count));
|
|
|
|
else
|
|
|
|
add_subst (glyph, grub_be_to_cpu16 (sub->repl[i++]), target);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (j = 0; j < grub_be_to_cpu16 (feature->lookupcount); j++)
|
|
|
|
{
|
|
|
|
int lookup_index = grub_be_to_cpu16 (feature->lookupindices[j]);
|
|
|
|
struct gsub_lookup *lookup;
|
|
|
|
if (lookup_index >= grub_be_to_cpu16 (lookups->count))
|
|
|
|
{
|
2012-03-10 12:19:46 +00:00
|
|
|
/* TRANSLATORS: "lookup" is taken directly from font specifications
|
|
|
|
which are formulated as "Under condition X replace LOOKUP with
|
|
|
|
SUBSTITUITION". "*/
|
2011-11-11 23:34:14 +00:00
|
|
|
printf (_("Out of range lookup: %d\n"), lookup_index);
|
2010-03-24 21:33:00 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
lookup = (struct gsub_lookup *)
|
|
|
|
((grub_uint8_t *) lookups
|
|
|
|
+ grub_be_to_cpu16 (lookups->offsets[lookup_index]));
|
|
|
|
if (grub_be_to_cpu16 (lookup->type) != GSUB_SINGLE_SUBSTITUTION)
|
|
|
|
{
|
2011-11-11 23:34:14 +00:00
|
|
|
printf (_("Unsupported substitution type: %d\n"),
|
2010-03-24 21:33:00 +00:00
|
|
|
grub_be_to_cpu16 (lookup->type));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (grub_be_to_cpu16 (lookup->flag) & ~GSUB_RTL_CHAR)
|
|
|
|
{
|
2011-11-11 23:34:14 +00:00
|
|
|
printf (_("Unsupported substitution flag: 0x%x\n"),
|
2010-03-24 21:33:00 +00:00
|
|
|
grub_be_to_cpu16 (lookup->flag));
|
|
|
|
}
|
|
|
|
switch (feattag)
|
|
|
|
{
|
|
|
|
case FEATURE_INIT:
|
|
|
|
if (grub_be_to_cpu16 (lookup->flag) & GSUB_RTL_CHAR)
|
|
|
|
target = &subst_leftjoin;
|
|
|
|
else
|
|
|
|
target = &subst_rightjoin;
|
|
|
|
break;
|
|
|
|
case FEATURE_FINA:
|
|
|
|
if (grub_be_to_cpu16 (lookup->flag) & GSUB_RTL_CHAR)
|
|
|
|
target = &subst_rightjoin;
|
|
|
|
else
|
|
|
|
target = &subst_leftjoin;
|
|
|
|
break;
|
|
|
|
case FEATURE_MEDI:
|
|
|
|
target = &subst_medijoin;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
for (k = 0; k < grub_be_to_cpu16 (lookup->subtablecount); k++)
|
|
|
|
{
|
|
|
|
sub = (struct gsub_substitution *)
|
|
|
|
((grub_uint8_t *) lookup + grub_be_to_cpu16 (lookup->subtables[k]));
|
|
|
|
grub_uint16_t substtype;
|
|
|
|
substtype = grub_be_to_cpu16 (sub->type);
|
|
|
|
if (substtype != GSUB_SUBSTITUTION_MAP
|
|
|
|
&& substtype != GSUB_SUBSTITUTION_DELTA)
|
|
|
|
{
|
2011-11-11 23:34:14 +00:00
|
|
|
printf (_("Unsupported substitution specification: %d\n"),
|
2010-03-24 21:33:00 +00:00
|
|
|
substtype);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
void *coverage = (grub_uint8_t *) sub
|
|
|
|
+ grub_be_to_cpu16 (sub->coverage_off);
|
|
|
|
grub_uint32_t covertype;
|
|
|
|
covertype = grub_be_to_cpu16 (*(grub_uint16_t * __attribute__ ((packed))) coverage);
|
|
|
|
i = 0;
|
|
|
|
if (covertype == GSUB_COVERAGE_LIST)
|
|
|
|
{
|
|
|
|
struct gsub_coverage_list *cover = coverage;
|
|
|
|
int l;
|
|
|
|
for (l = 0; l < grub_be_to_cpu16 (cover->count); l++)
|
|
|
|
subst (grub_be_to_cpu16 (cover->glyphs[l]));
|
|
|
|
}
|
|
|
|
else if (covertype == GSUB_COVERAGE_RANGE)
|
|
|
|
{
|
|
|
|
struct gsub_coverage_ranges *cover = coverage;
|
|
|
|
int l, m;
|
|
|
|
for (l = 0; l < grub_be_to_cpu16 (cover->count); l++)
|
|
|
|
for (m = grub_be_to_cpu16 (cover->ranges[l].start);
|
|
|
|
m <= grub_be_to_cpu16 (cover->ranges[l].end); m++)
|
|
|
|
subst (m);
|
|
|
|
}
|
|
|
|
else
|
2012-03-02 14:09:10 +00:00
|
|
|
/* TRANSLATORS: most font transformations apply only to
|
|
|
|
some glyphs. Those glyphs are described as "coverage".
|
|
|
|
There are 2 coverage specifications: list and range.
|
|
|
|
This warning is thrown when another coverage specification
|
|
|
|
is detected. */
|
2011-11-11 23:34:14 +00:00
|
|
|
printf (_("Unsupported coverage specification: %d\n"), covertype);
|
2010-03-24 21:33:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-10 12:31:43 +00:00
|
|
|
static void
|
2010-03-29 01:13:59 +00:00
|
|
|
add_font (struct grub_font_info *font_info, FT_Face face, int nocut)
|
2009-01-13 16:34:26 +00:00
|
|
|
{
|
2010-03-24 21:33:00 +00:00
|
|
|
struct gsub_header *gsub = NULL;
|
|
|
|
FT_ULong gsub_len = 0;
|
|
|
|
|
|
|
|
if (!FT_Load_Sfnt_Table (face, TTAG_GSUB, 0, NULL, &gsub_len))
|
|
|
|
{
|
|
|
|
gsub = xmalloc (gsub_len);
|
|
|
|
if (FT_Load_Sfnt_Table (face, TTAG_GSUB, 0, (void *) gsub, &gsub_len))
|
|
|
|
{
|
|
|
|
free (gsub);
|
|
|
|
gsub = NULL;
|
|
|
|
gsub_len = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (gsub)
|
|
|
|
{
|
|
|
|
struct gsub_features *features
|
|
|
|
= (struct gsub_features *) (((grub_uint8_t *) gsub)
|
|
|
|
+ grub_be_to_cpu16 (gsub->features_off));
|
|
|
|
struct gsub_lookup_list *lookups
|
|
|
|
= (struct gsub_lookup_list *) (((grub_uint8_t *) gsub)
|
|
|
|
+ grub_be_to_cpu16 (gsub->lookups_off));
|
|
|
|
int i;
|
|
|
|
int nfeatures = grub_be_to_cpu16 (features->count);
|
|
|
|
for (i = 0; i < nfeatures; i++)
|
|
|
|
{
|
|
|
|
struct gsub_feature *feature = (struct gsub_feature *)
|
|
|
|
((grub_uint8_t *) features
|
|
|
|
+ grub_be_to_cpu16 (features->features[i].offset));
|
|
|
|
grub_uint32_t feattag
|
|
|
|
= grub_be_to_cpu32 (features->features[i].feature_tag);
|
|
|
|
if (feature->params)
|
2012-02-08 18:26:01 +00:00
|
|
|
printf (_("WARNING: unsupported font feature parameters: %x\n"),
|
2010-03-24 21:33:00 +00:00
|
|
|
grub_be_to_cpu16 (feature->params));
|
|
|
|
switch (feattag)
|
|
|
|
{
|
|
|
|
/* Used for retrieving all possible variants. Useless in grub. */
|
|
|
|
case FEATURE_AALT:
|
|
|
|
break;
|
|
|
|
|
2010-03-25 10:26:50 +00:00
|
|
|
/* FIXME: Add ligature support. */
|
|
|
|
case FEATURE_LIGA:
|
|
|
|
case FEATURE_RLIG:
|
|
|
|
break;
|
|
|
|
|
2010-03-24 21:33:00 +00:00
|
|
|
/* Cursive form variants. */
|
|
|
|
case FEATURE_FINA:
|
|
|
|
case FEATURE_INIT:
|
|
|
|
case FEATURE_MEDI:
|
|
|
|
process_cursive (feature, lookups, feattag);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
char str[5];
|
|
|
|
int j;
|
|
|
|
memcpy (str, &features->features[i].feature_tag,
|
|
|
|
sizeof (features->features[i].feature_tag));
|
|
|
|
str[4] = 0;
|
|
|
|
for (j = 0; j < 4; j++)
|
|
|
|
if (!grub_isgraph (str[j]))
|
|
|
|
str[j] = '?';
|
2012-03-06 13:11:10 +00:00
|
|
|
/* TRANSLATORS: It's gsub feature, not gsub font. */
|
2012-02-08 18:26:01 +00:00
|
|
|
printf (_("Unknown gsub font feature 0x%x (%s)\n"),
|
|
|
|
feattag, str);
|
2010-03-24 21:33:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-13 16:34:26 +00:00
|
|
|
if (font_info->num_range)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
grub_uint32_t j;
|
|
|
|
|
|
|
|
for (i = 0; i < font_info->num_range; i++)
|
|
|
|
for (j = font_info->ranges[i * 2]; j <= font_info->ranges[i * 2 + 1];
|
|
|
|
j++)
|
2010-03-29 01:13:59 +00:00
|
|
|
add_char (font_info, face, j, nocut);
|
2009-01-13 16:34:26 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
grub_uint32_t char_code, glyph_index;
|
|
|
|
|
|
|
|
for (char_code = FT_Get_First_Char (face, &glyph_index);
|
|
|
|
glyph_index;
|
|
|
|
char_code = FT_Get_Next_Char (face, char_code, &glyph_index))
|
2010-03-29 01:13:59 +00:00
|
|
|
add_char (font_info, face, char_code, nocut);
|
2009-01-13 16:34:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-05 10:07:33 +00:00
|
|
|
static void
|
2012-02-10 12:31:43 +00:00
|
|
|
write_string_section (const char *name, const char *str,
|
|
|
|
int *offset, FILE *file,
|
2012-02-05 10:07:33 +00:00
|
|
|
const char *filename)
|
2009-01-13 16:34:26 +00:00
|
|
|
{
|
|
|
|
grub_uint32_t leng, leng_be32;
|
|
|
|
|
|
|
|
leng = strlen (str) + 1;
|
|
|
|
leng_be32 = grub_cpu_to_be32 (leng);
|
|
|
|
|
2012-02-05 10:07:33 +00:00
|
|
|
grub_util_write_image (name, 4, file, filename);
|
|
|
|
grub_util_write_image ((char *) &leng_be32, 4, file, filename);
|
|
|
|
grub_util_write_image (str, leng, file, filename);
|
2009-01-13 16:34:26 +00:00
|
|
|
|
|
|
|
*offset += 8 + leng;
|
|
|
|
}
|
|
|
|
|
2012-02-05 10:07:33 +00:00
|
|
|
static void
|
2012-02-10 12:31:43 +00:00
|
|
|
write_be16_section (const char *name, grub_uint16_t data, int* offset,
|
|
|
|
FILE *file, const char *filename)
|
2009-01-13 16:34:26 +00:00
|
|
|
{
|
|
|
|
grub_uint32_t leng;
|
|
|
|
|
|
|
|
leng = grub_cpu_to_be32 (2);
|
|
|
|
data = grub_cpu_to_be16 (data);
|
2012-02-05 10:07:33 +00:00
|
|
|
grub_util_write_image (name, 4, file, filename);
|
|
|
|
grub_util_write_image ((char *) &leng, 4, file, filename);
|
|
|
|
grub_util_write_image ((char *) &data, 2, file, filename);
|
2009-01-13 16:34:26 +00:00
|
|
|
|
|
|
|
*offset += 10;
|
|
|
|
}
|
|
|
|
|
2012-02-24 11:30:32 +00:00
|
|
|
#pragma GCC diagnostic ignored "-Wunsafe-loop-optimizations"
|
|
|
|
|
2012-02-10 12:31:43 +00:00
|
|
|
static void
|
2009-01-13 16:34:26 +00:00
|
|
|
print_glyphs (struct grub_font_info *font_info)
|
|
|
|
{
|
|
|
|
int num;
|
|
|
|
struct grub_glyph_info *glyph;
|
|
|
|
char line[512];
|
|
|
|
|
2010-03-24 21:33:00 +00:00
|
|
|
for (glyph = font_info->glyphs_sorted, num = 0; num < font_info->num_glyphs;
|
|
|
|
glyph++, num++)
|
2009-01-13 16:34:26 +00:00
|
|
|
{
|
|
|
|
int x, y, xmax, xmin, ymax, ymin;
|
|
|
|
grub_uint8_t *bitmap, mask;
|
|
|
|
|
2012-02-08 18:26:01 +00:00
|
|
|
printf ("\nGlyph #%d, U+%04x\n", num, glyph->char_code);
|
|
|
|
printf ("Width %d, Height %d, X offset %d, Y offset %d, Device width %d\n",
|
2009-01-13 16:34:26 +00:00
|
|
|
glyph->width, glyph->height, glyph->x_ofs, glyph->y_ofs,
|
|
|
|
glyph->device_width);
|
|
|
|
|
|
|
|
xmax = glyph->x_ofs + glyph->width;
|
|
|
|
if (xmax < glyph->device_width)
|
|
|
|
xmax = glyph->device_width;
|
|
|
|
|
|
|
|
xmin = glyph->x_ofs;
|
|
|
|
if (xmin > 0)
|
|
|
|
xmin = 0;
|
|
|
|
|
|
|
|
ymax = glyph->y_ofs + glyph->height;
|
2010-01-06 22:25:57 +00:00
|
|
|
if (ymax < font_info->asce)
|
|
|
|
ymax = font_info->asce;
|
2009-01-13 16:34:26 +00:00
|
|
|
|
|
|
|
ymin = glyph->y_ofs;
|
|
|
|
if (ymin > - font_info->desc)
|
|
|
|
ymin = - font_info->desc;
|
|
|
|
|
|
|
|
bitmap = glyph->bitmap;
|
|
|
|
mask = 0x80;
|
2012-02-24 11:30:32 +00:00
|
|
|
for (y = ymax - 1; y > ymin - 1; y--)
|
2009-01-13 16:34:26 +00:00
|
|
|
{
|
|
|
|
int line_pos;
|
|
|
|
|
|
|
|
line_pos = 0;
|
|
|
|
for (x = xmin; x < xmax; x++)
|
|
|
|
{
|
|
|
|
if ((x >= glyph->x_ofs) &&
|
|
|
|
(x < glyph->x_ofs + glyph->width) &&
|
|
|
|
(y >= glyph->y_ofs) &&
|
|
|
|
(y < glyph->y_ofs + glyph->height))
|
|
|
|
{
|
|
|
|
line[line_pos++] = (*bitmap & mask) ? '#' : '_';
|
|
|
|
mask >>= 1;
|
|
|
|
if (mask == 0)
|
|
|
|
{
|
|
|
|
mask = 0x80;
|
|
|
|
bitmap++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ((x >= 0) &&
|
|
|
|
(x < glyph->device_width) &&
|
|
|
|
(y >= - font_info->desc) &&
|
2010-01-06 22:25:57 +00:00
|
|
|
(y < font_info->asce))
|
2009-01-13 16:34:26 +00:00
|
|
|
{
|
|
|
|
line[line_pos++] = ((x == 0) || (y == 0)) ? '+' : '.';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
line[line_pos++] = '*';
|
|
|
|
}
|
|
|
|
line[line_pos] = 0;
|
|
|
|
printf ("%s\n", line);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-10 12:31:43 +00:00
|
|
|
static void
|
2010-01-10 23:33:57 +00:00
|
|
|
write_font_pf2 (struct grub_font_info *font_info, char *output_file)
|
2009-01-13 16:34:26 +00:00
|
|
|
{
|
|
|
|
FILE *file;
|
2011-01-12 11:49:16 +00:00
|
|
|
grub_uint32_t leng;
|
2013-08-14 08:56:55 +00:00
|
|
|
char style_name[20], *font_name, *ptr;
|
2010-03-24 21:33:00 +00:00
|
|
|
int offset;
|
|
|
|
struct grub_glyph_info *cur;
|
2009-01-13 16:34:26 +00:00
|
|
|
|
|
|
|
file = fopen (output_file, "wb");
|
|
|
|
if (! file)
|
2012-02-08 18:26:01 +00:00
|
|
|
grub_util_error (_("cannot write to `%s': %s"), output_file,
|
2012-02-05 10:07:33 +00:00
|
|
|
strerror (errno));
|
2009-01-13 16:34:26 +00:00
|
|
|
|
|
|
|
offset = 0;
|
|
|
|
|
|
|
|
leng = grub_cpu_to_be32 (4);
|
2010-01-26 20:16:08 +00:00
|
|
|
grub_util_write_image (FONT_FORMAT_SECTION_NAMES_FILE,
|
2012-02-05 10:07:33 +00:00
|
|
|
sizeof(FONT_FORMAT_SECTION_NAMES_FILE) - 1, file,
|
|
|
|
output_file);
|
|
|
|
grub_util_write_image ((char *) &leng, 4, file, output_file);
|
|
|
|
grub_util_write_image (FONT_FORMAT_PFF2_MAGIC, 4, file, output_file);
|
2009-01-13 16:34:26 +00:00
|
|
|
offset += 12;
|
|
|
|
|
|
|
|
if (! font_info->name)
|
|
|
|
font_info->name = "Unknown";
|
|
|
|
|
|
|
|
if (font_info->flags & GRUB_FONT_FLAG_BOLD)
|
|
|
|
font_info->style |= FT_STYLE_FLAG_BOLD;
|
|
|
|
|
|
|
|
style_name[0] = 0;
|
|
|
|
if (font_info->style & FT_STYLE_FLAG_BOLD)
|
|
|
|
strcpy (style_name, " Bold");
|
|
|
|
|
|
|
|
if (font_info->style & FT_STYLE_FLAG_ITALIC)
|
|
|
|
strcat (style_name, " Italic");
|
|
|
|
|
|
|
|
if (! style_name[0])
|
|
|
|
strcpy (style_name, " Regular");
|
|
|
|
|
2013-08-14 08:56:55 +00:00
|
|
|
font_name = xmalloc (strlen (font_info->name) + strlen (&style_name[1])
|
|
|
|
+ 3 + 20);
|
|
|
|
ptr = stpcpy (font_name, font_info->name);
|
|
|
|
*ptr++ = ' ';
|
|
|
|
ptr = stpcpy (ptr, &style_name[1]);
|
|
|
|
*ptr++ = ' ';
|
|
|
|
snprintf (ptr, 20, "%d", font_info->size);
|
2009-01-13 16:34:26 +00:00
|
|
|
|
2010-01-26 20:16:08 +00:00
|
|
|
write_string_section (FONT_FORMAT_SECTION_NAMES_FONT_NAME,
|
2012-02-05 10:07:33 +00:00
|
|
|
font_name, &offset, file, output_file);
|
2010-01-26 20:16:08 +00:00
|
|
|
write_string_section (FONT_FORMAT_SECTION_NAMES_FAMILY,
|
2012-02-05 10:07:33 +00:00
|
|
|
font_info->name, &offset, file, output_file);
|
2010-01-26 20:16:08 +00:00
|
|
|
write_string_section (FONT_FORMAT_SECTION_NAMES_WEIGHT,
|
2009-01-13 16:34:26 +00:00
|
|
|
(font_info->style & FT_STYLE_FLAG_BOLD) ?
|
|
|
|
"bold" : "normal",
|
2012-02-05 10:07:33 +00:00
|
|
|
&offset, file, output_file);
|
2010-01-26 20:16:08 +00:00
|
|
|
write_string_section (FONT_FORMAT_SECTION_NAMES_SLAN,
|
2009-01-13 16:34:26 +00:00
|
|
|
(font_info->style & FT_STYLE_FLAG_ITALIC) ?
|
|
|
|
"italic" : "normal",
|
2012-02-05 10:07:33 +00:00
|
|
|
&offset, file, output_file);
|
2009-01-13 16:34:26 +00:00
|
|
|
|
2010-01-26 20:16:08 +00:00
|
|
|
write_be16_section (FONT_FORMAT_SECTION_NAMES_POINT_SIZE,
|
2012-02-05 10:07:33 +00:00
|
|
|
font_info->size, &offset, file, output_file);
|
2010-01-26 20:16:08 +00:00
|
|
|
write_be16_section (FONT_FORMAT_SECTION_NAMES_MAX_CHAR_WIDTH,
|
2012-02-05 10:07:33 +00:00
|
|
|
font_info->max_width, &offset, file, output_file);
|
2010-01-26 20:16:08 +00:00
|
|
|
write_be16_section (FONT_FORMAT_SECTION_NAMES_MAX_CHAR_HEIGHT,
|
2012-02-05 10:07:33 +00:00
|
|
|
font_info->max_height, &offset, file, output_file);
|
2009-01-13 16:34:26 +00:00
|
|
|
|
|
|
|
if (! font_info->desc)
|
|
|
|
{
|
|
|
|
if (font_info->min_y >= 0)
|
|
|
|
font_info->desc = 1;
|
|
|
|
else
|
|
|
|
font_info->desc = - font_info->min_y;
|
|
|
|
}
|
|
|
|
|
2010-01-06 22:25:57 +00:00
|
|
|
if (! font_info->asce)
|
|
|
|
{
|
|
|
|
if (font_info->max_y <= 0)
|
|
|
|
font_info->asce = 1;
|
|
|
|
else
|
|
|
|
font_info->asce = font_info->max_y;
|
|
|
|
}
|
|
|
|
|
2010-01-26 20:16:08 +00:00
|
|
|
write_be16_section (FONT_FORMAT_SECTION_NAMES_ASCENT,
|
2012-02-05 10:07:33 +00:00
|
|
|
font_info->asce, &offset, file, output_file);
|
2010-01-26 20:16:08 +00:00
|
|
|
write_be16_section (FONT_FORMAT_SECTION_NAMES_DESCENT,
|
2012-02-05 10:07:33 +00:00
|
|
|
font_info->desc, &offset, file, output_file);
|
2009-01-13 16:34:26 +00:00
|
|
|
|
|
|
|
if (font_verbosity > 0)
|
|
|
|
{
|
|
|
|
printf ("Font name: %s\n", font_name);
|
|
|
|
printf ("Max width: %d\n", font_info->max_width);
|
|
|
|
printf ("Max height: %d\n", font_info->max_height);
|
2010-01-06 22:25:57 +00:00
|
|
|
printf ("Font ascent: %d\n", font_info->asce);
|
2009-01-13 16:34:26 +00:00
|
|
|
printf ("Font descent: %d\n", font_info->desc);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (font_verbosity > 0)
|
2010-03-24 21:33:00 +00:00
|
|
|
printf ("Number of glyph: %d\n", font_info->num_glyphs);
|
2009-01-13 16:34:26 +00:00
|
|
|
|
2010-03-24 21:33:00 +00:00
|
|
|
leng = grub_cpu_to_be32 (font_info->num_glyphs * 9);
|
2010-01-26 20:16:08 +00:00
|
|
|
grub_util_write_image (FONT_FORMAT_SECTION_NAMES_CHAR_INDEX,
|
|
|
|
sizeof(FONT_FORMAT_SECTION_NAMES_CHAR_INDEX) - 1,
|
2012-02-05 10:07:33 +00:00
|
|
|
file, output_file);
|
|
|
|
grub_util_write_image ((char *) &leng, 4, file, output_file);
|
2010-03-24 21:33:00 +00:00
|
|
|
offset += 8 + font_info->num_glyphs * 9 + 8;
|
2009-01-13 16:34:26 +00:00
|
|
|
|
2010-03-24 21:33:00 +00:00
|
|
|
for (cur = font_info->glyphs_sorted;
|
|
|
|
cur < font_info->glyphs_sorted + font_info->num_glyphs; cur++)
|
2009-01-13 16:34:26 +00:00
|
|
|
{
|
2011-01-12 11:49:16 +00:00
|
|
|
grub_uint32_t data32;
|
|
|
|
grub_uint8_t data8;
|
|
|
|
data32 = grub_cpu_to_be32 (cur->char_code);
|
2012-02-05 10:07:33 +00:00
|
|
|
grub_util_write_image ((char *) &data32, 4, file, output_file);
|
2011-01-12 11:49:16 +00:00
|
|
|
data8 = 0;
|
2012-02-05 10:07:33 +00:00
|
|
|
grub_util_write_image ((char *) &data8, 1, file, output_file);
|
2011-01-12 11:49:16 +00:00
|
|
|
data32 = grub_cpu_to_be32 (offset);
|
2012-02-05 10:07:33 +00:00
|
|
|
grub_util_write_image ((char *) &data32, 4, file, output_file);
|
2009-01-13 16:34:26 +00:00
|
|
|
offset += 10 + cur->bitmap_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
leng = 0xffffffff;
|
2010-01-26 20:16:08 +00:00
|
|
|
grub_util_write_image (FONT_FORMAT_SECTION_NAMES_DATA,
|
2012-02-05 10:07:33 +00:00
|
|
|
sizeof(FONT_FORMAT_SECTION_NAMES_DATA) - 1,
|
|
|
|
file, output_file);
|
|
|
|
grub_util_write_image ((char *) &leng, 4, file, output_file);
|
2009-01-13 16:34:26 +00:00
|
|
|
|
2010-03-24 21:33:00 +00:00
|
|
|
for (cur = font_info->glyphs_sorted;
|
|
|
|
cur < font_info->glyphs_sorted + font_info->num_glyphs; cur++)
|
2009-01-13 16:34:26 +00:00
|
|
|
{
|
2011-01-12 11:49:16 +00:00
|
|
|
grub_uint16_t data;
|
2009-01-13 16:34:26 +00:00
|
|
|
data = grub_cpu_to_be16 (cur->width);
|
2012-02-05 10:07:33 +00:00
|
|
|
grub_util_write_image ((char *) &data, 2, file, output_file);
|
2009-01-13 16:34:26 +00:00
|
|
|
data = grub_cpu_to_be16 (cur->height);
|
2012-02-05 10:07:33 +00:00
|
|
|
grub_util_write_image ((char *) &data, 2, file, output_file);
|
2009-01-13 16:34:26 +00:00
|
|
|
data = grub_cpu_to_be16 (cur->x_ofs);
|
2012-02-05 10:07:33 +00:00
|
|
|
grub_util_write_image ((char *) &data, 2, file, output_file);
|
2009-01-13 16:34:26 +00:00
|
|
|
data = grub_cpu_to_be16 (cur->y_ofs);
|
2012-02-05 10:07:33 +00:00
|
|
|
grub_util_write_image ((char *) &data, 2, file, output_file);
|
2009-01-13 16:34:26 +00:00
|
|
|
data = grub_cpu_to_be16 (cur->device_width);
|
2012-02-05 10:07:33 +00:00
|
|
|
grub_util_write_image ((char *) &data, 2, file, output_file);
|
|
|
|
grub_util_write_image ((char *) &cur->bitmap[0], cur->bitmap_size,
|
|
|
|
file, output_file);
|
2009-01-13 16:34:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fclose (file);
|
|
|
|
}
|
|
|
|
|
2013-08-22 15:00:59 +00:00
|
|
|
#ifndef GRUB_BUILD
|
2012-02-03 20:45:43 +00:00
|
|
|
static struct argp_option options[] = {
|
2012-02-05 10:07:33 +00:00
|
|
|
{"output", 'o', N_("FILE"), 0, N_("save output in FILE [required]"), 0},
|
2012-03-06 13:11:10 +00:00
|
|
|
/* TRANSLATORS: bitmaps are images like e.g. in JPEG. */
|
2012-03-02 14:09:10 +00:00
|
|
|
{"index", 'i', N_("NUM"), 0,
|
|
|
|
/* TRANSLATORS: some font files may have multiple faces (fonts).
|
|
|
|
This option is used to chose among them, the first face being '0'.
|
|
|
|
Rarely used. */
|
2012-03-10 12:16:41 +00:00
|
|
|
N_("select face index"), 0},
|
2012-03-06 13:11:10 +00:00
|
|
|
{"range", 'r', N_("FROM-TO[,FROM-TO]"), 0,
|
|
|
|
/* TRANSLATORS: It refers to the range of characters in font. */
|
|
|
|
N_("set font range"), 0},
|
|
|
|
{"name", 'n', N_("NAME"), 0,
|
|
|
|
/* TRANSLATORS: "family name" for font is just a generic name without suffix
|
|
|
|
like "Bold". */
|
|
|
|
N_("set font family name"), 0},
|
2012-02-08 18:26:01 +00:00
|
|
|
{"size", 's', N_("SIZE"), 0, N_("set font size"), 0},
|
2012-02-03 20:45:43 +00:00
|
|
|
{"desc", 'd', N_("NUM"), 0, N_("set font descent"), 0},
|
|
|
|
{"asce", 'c', N_("NUM"), 0, N_("set font ascent"), 0},
|
|
|
|
{"bold", 'b', 0, 0, N_("convert to bold font"), 0},
|
|
|
|
{"force-autohint", 'a', 0, 0, N_("force autohint"), 0},
|
|
|
|
{"no-hinting", 0x101, 0, 0, N_("disable hinting"), 0},
|
2012-03-02 14:09:10 +00:00
|
|
|
{"no-bitmap", 0x100, 0, 0,
|
|
|
|
/* TRANSLATORS: some fonts contain bitmap rendering for
|
|
|
|
some sizes. This option forces rerendering even if
|
|
|
|
pre-rendered bitmap is available.
|
|
|
|
*/
|
|
|
|
N_("ignore bitmap strikes when loading"), 0},
|
2012-02-03 20:45:43 +00:00
|
|
|
{"verbose", 'v', 0, 0, N_("print verbose messages."), 0},
|
|
|
|
{ 0, 0, 0, 0, 0, 0 }
|
|
|
|
};
|
2013-08-22 15:00:59 +00:00
|
|
|
#define my_argp_parse argp_parse
|
|
|
|
#define MY_ARGP_KEY_ARG ARGP_KEY_ARG
|
|
|
|
#define my_error_t error_t
|
|
|
|
#define MY_ARGP_ERR_UNKNOWN ARGP_ERR_UNKNOWN
|
2013-08-22 16:15:22 +00:00
|
|
|
#define my_argp_state argp_state
|
2013-08-22 15:00:59 +00:00
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
#define my_error_t int
|
|
|
|
#define MY_ARGP_ERR_UNKNOWN -1
|
|
|
|
#define MY_ARGP_KEY_ARG -1
|
|
|
|
#define my_argp_parse(a, argc, argv, b, c, st) my_argp_parse_real(argc, argv, st)
|
|
|
|
struct my_argp_state
|
|
|
|
{
|
|
|
|
void *input;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
2012-02-03 20:45:43 +00:00
|
|
|
|
|
|
|
struct arguments
|
2009-01-13 16:34:26 +00:00
|
|
|
{
|
|
|
|
struct grub_font_info font_info;
|
2012-02-03 20:45:43 +00:00
|
|
|
size_t nfiles;
|
|
|
|
size_t files_max;
|
|
|
|
char **files;
|
|
|
|
char *output_file;
|
|
|
|
int font_index;
|
|
|
|
int font_size;
|
|
|
|
enum file_formats file_format;
|
|
|
|
};
|
2009-01-13 16:34:26 +00:00
|
|
|
|
2013-08-22 16:15:22 +00:00
|
|
|
#ifdef GRUB_BUILD
|
|
|
|
|
2013-08-22 15:00:59 +00:00
|
|
|
static int
|
|
|
|
has_argument (int v)
|
|
|
|
{
|
|
|
|
return v =='o' || v == 'i' || v == 'r' || v == 'n' || v == 's'
|
|
|
|
|| v == 'd' || v == 'c';
|
|
|
|
}
|
|
|
|
|
2013-08-22 16:15:22 +00:00
|
|
|
#endif
|
|
|
|
|
2013-08-22 15:00:59 +00:00
|
|
|
static my_error_t
|
|
|
|
argp_parser (int key, char *arg, struct my_argp_state *state)
|
2012-02-03 20:45:43 +00:00
|
|
|
{
|
|
|
|
/* Get the input argument from argp_parse, which we
|
|
|
|
know is a pointer to our arguments structure. */
|
|
|
|
struct arguments *arguments = state->input;
|
2010-01-01 20:32:30 +00:00
|
|
|
|
2012-02-03 20:45:43 +00:00
|
|
|
switch (key)
|
2009-01-13 16:34:26 +00:00
|
|
|
{
|
2012-02-03 20:45:43 +00:00
|
|
|
case 'b':
|
|
|
|
arguments->font_info.flags |= GRUB_FONT_FLAG_BOLD;
|
|
|
|
break;
|
2009-01-13 16:34:26 +00:00
|
|
|
|
2012-02-03 20:45:43 +00:00
|
|
|
case 0x100:
|
|
|
|
arguments->font_info.flags |= GRUB_FONT_FLAG_NOBITMAP;
|
|
|
|
break;
|
2009-01-13 16:34:26 +00:00
|
|
|
|
2012-02-03 20:45:43 +00:00
|
|
|
case 0x101:
|
|
|
|
arguments->font_info.flags |= GRUB_FONT_FLAG_NOHINTING;
|
|
|
|
break;
|
2009-01-13 16:34:26 +00:00
|
|
|
|
2012-02-03 20:45:43 +00:00
|
|
|
case 'a':
|
|
|
|
arguments->font_info.flags |= GRUB_FONT_FLAG_FORCEHINT;
|
|
|
|
break;
|
2009-01-13 16:34:26 +00:00
|
|
|
|
2012-02-03 20:45:43 +00:00
|
|
|
case 'o':
|
|
|
|
arguments->output_file = xstrdup (arg);
|
|
|
|
break;
|
2009-01-13 16:34:26 +00:00
|
|
|
|
2012-02-03 20:45:43 +00:00
|
|
|
case 'n':
|
|
|
|
arguments->font_info.name = xstrdup (arg);
|
|
|
|
break;
|
2009-01-13 16:34:26 +00:00
|
|
|
|
2012-02-03 20:45:43 +00:00
|
|
|
case 'i':
|
|
|
|
arguments->font_index = strtoul (arg, NULL, 0);
|
|
|
|
break;
|
2009-01-13 16:34:26 +00:00
|
|
|
|
2012-02-03 20:45:43 +00:00
|
|
|
case 's':
|
|
|
|
arguments->font_size = strtoul (arg, NULL, 0);
|
|
|
|
break;
|
2009-01-13 16:34:26 +00:00
|
|
|
|
2012-02-03 20:45:43 +00:00
|
|
|
case 'r':
|
|
|
|
{
|
|
|
|
char *p = arg;
|
2009-01-13 16:34:26 +00:00
|
|
|
|
2012-02-03 20:45:43 +00:00
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
grub_uint32_t a, b;
|
|
|
|
|
|
|
|
a = strtoul (p, &p, 0);
|
|
|
|
if (*p != '-')
|
2012-03-06 13:11:10 +00:00
|
|
|
/* TRANSLATORS: It refers to the range of characters in font. */
|
2012-02-10 12:31:43 +00:00
|
|
|
grub_util_error ("%s", _("invalid font range"));
|
2012-02-03 20:45:43 +00:00
|
|
|
b = strtoul (p + 1, &p, 0);
|
|
|
|
if ((arguments->font_info.num_range
|
|
|
|
& (GRUB_FONT_RANGE_BLOCK - 1)) == 0)
|
|
|
|
arguments->font_info.ranges = xrealloc (arguments->font_info.ranges,
|
|
|
|
(arguments->font_info.num_range +
|
|
|
|
GRUB_FONT_RANGE_BLOCK) *
|
|
|
|
sizeof (grub_uint32_t) * 2);
|
|
|
|
|
|
|
|
arguments->font_info.ranges[arguments->font_info.num_range * 2] = a;
|
|
|
|
arguments->font_info.ranges[arguments->font_info.num_range * 2 + 1] = b;
|
|
|
|
arguments->font_info.num_range++;
|
|
|
|
|
|
|
|
if (*p)
|
|
|
|
{
|
|
|
|
if (*p != ',')
|
2012-02-10 12:31:43 +00:00
|
|
|
grub_util_error ("%s", _("invalid font range"));
|
|
|
|
p++;
|
2012-02-03 20:45:43 +00:00
|
|
|
}
|
|
|
|
else
|
2009-01-13 16:34:26 +00:00
|
|
|
break;
|
2012-02-03 20:45:43 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2009-01-13 16:34:26 +00:00
|
|
|
|
2012-02-03 20:45:43 +00:00
|
|
|
case 'd':
|
|
|
|
arguments->font_info.desc = strtoul (arg, NULL, 0);
|
|
|
|
break;
|
2009-01-13 16:34:26 +00:00
|
|
|
|
2012-12-10 10:45:00 +00:00
|
|
|
case 'c':
|
2012-02-03 20:45:43 +00:00
|
|
|
arguments->font_info.asce = strtoul (arg, NULL, 0);
|
|
|
|
break;
|
2010-01-06 22:25:57 +00:00
|
|
|
|
2012-02-03 20:45:43 +00:00
|
|
|
case 'v':
|
|
|
|
font_verbosity++;
|
|
|
|
break;
|
2009-01-13 16:34:26 +00:00
|
|
|
|
2013-08-22 15:00:59 +00:00
|
|
|
case MY_ARGP_KEY_ARG:
|
2012-02-03 20:45:43 +00:00
|
|
|
assert (arguments->nfiles < arguments->files_max);
|
|
|
|
arguments->files[arguments->nfiles++] = xstrdup(arg);
|
|
|
|
break;
|
2010-01-10 23:33:57 +00:00
|
|
|
|
2012-02-03 20:45:43 +00:00
|
|
|
default:
|
2013-08-22 15:00:59 +00:00
|
|
|
return MY_ARGP_ERR_UNKNOWN;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef GRUB_BUILD
|
|
|
|
|
|
|
|
/* We don't require host platform to have argp. In the same time configuring
|
|
|
|
gnulib for build would result in even worse mess. So we have our
|
|
|
|
minimalistic argp replacement just enough for build system. Most
|
|
|
|
argp features are omitted. */
|
|
|
|
|
|
|
|
static int
|
|
|
|
my_argp_parse_real (int argc, char **argv, void *st)
|
|
|
|
{
|
|
|
|
int curar;
|
|
|
|
struct my_argp_state p;
|
|
|
|
|
|
|
|
p.input = st;
|
|
|
|
|
|
|
|
for (curar = 1; curar < argc; )
|
|
|
|
{
|
|
|
|
if (argv[curar][0] == '-')
|
|
|
|
{
|
|
|
|
if (has_argument (argv[curar][1])
|
|
|
|
&& curar + 1 >= argc)
|
|
|
|
return 1;
|
|
|
|
if (has_argument (argv[curar][1]))
|
|
|
|
{
|
|
|
|
if (argp_parser (argv[curar][1], argv[curar + 1], &p))
|
|
|
|
return 1;
|
|
|
|
curar += 2;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (argp_parser (argv[curar][1], NULL, &p))
|
|
|
|
return 1;
|
|
|
|
curar++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (argp_parser (MY_ARGP_KEY_ARG, argv[curar], &p))
|
|
|
|
return 1;
|
|
|
|
curar++;
|
2012-02-03 20:45:43 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2013-08-22 15:00:59 +00:00
|
|
|
#endif
|
2010-03-16 20:29:15 +00:00
|
|
|
|
2013-08-22 15:00:59 +00:00
|
|
|
#ifndef GRUB_BUILD
|
2012-02-03 20:45:43 +00:00
|
|
|
static struct argp argp = {
|
|
|
|
options, argp_parser, N_("[OPTIONS] FONT_FILES"),
|
|
|
|
N_("Convert common font file formats into PF2"),
|
|
|
|
NULL, NULL, NULL
|
|
|
|
};
|
2013-08-22 15:00:59 +00:00
|
|
|
#endif
|
2012-02-03 20:45:43 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
main (int argc, char *argv[])
|
|
|
|
{
|
|
|
|
FT_Library ft_lib;
|
|
|
|
struct arguments arguments;
|
|
|
|
|
2013-08-22 15:00:59 +00:00
|
|
|
#ifndef GRUB_BUILD
|
2012-02-03 20:45:43 +00:00
|
|
|
set_program_name (argv[0]);
|
2013-08-22 15:00:59 +00:00
|
|
|
#endif
|
2012-02-03 20:45:43 +00:00
|
|
|
|
|
|
|
grub_util_init_nls ();
|
|
|
|
|
|
|
|
memset (&arguments, 0, sizeof (struct arguments));
|
|
|
|
arguments.file_format = PF2;
|
|
|
|
arguments.files_max = argc + 1;
|
|
|
|
arguments.files = xmalloc ((arguments.files_max + 1)
|
|
|
|
* sizeof (arguments.files[0]));
|
|
|
|
memset (arguments.files, 0, (arguments.files_max + 1)
|
|
|
|
* sizeof (arguments.files[0]));
|
|
|
|
|
2013-08-22 15:00:59 +00:00
|
|
|
if (my_argp_parse (&argp, argc, argv, 0, 0, &arguments) != 0)
|
2012-02-03 20:45:43 +00:00
|
|
|
{
|
|
|
|
fprintf (stderr, "%s", _("Error in parsing command line arguments\n"));
|
|
|
|
exit(1);
|
2009-01-13 16:34:26 +00:00
|
|
|
}
|
|
|
|
|
2012-02-03 20:45:43 +00:00
|
|
|
if (! arguments.output_file)
|
2012-02-10 12:31:43 +00:00
|
|
|
grub_util_error ("%s", _("output file must be specified"));
|
2009-01-13 16:34:26 +00:00
|
|
|
|
|
|
|
if (FT_Init_FreeType (&ft_lib))
|
2012-02-10 12:31:43 +00:00
|
|
|
grub_util_error ("%s", _("FT_Init_FreeType fails"));
|
2009-01-13 16:34:26 +00:00
|
|
|
|
2012-02-10 12:31:43 +00:00
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
for (i = 0; i < arguments.nfiles; i++)
|
|
|
|
{
|
|
|
|
FT_Face ft_face;
|
|
|
|
int size;
|
|
|
|
FT_Error err;
|
2011-01-03 13:16:42 +00:00
|
|
|
|
2012-02-10 12:31:43 +00:00
|
|
|
err = FT_New_Face (ft_lib, arguments.files[i],
|
|
|
|
arguments.font_index, &ft_face);
|
|
|
|
if (err)
|
|
|
|
{
|
2013-08-14 08:56:55 +00:00
|
|
|
printf (_("can't open file %s, index %d: error %d"),
|
|
|
|
arguments.files[i],
|
|
|
|
arguments.font_index, err);
|
2012-02-10 12:31:43 +00:00
|
|
|
if (err > 0 && err < (signed) ARRAY_SIZE (ft_errmsgs))
|
|
|
|
printf (": %s\n", ft_errmsgs[err]);
|
|
|
|
else
|
|
|
|
printf ("\n");
|
2009-01-13 16:34:26 +00:00
|
|
|
|
2012-02-10 12:31:43 +00:00
|
|
|
continue;
|
|
|
|
}
|
2009-01-13 16:34:26 +00:00
|
|
|
|
2012-02-10 12:31:43 +00:00
|
|
|
if ((! arguments.font_info.name) && (ft_face->family_name))
|
|
|
|
arguments.font_info.name = xstrdup (ft_face->family_name);
|
2009-01-13 16:34:26 +00:00
|
|
|
|
2012-02-10 12:31:43 +00:00
|
|
|
size = arguments.font_size;
|
|
|
|
if (! size)
|
|
|
|
{
|
|
|
|
if ((ft_face->face_flags & FT_FACE_FLAG_SCALABLE) ||
|
|
|
|
(! ft_face->num_fixed_sizes))
|
|
|
|
size = GRUB_FONT_DEFAULT_SIZE;
|
|
|
|
else
|
|
|
|
size = ft_face->available_sizes[0].height;
|
|
|
|
}
|
2009-01-13 16:34:26 +00:00
|
|
|
|
2012-02-10 12:31:43 +00:00
|
|
|
arguments.font_info.style = ft_face->style_flags;
|
|
|
|
arguments.font_info.size = size;
|
|
|
|
|
|
|
|
if (FT_Set_Pixel_Sizes (ft_face, size, size))
|
|
|
|
grub_util_error (_("can't set %dx%d font size"),
|
|
|
|
size, size);
|
|
|
|
add_font (&arguments.font_info, ft_face, arguments.file_format != PF2);
|
|
|
|
FT_Done_Face (ft_face);
|
|
|
|
}
|
|
|
|
}
|
2009-01-13 16:34:26 +00:00
|
|
|
|
|
|
|
FT_Done_FreeType (ft_lib);
|
|
|
|
|
2010-03-24 21:33:00 +00:00
|
|
|
{
|
|
|
|
int counter[65537];
|
|
|
|
struct grub_glyph_info *tmp, *cur;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
memset (counter, 0, sizeof (counter));
|
|
|
|
|
2012-02-03 20:45:43 +00:00
|
|
|
for (cur = arguments.font_info.glyphs_unsorted; cur; cur = cur->next)
|
2010-03-24 21:33:00 +00:00
|
|
|
counter[(cur->char_code & 0xffff) + 1]++;
|
|
|
|
for (i = 0; i < 0x10000; i++)
|
|
|
|
counter[i+1] += counter[i];
|
2012-02-03 20:45:43 +00:00
|
|
|
tmp = xmalloc (arguments.font_info.num_glyphs
|
2010-03-24 21:33:00 +00:00
|
|
|
* sizeof (tmp[0]));
|
2012-02-03 20:45:43 +00:00
|
|
|
for (cur = arguments.font_info.glyphs_unsorted; cur; cur = cur->next)
|
2010-03-24 21:33:00 +00:00
|
|
|
tmp[counter[(cur->char_code & 0xffff)]++] = *cur;
|
|
|
|
|
|
|
|
memset (counter, 0, sizeof (counter));
|
|
|
|
|
2012-02-03 20:45:43 +00:00
|
|
|
for (cur = tmp; cur < tmp + arguments.font_info.num_glyphs; cur++)
|
2010-03-24 21:33:00 +00:00
|
|
|
counter[((cur->char_code & 0xffff0000) >> 16) + 1]++;
|
|
|
|
for (i = 0; i < 0x10000; i++)
|
|
|
|
counter[i+1] += counter[i];
|
2012-02-03 20:45:43 +00:00
|
|
|
arguments.font_info.glyphs_sorted = xmalloc (arguments.font_info.num_glyphs
|
|
|
|
* sizeof (arguments.font_info.glyphs_sorted[0]));
|
|
|
|
for (cur = tmp; cur < tmp + arguments.font_info.num_glyphs; cur++)
|
|
|
|
arguments.font_info.glyphs_sorted[counter[(cur->char_code & 0xffff0000)
|
|
|
|
>> 16]++] = *cur;
|
2010-03-24 21:33:00 +00:00
|
|
|
free (tmp);
|
|
|
|
}
|
|
|
|
|
2012-02-03 20:45:43 +00:00
|
|
|
switch (arguments.file_format)
|
2010-03-16 20:29:15 +00:00
|
|
|
{
|
|
|
|
case PF2:
|
2012-02-03 20:45:43 +00:00
|
|
|
write_font_pf2 (&arguments.font_info, arguments.output_file);
|
2010-03-16 20:29:15 +00:00
|
|
|
break;
|
|
|
|
}
|
2010-01-10 23:33:57 +00:00
|
|
|
|
|
|
|
if (font_verbosity > 1)
|
2012-02-03 20:45:43 +00:00
|
|
|
print_glyphs (&arguments.font_info);
|
|
|
|
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
for (i = 0; i < arguments.nfiles; i++)
|
|
|
|
free (arguments.files[i]);
|
|
|
|
}
|
2009-01-13 16:34:26 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|