Skip to contentSkip to conversation

macrofy fontcontants

PATCH Carles Pina i Estany 3 participants 4 messages Jan 25, 2010 – Jan 26, 2010

lore
Share & tools
lore
#0 lore raw

Hello,

Find attached a way to macrofy the constants from font files between util and grub kernel.

Comments, name changes, etc. are welcomed.

Signature · 2 lines
Carles Pina i Estany
	http://pinux.info

=== modified file 'ChangeLog'

ChangeLog +9 -0
@@ -1,3 +1,12 @@
+2010-01-25  Carles Pina i Estany  <[email protected]>
+
+	* font/font.c: Include `grub/fontformat.h.
+	Remove font file format constants.
+	(grub_font_load): Use the new constant names.
+	* include/grub/fontformat.h: New file.
+	* util/grub-mkfont.c: Include `grub/fontformat.c'.
+	(write_font_pf2): Use the new macros instead of hardcoded literals.
+
 2010-01-25  Colin Watson  <[email protected]>
 
 	* util/hostdisk.c (open_device): Add trailing newline to debug

=== modified file 'font/font.c'

font.c +27 -24

116 lines not on this page · raw message

=== added file 'include/grub/fontformat.h'

grub/fontformat.h +38 -0
@@ -0,0 +1,38 @@
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2010 Free Software Foundation, Inc.
+ *
+ *  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/>.
+ */
+
+#ifndef GRUB_FONT_FORMAT_HEADER
+#define GRUB_FONT_FORMAT_HEADER	1
+
+/* FONT_FORMAT_PFF2_MAGIC use only 4 relevants bytes and the \0.  */
+#define FONT_FORMAT_PFF2_MAGIC "PFF2"
+#define FONT_FORMAT_SECTION_NAMES_FILE "FILE"
+#define FONT_FORMAT_SECTION_NAMES_FONT_NAME "NAME"
+#define FONT_FORMAT_SECTION_NAMES_POINT_SIZE "PTSZ"
+#define FONT_FORMAT_SECTION_NAMES_WEIGHT "WEIG"
+#define FONT_FORMAT_SECTION_NAMES_MAX_CHAR_WIDTH "MAXW"
+#define FONT_FORMAT_SECTION_NAMES_MAX_CHAR_HEIGHT "MAXH"
+#define FONT_FORMAT_SECTION_NAMES_ASCENT "ASCE"
+#define FONT_FORMAT_SECTION_NAMES_DESCENT "DESC"
+#define FONT_FORMAT_SECTION_NAMES_CHAR_INDEX "CHIX"
+#define FONT_FORMAT_SECTION_NAMES_DATA "DATA"
+#define FONT_FORMAT_SECTION_NAMES_FAMILY "FAMI"
+#define FONT_FORMAT_SECTION_NAMES_SLAN "SLAN"
+
+#endif /* ! GRUB_FONT_FORMAT_HEADER */
+

=== modified file 'util/grub-mkfont.c'

grub-mkfont.c +24 -13
@@ -20,6 +20,7 @@
 #include <grub/types.h>
 #include <grub/util/misc.h>
 #include <grub/i18n.h>
