~ubuntu-branches/ubuntu/wily/grub2/wily-proposed

« back to all changes in this revision

Viewing changes to font/font.c

  • Committer: Bazaar Package Importer
  • Author(s): Felix Zielcke, Robert Millan, Felix Zielcke
  • Date: 2010-01-26 19:26:25 UTC
  • mfrom: (1.13.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20100126192625-coq6czap2ofjollf
Tags: 1.98~20100126-1
* New Bazaar snapshot.
  - Includes mipsel-yeeloong port.

[ Robert Millan ]
* config.in: Lower priority of grub2/linux_cmdline_default.

[ Felix Zielcke ]
* Drop `CFLAGS=-O0' workaround on powerpc. Should be fixed correctly now.
* Ship grub-bin2h and grub-script-check in grub-common.
* Terminate NEWS.Debian with a blank line like lintian would suggest
  if that check would be working correctly.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* font.c - Font API and font file loader.  */
2
2
/*
3
3
 *  GRUB  --  GRand Unified Bootloader
4
 
 *  Copyright (C) 2003,2005,2006,2007,2008,2009  Free Software Foundation, Inc.
 
4
 *  Copyright (C) 2003,2005,2006,2007,2008,2009,2010  Free Software Foundation, Inc.
5
5
 *
6
6
 *  GRUB is free software: you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
27
27
#include <grub/video.h>
28
28
#include <grub/bitmap.h>
29
29
 
 
30
#ifdef USE_ASCII_FAILBACK
 
31
#include "ascii.h"
 
32
#endif
 
33
 
30
34
#ifndef FONT_DEBUG
31
35
#define FONT_DEBUG 0
32
36
#endif
43
47
 
44
48
#define FONT_WEIGHT_NORMAL 100
45
49
#define FONT_WEIGHT_BOLD 200
 
50
#define ASCII_BITMAP_SIZE 16
46
51
 
47
52
struct grub_font
48
53
{
58
63
  short leading;
59
64
  grub_uint32_t num_chars;
60
65
  struct char_index_entry *char_index;
 
66
  grub_uint16_t *bmp_idx;
61
67
};
62
68
 
63
69
/* Definition of font registry.  */
129
135
/* Flag to ensure module is initialized only once.  */
130
136
static grub_uint8_t font_loader_initialized;
131
137
 
 
138
#ifdef USE_ASCII_FAILBACK
 
139
static struct grub_font_glyph *ascii_font_glyph[0x80];
 
140
#endif
 
141
 
 
142
static struct grub_font_glyph *
 
143
ascii_glyph_lookup (grub_uint32_t code)
 
144
{
 
145
#ifdef USE_ASCII_FAILBACK 
 
146
  static int ascii_failback_initialized = 0;
 
147
 
 
148
  if (code >= 0x80)
 
149
    return unknown_glyph;
 
150
 
 
151
  if (ascii_failback_initialized == 0)
 
152
    {
 
153
      int current;
 
154
      for (current = 0; current < 0x80; current++)
 
155
        {
 
156
          ascii_font_glyph[current] = grub_malloc(sizeof(struct grub_font_glyph)
 
157
                                + ASCII_BITMAP_SIZE);
 
158
 
 
159
          ascii_font_glyph[current]->width = 8;
 
160
          ascii_font_glyph[current]->height = 16; 
 
161
          ascii_font_glyph[current]->offset_x = 0; 
 
162
          ascii_font_glyph[current]->offset_y = -2; 
 
163
          ascii_font_glyph[current]->device_width = 8;
 
164
 
 
165
          grub_memcpy (ascii_font_glyph[current]->bitmap,
 
166
                       &ascii_bitmaps[(0x7f - current) * ASCII_BITMAP_SIZE],
 
167
                       ASCII_BITMAP_SIZE);
 
168
        }
 
169
 
 
170
      ascii_failback_initialized = 1;
 
171
    }
 
172
 
 
173
  return ascii_font_glyph[code];
 
174
#else
 
175
  (void) code;
 
176
  return unknown_glyph;
 
177
#endif
 
178
}
 
179
 
132
180
void
133
181
grub_font_loader_init (void)
134
182
{
180
228
  font->descent = 0;
181
229
  font->num_chars = 0;
182
230
  font->char_index = 0;
 
231
  font->bmp_idx = 0;
183
232
}
184
233
 
185
234
/* Open the next section in the file.
273
322
                                  * sizeof (struct char_index_entry));
274
323
  if (! font->char_index)
275
324
    return 1;
 
325
  font->bmp_idx = grub_malloc (0x10000 * sizeof (grub_uint16_t));
 
326
  if (! font->bmp_idx)
 
327
    {
 
328
      grub_free (font->char_index);
 
329
      return 1;
 
330
    }
 
331
  grub_memset (font->bmp_idx, 0xff, 0x10000 * sizeof (grub_uint16_t));
 
332
 
276
333
 
277
334
#if FONT_DEBUG >= 2
278
335
  grub_printf("num_chars=%d)\n", font->num_chars);
299
356
          return 1;
300
357
        }
301
358
 
 
359
      if (entry->code < 0x10000)
 
360
        font->bmp_idx[entry->code] = i;
 
361
 
302
362
      last_code = entry->code;
303
363
 
304
364
      /* Read storage flags byte.  */
594
654
 
595
655
/* Return a pointer to the character index entry for the glyph corresponding to
596
656
   the codepoint CODE in the font FONT.  If not found, return zero.  */
597
 
static struct char_index_entry *
 
657
static inline struct char_index_entry *
598
658
find_glyph (const grub_font_t font, grub_uint32_t code)
599
659
{
600
660
  struct char_index_entry *table;
602
662
  grub_size_t hi;
603
663
  grub_size_t mid;
604
664
 
 
665
  table = font->char_index;
 
666
 
 
667
  /* Use BMP index if possible.  */
 
668
  if (code < 0x10000)
 
669
    {
 
670
      if (font->bmp_idx[code] == 0xffff)
 
671
        return 0;
 
672
      return &table[font->bmp_idx[code]];
 
673
    }
 
674
 
605
675
  /* Do a binary search in `char_index', which is ordered by code point.  */
606
 
  table = font->char_index;
607
676
  lo = 0;
608
677
  hi = font->num_chars - 1;
609
678
 
865
934
}
866
935
 
867
936
/* Get the glyph for FONT corresponding to the Unicode code point CODE.
868
 
   Returns a pointer to an glyph indicating there is no glyph available
869
 
   if CODE does not exist in the font.  The glyphs are cached once loaded.  */
 
937
   Returns the ASCII glyph for the code if no other fonts are available. 
 
938
   The glyphs are cached once loaded.  */
870
939
struct grub_font_glyph *
871
940
grub_font_get_glyph (grub_font_t font, grub_uint32_t code)
872
941
{
873
942
  struct grub_font_glyph *glyph;
874
943
  glyph = grub_font_get_glyph_internal (font, code);
875
944
  if (glyph == 0)
876
 
    glyph = unknown_glyph;
 
945
    {
 
946
      glyph = ascii_glyph_lookup (code);
 
947
    }
877
948
  return glyph;
878
949
}
879
950
 
968
1039
  if (best_glyph)
969
1040
    return best_glyph;
970
1041
  else
971
 
    /* Glyph not available in any font.  Return unknown glyph.  */
972
 
    return unknown_glyph;
 
1042
    /* Glyph not available in any font.  Return ASCII failback.  */
 
1043
    return ascii_glyph_lookup (code);
973
1044
}
974
1045
 
975
1046