From: oetiker Date: Sun, 8 May 2005 21:25:42 +0000 (+0000) Subject: added support for getting ascent/descent size info for ps fonts -- Peter Speck X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=ee5c354c98d7393c92829a865279e3eb83a3b038;p=rrdtool.git added support for getting ascent/descent size info for ps fonts -- Peter Speck git-svn-id: svn://svn.oetiker.ch/rrdtool/branches/1.2/program@521 a5681a0c-68f1-0310-ab6d-d61299d08faa --- diff --git a/libraries/afm/compile_afm.pl b/libraries/afm/compile_afm.pl index b53d3d4..efcf5dd 100644 --- a/libraries/afm/compile_afm.pl +++ b/libraries/afm/compile_afm.pl @@ -1,4 +1,4 @@ -#!/usr/local/bin/perl -w +#!/usr/bin/perl -w require 5.005; use strict; @@ -63,11 +63,15 @@ sub process_font $fi{FontSpecificUnicodeNameToChar} = {}; $fi{filename} = $fn; $fi{filename} =~ s/.*\///; + $fi{Ascender} = 0; + $fi{Descender} = 0; open(FH, $fn) || die "Can't open $fn\n"; print STDERR "Reads global font info\n" if $q; while () { chomp; next if /^\s*$/ || /^\s*#/; + $fi{Ascender} = $1 if /^Ascender\s+(-?\d+)/; + $fi{Descender} = $1 if /^Descender\s+(-?\d+)/; last if /^StartCharMetrics/; next unless (/^(\S+)\s+(\S(.*\S)?)/); my $id = $1; @@ -244,8 +248,8 @@ sub write_font $kerning_data_count + 2 * $highchars_count + 3 * 2 * $ligatures_count; $info_code .= $indent1 . "{ /* $$fiR{filename} $packedSize bytes */\n"; - $info_code .= $i2 . "\"$$fiR{AfmFontName}\","; - $info_code .= " \"$$fiR{AfmFullName}\",\n"; + $info_code .= $i2 . "\"$$fiR{AfmFontName}\", \"$$fiR{AfmFullName}\",\n"; + $info_code .= $i2 . $$fiR{Ascender} . ", " . $$fiR{Descender} . ",\n"; $info_code .= $i2 . $$fiR{widthsACName} . ",\n"; $info_code .= $i2 . $$fiR{kerning_indexACName} . ",\n"; $info_code .= $i2 . $$fiR{kerning_dataACName} . ",\n"; @@ -448,7 +452,7 @@ sub main print CFILE ${$font_code{$_}}{TABLES} foreach @fonts; print CFILE "const afm_fontinfo afm_fontinfolist[] = {\n"; print CFILE ${$font_code{$_}}{INFO} foreach @fonts; - print CFILE $indent1 . "{ 0, 0, 0 }\n"; + print CFILE $indent1 . "{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }\n"; print CFILE $indent0 . "};\n"; print CFILE $indent0 . "const int afm_fontinfo_count = ", ($#fonts + 1), ";\n"; diff --git a/src/rrd_afm.c b/src/rrd_afm.c index 2b7e343..5bf6e91 100644 --- a/src/rrd_afm.c +++ b/src/rrd_afm.c @@ -73,6 +73,18 @@ const char *afm_get_font_postscript_name(const char* font) return p ? p->postscript_name : "Helvetica"; } +double afm_get_ascender(const char* font, double size) +{ + const afm_fontinfo *p = afm_findfont(font); + return p ? p->ascender : 10; /* just a guess to avoid really bad design if we don't know the font */ +} + +double afm_get_descender(const char* font, double size) +{ + const afm_fontinfo *p = afm_findfont(font); + return p ? p->descender : 4; /* just a guess to avoid really bad design if we don't know the font */ +} + static int afm_find_char_index(const afm_fontinfo *fontinfo, afm_cunicode ch1) { diff --git a/src/rrd_afm.h b/src/rrd_afm.h index 2ff9d06..6a59318 100644 --- a/src/rrd_afm.h +++ b/src/rrd_afm.h @@ -12,6 +12,9 @@ double afm_get_text_width ( double start, const char* font, double size, double tabwidth, const char* text); +double afm_get_ascender(const char* font, double size); +double afm_get_descender(const char* font, double size); + /* get postscript name from fullname or postscript name */ const char *afm_get_font_postscript_name ( const char* font); diff --git a/src/rrd_afm_data.c b/src/rrd_afm_data.c index 39fb43e..f5805fd 100644 --- a/src/rrd_afm_data.c +++ b/src/rrd_afm_data.c @@ -3223,6 +3223,7 @@ static afm_cunicode afm_Times_Roman_ligatures[] = { /* 3 */ const afm_fontinfo afm_fontinfolist[] = { { /* Courier.afm 761 bytes */ "Courier", "Courier", + 629, -157, afm_Courier_widths, NULL, NULL, @@ -3230,6 +3231,7 @@ const afm_fontinfo afm_fontinfolist[] = { afm_Courier_ligatures, 1}, { /* Courier-Bold.afm 761 bytes */ "Courier-Bold", "Courier Bold", + 629, -157, afm_Courier_Bold_widths, NULL, NULL, @@ -3237,6 +3239,7 @@ const afm_fontinfo afm_fontinfolist[] = { afm_Courier_Bold_ligatures, 1}, { /* Courier-BoldOblique.afm 761 bytes */ "Courier-BoldOblique", "Courier Bold Oblique", + 629, -157, afm_Courier_BoldOblique_widths, NULL, NULL, @@ -3244,6 +3247,7 @@ const afm_fontinfo afm_fontinfolist[] = { afm_Courier_BoldOblique_ligatures, 1}, { /* Courier-Oblique.afm 761 bytes */ "Courier-Oblique", "Courier Oblique", + 629, -157, afm_Courier_Oblique_widths, NULL, NULL, @@ -3251,6 +3255,7 @@ const afm_fontinfo afm_fontinfolist[] = { afm_Courier_Oblique_ligatures, 1}, { /* Helvetica.afm 7841 bytes */ "Helvetica", "Helvetica", + 718, -207, afm_Helvetica_widths, afm_Helvetica_kerning_index, afm_Helvetica_kerning_data, @@ -3258,6 +3263,7 @@ const afm_fontinfo afm_fontinfolist[] = { afm_Helvetica_ligatures, 1}, { /* Helvetica-Bold.afm 7336 bytes */ "Helvetica-Bold", "Helvetica Bold", + 718, -207, afm_Helvetica_Bold_widths, afm_Helvetica_Bold_kerning_index, afm_Helvetica_Bold_kerning_data, @@ -3265,6 +3271,7 @@ const afm_fontinfo afm_fontinfolist[] = { afm_Helvetica_Bold_ligatures, 1}, { /* Helvetica-BoldOblique.afm 7336 bytes */ "Helvetica-BoldOblique", "Helvetica Bold Oblique", + 718, -207, afm_Helvetica_BoldOblique_widths, afm_Helvetica_BoldOblique_kerning_index, afm_Helvetica_BoldOblique_kerning_data, @@ -3272,6 +3279,7 @@ const afm_fontinfo afm_fontinfolist[] = { afm_Helvetica_BoldOblique_ligatures, 1}, { /* Helvetica-Oblique.afm 7841 bytes */ "Helvetica-Oblique", "Helvetica Oblique", + 718, -207, afm_Helvetica_Oblique_widths, afm_Helvetica_Oblique_kerning_index, afm_Helvetica_Oblique_kerning_data, @@ -3279,6 +3287,7 @@ const afm_fontinfo afm_fontinfolist[] = { afm_Helvetica_Oblique_ligatures, 1}, { /* ZapfDingbats.afm 416 bytes */ "ZapfDingbats", "ITC Zapf Dingbats", + 0, 0, afm_ZapfDingbats_widths, NULL, NULL, @@ -3286,6 +3295,7 @@ const afm_fontinfo afm_fontinfolist[] = { NULL, 0}, { /* Symbol.afm 563 bytes */ "Symbol", "Symbol", + 0, 0, afm_Symbol_widths, NULL, NULL, @@ -3293,6 +3303,7 @@ const afm_fontinfo afm_fontinfolist[] = { NULL, 0}, { /* Times-Bold.afm 6761 bytes */ "Times-Bold", "Times Bold", + 683, -217, afm_Times_Bold_widths, afm_Times_Bold_kerning_index, afm_Times_Bold_kerning_data, @@ -3300,6 +3311,7 @@ const afm_fontinfo afm_fontinfolist[] = { afm_Times_Bold_ligatures, 1}, { /* Times-BoldItalic.afm 6270 bytes */ "Times-BoldItalic", "Times Bold Italic", + 683, -217, afm_Times_BoldItalic_widths, afm_Times_BoldItalic_kerning_index, afm_Times_BoldItalic_kerning_data, @@ -3307,6 +3319,7 @@ const afm_fontinfo afm_fontinfolist[] = { afm_Times_BoldItalic_ligatures, 1}, { /* Times-Italic.afm 6975 bytes */ "Times-Italic", "Times Italic", + 683, -217, afm_Times_Italic_widths, afm_Times_Italic_kerning_index, afm_Times_Italic_kerning_data, @@ -3314,11 +3327,12 @@ const afm_fontinfo afm_fontinfolist[] = { afm_Times_Italic_ligatures, 1}, { /* Times-Roman.afm 6287 bytes */ "Times-Roman", "Times Roman", + 683, -217, afm_Times_Roman_widths, afm_Times_Roman_kerning_index, afm_Times_Roman_kerning_data, afm_Times_Roman_highchars_index, 220, afm_Times_Roman_ligatures, 1}, - { 0, 0, 0, 0, 0, 0, 0, 0, 0 } + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }; const int afm_fontinfo_count = 14; diff --git a/src/rrd_afm_data.h b/src/rrd_afm_data.h index 9ae858c..ecc049f 100644 --- a/src/rrd_afm_data.h +++ b/src/rrd_afm_data.h @@ -168,6 +168,7 @@ typedef const afm_unicode afm_cunicode; typedef struct afm_fontinfo { const char *fullname; /* e.g. "Futura Bold Oblique" */ const char *postscript_name; /* e.g. "Futura-BoldOblique" */ + afm_cuint16 ascender, descender; afm_cuint8 *widths; afm_csint16 *kerning_index; afm_cuint8 *kerning_data;