+#include <grub/fontformat.h>
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -392,9 +393,10 @@ write_font_pf2 (struct grub_font_info *f
   offset = 0;
 
   leng = grub_cpu_to_be32 (4);
-  grub_util_write_image ("FILE", 4, file);
+  grub_util_write_image (FONT_FORMAT_SECTION_NAMES_FILE,
+  			 sizeof(FONT_FORMAT_SECTION_NAMES_FILE) - 1, file);
   grub_util_write_image ((char *) &leng, 4, file);
-  grub_util_write_image ("PFF2", 4, file);
+  grub_util_write_image (FONT_FORMAT_PFF2_MAGIC, 4, file);
   offset += 12;
 
   if (! font_info->name)
@@ -416,20 +418,25 @@ write_font_pf2 (struct grub_font_info *f
   font_name = xasprintf ("%s %s %d", font_info->name, &style_name[1],
 			 font_info->size);
 
-  write_string_section ("NAME", font_name, &offset, file);
-  write_string_section ("FAMI", font_info->name, &offset, file);
-  write_string_section ("WEIG",
+  write_string_section (FONT_FORMAT_SECTION_NAMES_FONT_NAME,
+  			font_name, &offset, file);
+  write_string_section (FONT_FORMAT_SECTION_NAMES_FAMILY,
+  			font_info->name, &offset, file);
+  write_string_section (FONT_FORMAT_SECTION_NAMES_WEIGHT,
 			(font_info->style & FT_STYLE_FLAG_BOLD) ?
 			"bold" : "normal",
 			&offset, file);
-  write_string_section ("SLAN",
+  write_string_section (FONT_FORMAT_SECTION_NAMES_SLAN,
 			(font_info->style & FT_STYLE_FLAG_ITALIC) ?
 			"italic" : "normal",
 			&offset, file);
 
-  write_be16_section ("PTSZ", font_info->size, &offset, file);
-  write_be16_section ("MAXW", font_info->max_width, &offset, file);
-  write_be16_section ("MAXH", font_info->max_height, &offset, file);
+  write_be16_section (FONT_FORMAT_SECTION_NAMES_POINT_SIZE,
+  		      font_info->size, &offset, file);
+  write_be16_section (FONT_FORMAT_SECTION_NAMES_MAX_CHAR_WIDTH,
+  		      font_info->max_width, &offset, file);
+  write_be16_section (FONT_FORMAT_SECTION_NAMES_MAX_CHAR_HEIGHT,
+  		      font_info->max_height, &offset, file);
 
   if (! font_info->desc)
     {
@@ -447,8 +454,10 @@ write_font_pf2 (struct grub_font_info *f
 	font_info->asce = font_info->max_y;
     }
 
-  write_be16_section ("ASCE", font_info->asce, &offset, file);
-  write_be16_section ("DESC", font_info->desc, &offset, file);
+  write_be16_section (FONT_FORMAT_SECTION_NAMES_ASCENT,
+  		      font_info->asce, &offset, file);
+  write_be16_section (FONT_FORMAT_SECTION_NAMES_DESCENT,
+  		      font_info->desc, &offset, file);
 
   if (font_verbosity > 0)
     {
@@ -479,7 +488,9 @@ write_font_pf2 (struct grub_font_info *f
     printf ("Number of glyph: %d\n", num);
 
   leng = grub_cpu_to_be32 (num * 9);
-  grub_util_write_image ("CHIX", 4, file);
+  grub_util_write_image (FONT_FORMAT_SECTION_NAMES_CHAR_INDEX,
+  			 sizeof(FONT_FORMAT_SECTION_NAMES_CHAR_INDEX) - 1,
+			 file);
   grub_util_write_image ((char *) &leng, 4, file);
   offset += 8 + num * 9 + 8;
 
@@ -495,7 +506,7 @@ write_font_pf2 (struct grub_font_info *f
     }
 
   leng = 0xffffffff;
-  grub_util_write_image ("DATA", 4, file);
+  grub_util_write_image (FONT_FORMAT_SECTION_NAMES_DATA, 4, file);
   grub_util_write_image ((char *) &leng, 4, file);
 
   for (cur = font_info->glyph; cur; cur = cur->next)
#2 lore raw
Quoted 6 lines · Evgeny Kolesnikov
Quoted 3 lines · Carles Pina i Estany

Find attached a way to macrofy the constants from font files between util and grub kernel.

Quoted 10 lines
Quoted 2 lines

Comments, name changes, etc. are welcomed.

Can you please consider my patch for anti-aliased fonts in your scheme. It's in the way to be added into trunk.

(http://lists.gnu.org/archive/html/grub-devel/2010-01/msg00301.html)

There is no reason your pending patch should affect Carles' one.
Carles: Assuming, files generated by grub-mkfont are the same up to byte and you have tested rendering part, you can merge your patch

Quoted 6 lines

_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel

Signature · 2 lines
Regards
Vladimir 'φ-coder/phcoder' Serbinenko
#3 lore raw

Hi,

Quoted 10 lines · Vladimir '??-coder/phcoder' Serbinenko
Quoted 9 lines · Evgeny Kolesnikov
Quoted 5 lines · Carles Pina i Estany

Find attached a way to macrofy the constants from font files between util and grub kernel.

Comments, name changes, etc. are welcomed.

Quoted 8 lines
Quoted 7 lines

Can you please consider my patch for anti-aliased fonts in your scheme. It's in the way to be added into trunk.

(http://lists.gnu.org/archive/html/grub-devel/2010-01/msg00301.html)

There is no reason your pending patch should affect Carles' one.

Well, someone has to adapt some code :-(

It was on my pending list for some weeks... bad timing. But your one Evgeny is a bit bigger and may take some time

Quoted 2 lines

Carles: Assuming, files generated by grub-mkfont are the same up to byte and you have tested rendering part, you can merge your patch

I will double check and commit.

Thanks,

Signature · 2 lines
Carles Pina i Estany
	http://pinux.info