summaryrefslogtreecommitdiff
path: root/Build/source/texk/web2c/luatexdir/font
diff options
context:
space:
mode:
Diffstat (limited to 'Build/source/texk/web2c/luatexdir/font')
-rw-r--r--Build/source/texk/web2c/luatexdir/font/dofont.c179
-rw-r--r--Build/source/texk/web2c/luatexdir/font/dofont.w147
-rw-r--r--Build/source/texk/web2c/luatexdir/font/luafont.w (renamed from Build/source/texk/web2c/luatexdir/font/luafont.c)694
-rw-r--r--Build/source/texk/web2c/luatexdir/font/luatexfont.h80
-rw-r--r--Build/source/texk/web2c/luatexdir/font/macnames.c313
-rw-r--r--Build/source/texk/web2c/luatexdir/font/mapfile.h106
-rw-r--r--Build/source/texk/web2c/luatexdir/font/mapfile.w (renamed from Build/source/texk/web2c/luatexdir/font/mapfile.c)493
-rw-r--r--Build/source/texk/web2c/luatexdir/font/pkin.w (renamed from Build/source/texk/web2c/luatexdir/font/pkin.c)203
-rw-r--r--Build/source/texk/web2c/luatexdir/font/sfnt.h8
-rw-r--r--Build/source/texk/web2c/luatexdir/font/sfnt.w (renamed from Build/source/texk/web2c/luatexdir/font/sfnt.c)311
-rw-r--r--Build/source/texk/web2c/luatexdir/font/subfont.txt103
-rw-r--r--Build/source/texk/web2c/luatexdir/font/subfont.w (renamed from Build/source/texk/web2c/luatexdir/font/subfont.c)112
-rw-r--r--Build/source/texk/web2c/luatexdir/font/texfont.h283
-rw-r--r--Build/source/texk/web2c/luatexdir/font/texfont.w (renamed from Build/source/texk/web2c/luatexdir/font/texfont.c)630
-rw-r--r--Build/source/texk/web2c/luatexdir/font/tfmofm.w (renamed from Build/source/texk/web2c/luatexdir/font/tfmofm.c)299
-rw-r--r--Build/source/texk/web2c/luatexdir/font/tounicode.w (renamed from Build/source/texk/web2c/luatexdir/font/tounicode.c)232
-rw-r--r--Build/source/texk/web2c/luatexdir/font/tt_glyf.w (renamed from Build/source/texk/web2c/luatexdir/font/tt_glyf.c)200
-rw-r--r--Build/source/texk/web2c/luatexdir/font/tt_table.w (renamed from Build/source/texk/web2c/luatexdir/font/tt_table.c)125
-rw-r--r--Build/source/texk/web2c/luatexdir/font/vfovf.w (renamed from Build/source/texk/web2c/luatexdir/font/vfovf.c)544
-rw-r--r--Build/source/texk/web2c/luatexdir/font/vfpacket.w (renamed from Build/source/texk/web2c/luatexdir/font/vfpacket.c)192
-rw-r--r--Build/source/texk/web2c/luatexdir/font/writecff.h6
-rw-r--r--Build/source/texk/web2c/luatexdir/font/writecff.w (renamed from Build/source/texk/web2c/luatexdir/font/writecff.c)858
-rw-r--r--Build/source/texk/web2c/luatexdir/font/writeenc.c187
-rw-r--r--Build/source/texk/web2c/luatexdir/font/writeenc.w161
-rw-r--r--Build/source/texk/web2c/luatexdir/font/writefont.w (renamed from Build/source/texk/web2c/luatexdir/font/writefont.c)639
-rw-r--r--Build/source/texk/web2c/luatexdir/font/writet1.w (renamed from Build/source/texk/web2c/luatexdir/font/writet1.c)750
-rw-r--r--Build/source/texk/web2c/luatexdir/font/writet3.w (renamed from Build/source/texk/web2c/luatexdir/font/writet3.c)247
-rw-r--r--Build/source/texk/web2c/luatexdir/font/writettf.h18
-rw-r--r--Build/source/texk/web2c/luatexdir/font/writettf.w (renamed from Build/source/texk/web2c/luatexdir/font/writettf.c)866
-rw-r--r--Build/source/texk/web2c/luatexdir/font/writetype0.c125
-rw-r--r--Build/source/texk/web2c/luatexdir/font/writetype0.w123
-rw-r--r--Build/source/texk/web2c/luatexdir/font/writetype2.w (renamed from Build/source/texk/web2c/luatexdir/font/writetype2.c)327
32 files changed, 4564 insertions, 4997 deletions
diff --git a/Build/source/texk/web2c/luatexdir/font/dofont.c b/Build/source/texk/web2c/luatexdir/font/dofont.c
deleted file mode 100644
index 4e026f339a3..00000000000
--- a/Build/source/texk/web2c/luatexdir/font/dofont.c
+++ /dev/null
@@ -1,179 +0,0 @@
-/* dofont.c
-
- Copyright 2006-2008 Taco Hoekwater <taco@luatex.org>
-
- This file is part of LuaTeX.
-
- LuaTeX 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 2 of the License, or (at your
- option) any later version.
-
- LuaTeX 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 Lesser General Public
- License for more details.
-
- You should have received a copy of the GNU General Public License along
- with LuaTeX; if not, see <http://www.gnu.org/licenses/>. */
-
-#include "ptexlib.h"
-
-#include "luatex-api.h"
-
-static const char _svn_version[] =
- "$Id: dofont.c 2448 2009-06-08 07:43:50Z taco $ $URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.40.6/source/texk/web2c/luatexdir/font/dofont.c $";
-
-#define TIMERS 0
-
-#if TIMERS
-# include <sys/time.h>
-#endif
-
-
-/* a bit more interfacing is needed for proper error reporting */
-
-static char *font_error_message(pointer u, char *nom, scaled s)
-{
- char *str = xmalloc(256);
- char *c = makecstring(zget_cs_text(u));
- const char *extra = "metric data not found or bad";
- if (s >= 0) {
- snprintf(str, 255, "Font \\%s=%s at %gpt not loadable: %s", c, nom,
- (double) s / 65536, extra);
- } else if (s != -1000) {
- snprintf(str, 255, "Font \\%s=%s scaled %d not loadable: %s", c, nom,
- (int) (-s), extra);
- } else {
- snprintf(str, 255, "Font \\%s=%s not loadable: %s", c, nom, extra);
- }
- return str;
-}
-
-static int do_define_font(integer f, const char *cnom, scaled s, integer natural_dir)
-{
-
- boolean res; /* was the callback successful? */
- integer callback_id;
- char *cnam;
-#if TIMERS
- struct timeval tva;
- struct timeval tvb;
- double tvdiff;
-#endif
- int r;
- res = 0;
-
- callback_id = callback_defined(define_font_callback);
- if (callback_id > 0) {
- cnam = xstrdup(cnom);
-#if TIMERS
- gettimeofday(&tva, NULL);
-#endif
- callback_id = run_and_save_callback(callback_id, "Sdd->", cnam, s, f);
-#if TIMERS
- gettimeofday(&tvb, NULL);
- tvdiff = tvb.tv_sec * 1000000.0;
- tvdiff += (double) tvb.tv_usec;
- tvdiff -= (tva.tv_sec * 1000000.0);
- tvdiff -= (double) tva.tv_usec;
- tvdiff /= 1000000;
- fprintf(stdout, "\ncallback('define_font',%s,%i): %f seconds\n", cnam,
- f, tvdiff);
-#endif
- free(cnam);
- if (callback_id > 0) { /* success */
- luaL_checkstack(Luas, 1, "out of stack space");
- lua_rawgeti(Luas, LUA_REGISTRYINDEX, callback_id);
- if (lua_istable(Luas, -1)) {
-#if TIMERS
- gettimeofday(&tva, NULL);
-#endif
- res = font_from_lua(Luas, f);
- destroy_saved_callback(callback_id);
-#if TIMERS
- gettimeofday(&tvb, NULL);
- tvdiff = tvb.tv_sec * 1000000.0;
- tvdiff += (double) tvb.tv_usec;
- tvdiff -= (tva.tv_sec * 1000000.0);
- tvdiff -= (double) tva.tv_usec;
- tvdiff /= 1000000;
- fprintf(stdout, "font_from_lua(%s,%i): %f seconds\n",
- font_name(f), f, tvdiff);
-#endif
- /* lua_pop(Luas, 1); *//* done by font_from_lua */
- } else if (lua_isnumber(Luas, -1)) {
- r = lua_tonumber(Luas, -1);
- destroy_saved_callback(callback_id);
- delete_font(f);
- lua_pop(Luas, 1);
- return r;
- } else {
- lua_pop(Luas, 1);
- delete_font(f);
- return 0;
- }
- }
- } else if (callback_id == 0) {
- res = read_tfm_info(f, cnom, s);
- if (res) {
- set_hyphen_char(f, get_default_hyphen_char());
- set_skew_char(f, get_default_skew_char());
- }
- }
- if (res) {
- if (font_type(f) != virtual_font_type) { /* implies lua */
- do_vf(f);
- set_font_natural_dir(f, natural_dir);
- }
- return f;
- } else {
- delete_font(f);
- return 0;
- }
-
-}
-
-int read_font_info(pointer u, str_number nom, scaled s, integer natural_dir)
-{
- integer f;
- char *cnom;
- char *msg;
- cnom = xstrdup(makecstring(nom));
-
- f = new_font();
- if ((f = do_define_font(f, cnom, s, natural_dir))) {
- free(cnom);
- return f;
- } else {
- const char *help[] = { "I wasn't able to read the size data for this font,",
- "so I will ignore the font specification.",
- "[Wizards can fix TFM files using TFtoPL/PLtoTF.]",
- "You might try inserting a different font spec;",
- "e.g., type `I\font<same font id>=<substitute font name>'.",
- NULL
- };
- if (!get_suppress_fontnotfound_error()) {
- msg = font_error_message(u, cnom, s);
- tex_error(msg, help);
- free(msg);
- }
- free(cnom);
- return 0;
- }
-}
-
-/* TODO This function is a placeholder. There can easily appears holes in
- the |font_tables| array, and we could attempt to reuse those
-*/
-
-int find_font_id(const char *nom, scaled s)
-{
- integer f;
- f = new_font();
- if ((f = do_define_font(f, nom, s, -1))) {
- return f;
- } else {
- return 0;
- }
-}
diff --git a/Build/source/texk/web2c/luatexdir/font/dofont.w b/Build/source/texk/web2c/luatexdir/font/dofont.w
new file mode 100644
index 00000000000..38278e8d1cb
--- /dev/null
+++ b/Build/source/texk/web2c/luatexdir/font/dofont.w
@@ -0,0 +1,147 @@
+% dofont.w
+%
+% Copyright 2006-2010 Taco Hoekwater <taco@@luatex.org>
+%
+% This file is part of LuaTeX.
+%
+% LuaTeX 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 2 of the License, or (at your
+% option) any later version.
+%
+% LuaTeX 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 Lesser General Public
+% License for more details.
+%
+% You should have received a copy of the GNU General Public License along
+% with LuaTeX; if not, see <http://www.gnu.org/licenses/>.
+
+@ @c
+#include "ptexlib.h"
+
+#include "lua/luatex-api.h"
+
+static const char _svn_version[] =
+ "$Id: dofont.w 3584 2010-04-02 17:45:55Z hhenkel $ "
+ "$URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.60.0/source/texk/web2c/luatexdir/font/dofont.w $";
+
+@ a bit more interfacing is needed for proper error reporting
+
+@c
+static char *font_error_message(pointer u, char *nom, scaled s)
+{
+ char *str = xmalloc(256);
+ char *c = makecstring(cs_text(u));
+ const char *extra = "metric data not found or bad";
+ if (s >= 0) {
+ snprintf(str, 255, "Font \\%s=%s at %gpt not loadable: %s", c, nom,
+ (double) s / 65536, extra);
+ } else if (s != -1000) {
+ snprintf(str, 255, "Font \\%s=%s scaled %d not loadable: %s", c, nom,
+ (int) (-s), extra);
+ } else {
+ snprintf(str, 255, "Font \\%s=%s not loadable: %s", c, nom, extra);
+ }
+ free(c);
+ return str;
+}
+
+static int do_define_font(int f, const char *cnom, scaled s, int natural_dir)
+{
+
+ boolean res; /* was the callback successful? */
+ int callback_id;
+ char *cnam;
+ int r;
+ res = 0;
+
+ callback_id = callback_defined(define_font_callback);
+ if (callback_id > 0) {
+ cnam = xstrdup(cnom);
+ callback_id = run_and_save_callback(callback_id, "Sdd->", cnam, s, f);
+ free(cnam);
+ if (callback_id > 0) { /* success */
+ luaL_checkstack(Luas, 1, "out of stack space");
+ lua_rawgeti(Luas, LUA_REGISTRYINDEX, callback_id);
+ if (lua_istable(Luas, -1)) {
+ res = font_from_lua(Luas, f);
+ destroy_saved_callback(callback_id);
+ /* |lua_pop(Luas, 1);| *//* done by |font_from_lua| */
+ } else if (lua_isnumber(Luas, -1)) {
+ lua_number2int(r, lua_tonumber(Luas, -1));
+ destroy_saved_callback(callback_id);
+ delete_font(f);
+ lua_pop(Luas, 1);
+ return r;
+ } else {
+ lua_pop(Luas, 1);
+ delete_font(f);
+ return 0;
+ }
+ }
+ } else if (callback_id == 0) {
+ res = read_tfm_info(f, cnom, s);
+ if (res) {
+ set_hyphen_char(f, int_par(default_hyphen_char_code));
+ set_skew_char(f, int_par(default_skew_char_code));
+ }
+ }
+ if (font_name(f) && strlen(font_name(f)) > 255) {
+ /* the font name has to fit in the dvi file's single byte storage */
+ /* no need to test area, as we are never using it */
+ res = 0;
+ }
+ if (res) {
+ if (font_type(f) != virtual_font_type) { /* implies lua */
+ do_vf(f);
+ set_font_natural_dir(f, natural_dir);
+ }
+ return f;
+ } else {
+ delete_font(f);
+ return 0;
+ }
+
+}
+
+int read_font_info(pointer u, char *cnom, scaled s, int natural_dir)
+{
+ int f;
+ char *msg;
+
+ f = new_font();
+ if ((f = do_define_font(f, cnom, s, natural_dir))) {
+ return f;
+ } else {
+ const char *help[] =
+ { "I wasn't able to read the size data for this font,",
+ "so I will ignore the font specification.",
+ "[Wizards can fix TFM files using TFtoPL/PLtoTF.]",
+ "You might try inserting a different font spec;",
+ "e.g., type `I\\font<same font id>=<substitute font name>'.",
+ NULL
+ };
+ if (int_par(suppress_fontnotfound_error_code) == 0) {
+ msg = font_error_message(u, cnom, s);
+ tex_error(msg, help);
+ free(msg);
+ }
+ return 0;
+ }
+}
+
+@ TODO This function is a placeholder. There can easily appears holes in
+ the |font_tables| array, and we could attempt to reuse those
+
+@c
+int find_font_id(const char *nom, scaled s)
+{
+ int f;
+ f = new_font();
+ if ((f = do_define_font(f, nom, s, -1))) {
+ return f;
+ } else {
+ return 0;
+ }
+}
diff --git a/Build/source/texk/web2c/luatexdir/font/luafont.c b/Build/source/texk/web2c/luatexdir/font/luafont.w
index 11bafd8b1ec..bde66530fb4 100644
--- a/Build/source/texk/web2c/luatexdir/font/luafont.c
+++ b/Build/source/texk/web2c/luatexdir/font/luafont.w
@@ -1,36 +1,38 @@
-/* luafont.c
-
- Copyright 2006-2009 Taco Hoekwater <taco@luatex.org>
-
- This file is part of LuaTeX.
-
- LuaTeX 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 2 of the License, or (at your
- option) any later version.
-
- LuaTeX 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 Lesser General Public
- License for more details.
-
- You should have received a copy of the GNU General Public License along
- with LuaTeX; if not, see <http://www.gnu.org/licenses/>. */
-
-#include "luatex-api.h"
-#include <ptexlib.h>
-
-#include "nodes.h"
-
+% luafont.w
+%
+% Copyright 2006-2010 Taco Hoekwater <taco@@luatex.org>
+%
+% This file is part of LuaTeX.
+%
+% LuaTeX 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 2 of the License, or (at your
+% option) any later version.
+%
+% LuaTeX 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 Lesser General Public
+% License for more details.
+%
+% You should have received a copy of the GNU General Public License along
+% with LuaTeX; if not, see <http://www.gnu.org/licenses/>.
+
+@ @c
static const char _svn_version[] =
- "$Id: luafont.c 2448 2009-06-08 07:43:50Z taco $ $URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.40.6/source/texk/web2c/luatexdir/font/luafont.c $";
+ "$Id: luafont.w 3584 2010-04-02 17:45:55Z hhenkel $ "
+"$URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.60.0/source/texk/web2c/luatexdir/font/luafont.w $";
+
+#include "ptexlib.h"
+#include "lua/luatex-api.h"
#define noVERBOSE
const char *font_type_strings[] = { "unknown", "virtual", "real", NULL };
const char *font_format_strings[] =
{ "unknown", "type1", "type3", "truetype", "opentype", NULL };
-const char *font_embedding_strings[] = { "unknown", "no", "subset", "full", NULL };
+const char *font_embedding_strings[] =
+ { "unknown", "no", "subset", "full", NULL };
+
const char *ligature_type_strings[] =
{ "=:", "=:|", "|=:", "|=:|", "", "=:|>", "|=:>", "|=:|>", "", "", "",
"|=:|>>", NULL
@@ -96,6 +98,8 @@ const char *MATH_param_names[] = {
"RadicalDegreeBottomRaisePercent",
"MinConnectorOverlap",
"SubscriptShiftDownWithSuperscript",
+ "FractionDelimiterSize",
+ "FractionDelimiterDisplayStyleSize",
NULL,
};
@@ -107,7 +111,7 @@ static void dump_intfield(lua_State * L, const char *n, int c)
}
-static void dump_math_kerns(lua_State * L, charinfo * co, int l, int id)
+void dump_math_kerns(lua_State * L, charinfo * co, int l, int id)
{
int i;
for (i = 0; i < l; i++) {
@@ -132,7 +136,7 @@ static void dump_math_kerns(lua_State * L, charinfo * co, int l, int id)
}
-static void font_char_to_lua(lua_State * L, internalfontnumber f, charinfo * co)
+void font_char_to_lua(lua_State * L, internal_font_number f, charinfo * co)
{
int i, j;
liginfo *l;
@@ -359,7 +363,7 @@ static void write_lua_parameters(lua_State * L, int f)
lua_setfield(L, -2, "parameters");
}
-
+@ @c
static void write_lua_math_parameters(lua_State * L, int f)
{
int k;
@@ -382,8 +386,8 @@ int font_to_lua(lua_State * L, int f)
int k;
charinfo *co;
if (font_cache_id(f) > 0) {
- /* fetch the table from the registry if it was
- saved there by font_from_lua() */
+ /* fetch the table from the registry if it was
+ saved there by |font_from_lua()| */
lua_rawgeti(L, LUA_REGISTRYINDEX, font_cache_id(f));
/* fontdimens can be changed from tex code */
write_lua_parameters(L, f);
@@ -405,6 +409,10 @@ int font_to_lua(lua_State * L, int f)
lua_pushstring(L, font_fullname(f));
lua_setfield(L, -2, "fullname");
}
+ if (font_psname(f) != NULL) {
+ lua_pushstring(L, font_psname(f));
+ lua_setfield(L, -2, "psname");
+ }
if (font_encodingname(f) != NULL) {
lua_pushstring(L, font_encodingname(f));
lua_setfield(L, -2, "encodingname");
@@ -421,6 +429,8 @@ int font_to_lua(lua_State * L, int f)
lua_pushstring(L, font_embedding_strings[font_embedding(f)]);
lua_setfield(L, -2, "embedding");
+ lua_pushnumber(L, font_units_per_em(f));
+ lua_setfield(L, -2, "units_per_em");
lua_pushnumber(L, font_size(f));
lua_setfield(L, -2, "size");
lua_pushnumber(L, font_dsize(f));
@@ -440,11 +450,7 @@ int font_to_lua(lua_State * L, int f)
/* pdf parameters */
/* skip the first four for now, that are very much interal */
- /*
- if (pdf_font_size(f) != 0) {
- lua_pushnumber(L,pdf_font_size(f));
- lua_setfield(L,-2,"pdf_size");
- }
+#if 0
if (pdf_font_num(f) != 0) {
lua_pushnumber(L,pdf_font_num(f));
lua_setfield(L,-2,"pdf_num");
@@ -457,30 +463,32 @@ int font_to_lua(lua_State * L, int f)
lua_pushnumber(L,pdf_font_elink(f));
lua_setfield(L,-2,"pdf_elink");
}
- */
+#endif
/* the next one is read only */
- if (pdf_font_expand_ratio(f) != 0) {
- lua_pushnumber(L, pdf_font_expand_ratio(f));
+ if (font_expand_ratio(f) != 0) {
+ lua_pushnumber(L, font_expand_ratio(f));
lua_setfield(L, -2, "expand_ratio");
}
- if (pdf_font_shrink(f) != 0) {
- lua_pushnumber(L, pdf_font_shrink(f));
+ if (font_shrink(f) != 0) {
+ lua_pushnumber(L, font_shrink(f));
lua_setfield(L, -2, "shrink");
}
- if (pdf_font_stretch(f) != 0) {
- lua_pushnumber(L, pdf_font_stretch(f));
+ if (font_stretch(f) != 0) {
+ lua_pushnumber(L, font_stretch(f));
lua_setfield(L, -2, "stretch");
}
- if (pdf_font_step(f) != 0) {
- lua_pushnumber(L, pdf_font_step(f));
+ if (font_step(f) != 0) {
+ lua_pushnumber(L, font_step(f));
lua_setfield(L, -2, "step");
}
- if (pdf_font_auto_expand(f) != 0) {
- lua_pushboolean(L, pdf_font_auto_expand(f));
+ if (font_auto_expand(f) != 0) {
+ lua_pushboolean(L, font_auto_expand(f));
lua_setfield(L, -2, "auto_expand");
}
if (pdf_font_attr(f) != 0) {
- lua_pushstring(L, makecstring(pdf_font_attr(f)));
+ char *s = makecstring(pdf_font_attr(f));
+ lua_pushstring(L, s);
+ free(s);
lua_setfield(L, -2, "attributes");
}
@@ -503,7 +511,7 @@ int font_to_lua(lua_State * L, int f)
}
for (k = font_bc(f); k <= font_ec(f); k++) {
- if (char_exists(f, k)) {
+ if (quick_char_exists(f, k)) {
lua_pushnumber(L, k);
co = get_charinfo(f, k);
font_char_to_lua(L, f, co);
@@ -513,9 +521,9 @@ int font_to_lua(lua_State * L, int f)
lua_setfield(L, -2, "characters");
if (font_cache_id(f) == 0) { /* renew */
- integer r;
+ int r;
lua_pushvalue(L, -1);
- r = luaL_ref(Luas, LUA_REGISTRYINDEX); /* pops the table */
+ r = luaL_ref(L, LUA_REGISTRYINDEX); /* pops the table */
set_font_cache_id(f, r);
}
return 1;
@@ -541,9 +549,10 @@ static int count_hash_items(lua_State * L, int name_index)
return n;
}
+@ @c
#define streq(a,b) (strcmp(a,b)==0)
-#define append_packet(k) { cpackets[np++] = k; }
+#define append_packet(k) { cpackets[np++] = (eight_bits)(k); }
#define do_store_four(l) { \
append_packet((l&0xFF000000)>>24); \
@@ -581,7 +590,8 @@ static int n_numeric_field(lua_State * L, int name_index, int dflt)
}
-static int enum_field(lua_State * L, const char *name, int dflt, const char **values)
+static int enum_field(lua_State * L, const char *name, int dflt,
+ const char **values)
{
int k;
const char *s;
@@ -589,7 +599,7 @@ static int enum_field(lua_State * L, const char *name, int dflt, const char **va
lua_pushstring(L, name);
lua_rawget(L, -2);
if (lua_isnumber(L, -1)) {
- i = lua_tonumber(L, -1);
+ lua_number2int(i, lua_tonumber(L, -1));
} else if (lua_isstring(L, -1)) {
s = lua_tostring(L, -1);
k = 0;
@@ -646,7 +656,7 @@ static char *string_field(lua_State * L, const char *name, const char *dflt)
return i;
}
-static char *n_string_field(lua_State * L, int name_index, const char *dflt)
+static char *n_string_field(lua_State * L, int name_index, char *dflt)
{
char *i;
lua_rawgeti(L, LUA_REGISTRYINDEX, name_index); /* fetch the stringptr */
@@ -662,10 +672,10 @@ static char *n_string_field(lua_State * L, int name_index, const char *dflt)
return i;
}
-#define init_luaS_index(a) do { \
- lua_pushliteral(L,#a); \
- luaS_##a##_ptr = lua_tostring(L,-1); \
- luaS_##a##_index = luaL_ref (L,LUA_REGISTRYINDEX); \
+#define init_luaS_index(a) do { \
+ lua_pushliteral(L,#a); \
+ luaS_##a##_ptr = lua_tostring(L,-1); \
+ luaS_##a##_index = luaL_ref (L,LUA_REGISTRYINDEX); \
} while (0)
#define make_luaS_index(a) \
@@ -729,7 +739,7 @@ make_luaS_index(vert_variants);
make_luaS_index(mathkern);
make_luaS_index(commands);
-static void init_font_string_pointers(lua_State * L)
+void init_font_string_pointers(lua_State * L)
{
init_luaS_index(width);
init_luaS_index(height);
@@ -827,7 +837,7 @@ static int count_char_packet_bytes(lua_State * L)
(void) lua_tolstring(L, -1, &len);
lua_pop(L, 1);
if (len > 0) {
- l = l + 5 + len;
+ l = (int) (l + 5 + (int) len);
}
} else if (luaS_ptr_eq(s, image)) {
l += 5;
@@ -846,7 +856,7 @@ static int count_char_packet_bytes(lua_State * L)
-static scaled sp_to_dvi(halfword sp, halfword atsize)
+scaled sp_to_dvi(halfword sp, halfword atsize)
{
double result, mult;
mult = (double) (atsize / 65536.0);
@@ -854,15 +864,15 @@ static scaled sp_to_dvi(halfword sp, halfword atsize)
return floor(result / mult);
}
-
+@ @c
static void
-read_char_packets(lua_State * L, integer * l_fonts, charinfo * co, int atsize)
+read_char_packets(lua_State * L, int *l_fonts, charinfo * co, int atsize)
{
int i, n, m;
size_t l;
int cmd;
const char *s;
- real_eight_bits *cpackets;
+ eight_bits *cpackets;
int ff = 0;
int np = 0;
int max_f = 0;
@@ -874,7 +884,7 @@ read_char_packets(lua_State * L, integer * l_fonts, charinfo * co, int atsize)
while (l_fonts[(max_f + 1)] != 0)
max_f++;
- cpackets = xmalloc(pc + 1);
+ cpackets = xmalloc((unsigned) (pc + 1));
for (i = 1; i <= (int) lua_objlen(L, -1); i++) {
lua_rawgeti(L, -1, i);
if (lua_istable(L, -1)) {
@@ -895,10 +905,10 @@ read_char_packets(lua_State * L, integer * l_fonts, charinfo * co, int atsize)
} else if (luaS_ptr_eq(s, slot)) {
cmd = packet_nop_code;
lua_rawgeti(L, -2, 2);
- n = lua_tointeger(L, -1);
+ n = (int) lua_tointeger(L, -1);
ff = (n > max_f ? l_fonts[1] : l_fonts[n]);
lua_rawgeti(L, -3, 3);
- n = lua_tointeger(L, -1);
+ n = (int) lua_tointeger(L, -1);
lua_pop(L, 2);
append_packet(packet_font_code);
do_store_four(ff);
@@ -932,7 +942,7 @@ read_char_packets(lua_State * L, integer * l_fonts, charinfo * co, int atsize)
case packet_font_code:
append_packet(cmd);
lua_rawgeti(L, -2, 2);
- n = lua_tointeger(L, -1);
+ n = (int) lua_tointeger(L, -1);
ff = (n > max_f ? l_fonts[1] : l_fonts[n]);
do_store_four(ff);
lua_pop(L, 1);
@@ -947,7 +957,7 @@ read_char_packets(lua_State * L, integer * l_fonts, charinfo * co, int atsize)
case packet_char_code:
append_packet(cmd);
lua_rawgeti(L, -2, 2);
- n = lua_tointeger(L, -1);
+ n = (int) lua_tointeger(L, -1);
do_store_four(n);
lua_pop(L, 1);
break;
@@ -955,17 +965,17 @@ read_char_packets(lua_State * L, integer * l_fonts, charinfo * co, int atsize)
case packet_down_code:
append_packet(cmd);
lua_rawgeti(L, -2, 2);
- n = lua_tointeger(L, -1);
+ n = (int) lua_tointeger(L, -1);
do_store_four(sp_to_dvi(n, atsize));
lua_pop(L, 1);
break;
case packet_rule_code:
append_packet(cmd);
lua_rawgeti(L, -2, 2);
- n = lua_tointeger(L, -1);
+ n = (int) lua_tointeger(L, -1);
do_store_four(sp_to_dvi(n, atsize));
lua_rawgeti(L, -3, 3);
- n = lua_tointeger(L, -1);
+ n = (int) lua_tointeger(L, -1);
do_store_four(sp_to_dvi(n, atsize));
lua_pop(L, 2);
break;
@@ -1021,6 +1031,7 @@ read_char_packets(lua_State * L, integer * l_fonts, charinfo * co, int atsize)
}
+@ @c
static void read_lua_cidinfo(lua_State * L, int f)
{
int i;
@@ -1040,6 +1051,7 @@ static void read_lua_cidinfo(lua_State * L, int f)
}
+@ @c
static void read_lua_parameters(lua_State * L, int f)
{
int i, n;
@@ -1051,7 +1063,7 @@ static void read_lua_parameters(lua_State * L, int f)
lua_pushnil(L); /* first key */
while (lua_next(L, -2) != 0) {
if (lua_isnumber(L, -2)) {
- i = lua_tonumber(L, -2);
+ lua_number2int(i, lua_tonumber(L, -2));
if (i > n)
n = i;
}
@@ -1071,7 +1083,7 @@ static void read_lua_parameters(lua_State * L, int f)
lua_pushnil(L); /* first key */
while (lua_next(L, -2) != 0) {
if (lua_isnumber(L, -2)) {
- i = lua_tointeger(L, -2);
+ i = (int) lua_tointeger(L, -2);
if (i >= 8) {
n = (lua_isnumber(L, -1) ? lua_roundnumber(L, -1) : 0);
set_font_param(f, i, n);
@@ -1102,6 +1114,7 @@ static void read_lua_parameters(lua_State * L, int f)
}
+@ @c
static void read_lua_math_parameters(lua_State * L, int f)
{
int i = 0, n = 0;
@@ -1110,11 +1123,11 @@ static void read_lua_math_parameters(lua_State * L, int f)
lua_pushnil(L);
while (lua_next(L, -2) != 0) {
if (lua_isnumber(L, -2)) {
- i = lua_tonumber(L, -2);
+ lua_number2int(i, lua_tonumber(L, -2));
} else if (lua_isstring(L, -2)) {
i = luaL_checkoption(L, -2, NULL, MATH_param_names);
}
- n = lua_tonumber(L, -1);
+ lua_number2int(n, lua_tonumber(L, -1));
if (i != 0) {
set_font_math_param(f, i, n);
}
@@ -1124,27 +1137,30 @@ static void read_lua_math_parameters(lua_State * L, int f)
lua_pop(L, 1);
}
+@ @c
#define MIN_INF -0x7FFFFFFF
static void store_math_kerns(lua_State * L, charinfo * co, int id)
{
- int l, k;
+ int l, k, i;
scaled ht, krn;
- if (lua_istable(L, -1) && ((k = lua_objlen(L, -1)) > 0)) {
+ if (lua_istable(L, -1) && ((k = (int) lua_objlen(L, -1)) > 0)) {
for (l = 0; l < k; l++) {
lua_rawgeti(L, -1, (l + 1));
if (lua_istable(L, -1)) {
lua_getfield(L, -1, "height");
if (lua_isnumber(L, -1)) {
- ht = (scaled) lua_tonumber(L, -1);
+ lua_number2int(i, lua_tonumber(L, -1));
+ ht = (scaled) i;
} else {
ht = MIN_INF;
}
lua_pop(L, 1);
lua_getfield(L, -1, "kern");
if (lua_isnumber(L, -1)) {
- krn = (scaled) lua_tonumber(L, -1);
+ lua_number2int(i, lua_tonumber(L, -1));
+ krn = (scaled) i;
} else {
krn = MIN_INF;
}
@@ -1157,16 +1173,17 @@ static void store_math_kerns(lua_State * L, charinfo * co, int id)
}
}
-static void
-font_char_from_lua(lua_State * L, internal_font_number f, integer i,
- integer * l_fonts)
+@ @c
+void
+font_char_from_lua(lua_State * L, internal_font_number f, int i,
+ int *l_fonts, boolean has_math)
{
int k, r, t;
charinfo *co;
kerninfo *ckerns;
liginfo *cligs;
scaled j;
- char *s;
+ const char *s;
int nl = 0; /* number of ligature table items */
int nk = 0; /* number of kern table items */
int ctr = 0;
@@ -1182,10 +1199,6 @@ font_char_from_lua(lua_State * L, internal_font_number f, integer i,
set_charinfo_depth(co, j);
j = n_numeric_field(L, luaS_italic_index, 0);
set_charinfo_italic(co, j);
- j = n_numeric_field(L, luaS_top_accent_index, 0);
- set_charinfo_top_accent(co, j);
- j = n_numeric_field(L, luaS_bot_accent_index, 0);
- set_charinfo_bot_accent(co, j);
j = n_numeric_field(L, luaS_index_index, 0);
set_charinfo_index(co, j);
j = n_numeric_field(L, luaS_expansion_factor_index, 0);
@@ -1197,117 +1210,131 @@ font_char_from_lua(lua_State * L, internal_font_number f, integer i,
k = n_boolean_field(L, luaS_used_index, 0);
set_charinfo_used(co, k);
s = n_string_field(L, luaS_name_index, NULL);
- set_charinfo_name(co, s);
+ if (s != NULL)
+ set_charinfo_name(co, xstrdup(s));
+ else
+ set_charinfo_name(co, NULL);
s = n_string_field(L, luaS_tounicode_index, NULL);
- set_charinfo_tounicode(co, s);
- k = n_numeric_field(L, luaS_next_index, -1);
- if (k >= 0) {
- set_charinfo_tag(co, list_tag);
- set_charinfo_remainder(co, k);
- }
-
- lua_rawgeti(L, LUA_REGISTRYINDEX, luaS_extensible_index);
- lua_rawget(L, -2);
- if (lua_istable(L, -1)) {
- int top, bot, mid, rep;
- top = n_numeric_field(L, luaS_top_index, 0);
- bot = n_numeric_field(L, luaS_bot_index, 0);
- mid = n_numeric_field(L, luaS_mid_index, 0);
- rep = n_numeric_field(L, luaS_rep_index, 0);
- if (top != 0 || bot != 0 || mid != 0 || rep != 0) {
- set_charinfo_tag(co, ext_tag);
- set_charinfo_extensible(co, top, bot, mid, rep);
- } else {
- pdftex_warn
- ("lua-loaded font %s char [U+%X] has an invalid extensible field!",
- font_name(f), (int) i);
+ if (s != NULL)
+ set_charinfo_tounicode(co, xstrdup(s));
+ else
+ set_charinfo_tounicode(co, NULL);
+
+ if (has_math) {
+ j = n_numeric_field(L, luaS_top_accent_index, 0);
+ set_charinfo_top_accent(co, j);
+ j = n_numeric_field(L, luaS_bot_accent_index, 0);
+ set_charinfo_bot_accent(co, j);
+ k = n_numeric_field(L, luaS_next_index, -1);
+ if (k >= 0) {
+ set_charinfo_tag(co, list_tag);
+ set_charinfo_remainder(co, k);
}
- }
- lua_pop(L, 1);
- lua_rawgeti(L, LUA_REGISTRYINDEX, luaS_horiz_variants_index);
- lua_rawget(L, -2);
- if (lua_istable(L, -1)) {
- int glyph, startconnect, endconnect, advance, extender;
- extinfo *h;
- set_charinfo_tag(co, ext_tag);
- set_charinfo_hor_variants(co, NULL);
- for (k = 1;; k++) {
- lua_rawgeti(L, -1, k);
- if (lua_istable(L, -1)) {
- glyph = n_numeric_field(L, luaS_glyph_index, 0);
- extender = n_numeric_field(L, luaS_extender_index, 0);
- startconnect = n_numeric_field(L, luaS_start_index, 0);
- endconnect = n_numeric_field(L, luaS_end_index, 0);
- advance = n_numeric_field(L, luaS_advance_index, 0);
- h = new_variant(glyph, startconnect, endconnect, advance,
- extender);
- add_charinfo_hor_variant(co, h);
- lua_pop(L, 1);
+ lua_rawgeti(L, LUA_REGISTRYINDEX, luaS_extensible_index);
+ lua_rawget(L, -2);
+ if (lua_istable(L, -1)) {
+ int top, bot, mid, rep;
+ top = n_numeric_field(L, luaS_top_index, 0);
+ bot = n_numeric_field(L, luaS_bot_index, 0);
+ mid = n_numeric_field(L, luaS_mid_index, 0);
+ rep = n_numeric_field(L, luaS_rep_index, 0);
+ if (top != 0 || bot != 0 || mid != 0 || rep != 0) {
+ set_charinfo_tag(co, ext_tag);
+ set_charinfo_extensible(co, top, bot, mid, rep);
} else {
- lua_pop(L, 1);
- break;
+ pdftex_warn
+ ("lua-loaded font %s char [U+%X] has an invalid extensible field!",
+ font_name(f), (int) i);
}
}
- }
- lua_pop(L, 1);
+ lua_pop(L, 1);
- lua_rawgeti(L, LUA_REGISTRYINDEX, luaS_vert_variants_index);
- lua_rawget(L, -2);
- if (lua_istable(L, -1)) {
- int glyph, startconnect, endconnect, advance, extender;
- extinfo *h;
- set_charinfo_tag(co, ext_tag);
- set_charinfo_vert_variants(co, NULL);
- for (k = 1;; k++) {
- lua_rawgeti(L, -1, k);
- if (lua_istable(L, -1)) {
- glyph = n_numeric_field(L, luaS_glyph_index, 0);
- extender = n_numeric_field(L, luaS_extender_index, 0);
- startconnect = n_numeric_field(L, luaS_start_index, 0);
- endconnect = n_numeric_field(L, luaS_end_index, 0);
- advance = n_numeric_field(L, luaS_advance_index, 0);
- h = new_variant(glyph, startconnect, endconnect, advance,
- extender);
- add_charinfo_vert_variant(co, h);
- lua_pop(L, 1);
- } else {
- lua_pop(L, 1);
- break;
+ lua_rawgeti(L, LUA_REGISTRYINDEX, luaS_horiz_variants_index);
+ lua_rawget(L, -2);
+ if (lua_istable(L, -1)) {
+ int glyph, startconnect, endconnect, advance, extender;
+ extinfo *h;
+ set_charinfo_tag(co, ext_tag);
+ set_charinfo_hor_variants(co, NULL);
+ for (k = 1;; k++) {
+ lua_rawgeti(L, -1, k);
+ if (lua_istable(L, -1)) {
+ glyph = n_numeric_field(L, luaS_glyph_index, 0);
+ extender = n_numeric_field(L, luaS_extender_index, 0);
+ startconnect = n_numeric_field(L, luaS_start_index, 0);
+ endconnect = n_numeric_field(L, luaS_end_index, 0);
+ advance = n_numeric_field(L, luaS_advance_index, 0);
+ h = new_variant(glyph, startconnect, endconnect,
+ advance, extender);
+ add_charinfo_hor_variant(co, h);
+ lua_pop(L, 1);
+ } else {
+ lua_pop(L, 1);
+ break;
+ }
}
}
- }
- lua_pop(L, 1);
-
- /* Here is a complete example:
- ["mathkern"]={
- ["bottom_left"] ={ { ["height"]=420, ["kern"]=80 }, { ["height"]=520, ["kern"]=4 } },
- ["bottom_right"]={ { ["height"]=0, ["kern"]=48 } },
- ["top_left"] ={ { ["height"]=620, ["kern"]=0 }, { ["height"]=720, ["kern"]=-80 } },
- ["top_right"] ={ { ["height"]=676, ["kern"]=115 }, { ["height"]=776, ["kern"]=45 } },
- }
- */
- lua_rawgeti(L, LUA_REGISTRYINDEX, luaS_mathkern_index);
- lua_rawget(L, -2);
- if (lua_istable(L, -1)) {
- lua_getfield(L, -1, "top_left");
- store_math_kerns(L, co, top_left_kern);
- lua_pop(L, 1);
- lua_getfield(L, -1, "top_right");
- store_math_kerns(L, co, top_right_kern);
lua_pop(L, 1);
- lua_getfield(L, -1, "bottom_right");
- store_math_kerns(L, co, bottom_right_kern);
+
+ lua_rawgeti(L, LUA_REGISTRYINDEX, luaS_vert_variants_index);
+ lua_rawget(L, -2);
+ if (lua_istable(L, -1)) {
+ int glyph, startconnect, endconnect, advance, extender;
+ extinfo *h;
+ set_charinfo_tag(co, ext_tag);
+ set_charinfo_vert_variants(co, NULL);
+ for (k = 1;; k++) {
+ lua_rawgeti(L, -1, k);
+ if (lua_istable(L, -1)) {
+ glyph = n_numeric_field(L, luaS_glyph_index, 0);
+ extender = n_numeric_field(L, luaS_extender_index, 0);
+ startconnect = n_numeric_field(L, luaS_start_index, 0);
+ endconnect = n_numeric_field(L, luaS_end_index, 0);
+ advance = n_numeric_field(L, luaS_advance_index, 0);
+ h = new_variant(glyph, startconnect, endconnect,
+ advance, extender);
+ add_charinfo_vert_variant(co, h);
+ lua_pop(L, 1);
+ } else {
+ lua_pop(L, 1);
+ break;
+ }
+ }
+ }
lua_pop(L, 1);
- lua_getfield(L, -1, "bottom_left");
- store_math_kerns(L, co, bottom_left_kern);
+
+/* Here is a complete example:
+
+ |["mathkern"]={|
+ |["bottom_left"] ={ { ["height"]=420, ["kern"]=80 }, { ["height"]=520, ["kern"]=4 } },|
+ |["bottom_right"]={ { ["height"]=0, ["kern"]=48 } },|
+ |["top_left"] ={ { ["height"]=620, ["kern"]=0 }, { ["height"]=720, ["kern"]=-80 } },|
+ |["top_right"] ={ { ["height"]=676, ["kern"]=115 }, { ["height"]=776, ["kern"]=45 } },|
+ |}|
+ */
+ lua_rawgeti(L, LUA_REGISTRYINDEX, luaS_mathkern_index);
+ lua_rawget(L, -2);
+ if (lua_istable(L, -1)) {
+ lua_getfield(L, -1, "top_left");
+ store_math_kerns(L, co, top_left_kern);
+ lua_pop(L, 1);
+ lua_getfield(L, -1, "top_right");
+ store_math_kerns(L, co, top_right_kern);
+ lua_pop(L, 1);
+ lua_getfield(L, -1, "bottom_right");
+ store_math_kerns(L, co, bottom_right_kern);
+ lua_pop(L, 1);
+ lua_getfield(L, -1, "bottom_left");
+ store_math_kerns(L, co, bottom_left_kern);
+ lua_pop(L, 1);
+ }
lua_pop(L, 1);
}
- lua_pop(L, 1);
-
+ /* end of |has_math| */
nk = count_hash_items(L, luaS_index(kerns));
if (nk > 0) {
- ckerns = xcalloc((nk + 1), sizeof(kerninfo));
+ ckerns = xcalloc((unsigned) (nk + 1), sizeof(kerninfo));
lua_rawgeti(L, LUA_REGISTRYINDEX, luaS_index(kerns));
lua_rawget(L, -2);
if (lua_istable(L, -1)) { /* there are kerns */
@@ -1316,11 +1343,12 @@ font_char_from_lua(lua_State * L, internal_font_number f, integer i,
while (lua_next(L, -2) != 0) {
k = non_boundarychar;
if (lua_isnumber(L, -2)) {
- k = lua_tonumber(L, -2); /* adjacent char */
+ lua_number2int(k, lua_tonumber(L, -2)); /* adjacent char */
if (k < 0)
k = non_boundarychar;
} else if (lua_isstring(L, -2)) {
- if (luaS_ptr_eq(lua_tostring(L, -2), right_boundary)) {
+ s = lua_tostring(L, -2);
+ if (luaS_ptr_eq(s, right_boundary)) {
k = right_boundarychar;
if (!has_right_boundary(f))
set_right_boundary(f,
@@ -1359,7 +1387,7 @@ font_char_from_lua(lua_State * L, internal_font_number f, integer i,
lua_pushnil(L); /* first key */
if (lua_next(L, -2) != 0) {
lua_pop(L, 2);
- read_char_packets(L, (integer *) l_fonts, co, atsize);
+ read_char_packets(L, (int *) l_fonts, co, atsize);
}
}
lua_pop(L, 1);
@@ -1368,7 +1396,7 @@ font_char_from_lua(lua_State * L, internal_font_number f, integer i,
nl = count_hash_items(L, luaS_index(ligatures));
if (nl > 0) {
- cligs = xcalloc((nl + 1), sizeof(liginfo));
+ cligs = xcalloc((unsigned) (nl + 1), sizeof(liginfo));
lua_rawgeti(L, LUA_REGISTRYINDEX, luaS_index(ligatures));
lua_rawget(L, -2);
if (lua_istable(L, -1)) { /* do ligs */
@@ -1377,12 +1405,13 @@ font_char_from_lua(lua_State * L, internal_font_number f, integer i,
while (lua_next(L, -2) != 0) {
k = non_boundarychar;
if (lua_isnumber(L, -2)) {
- k = lua_tonumber(L, -2); /* adjacent char */
+ lua_number2int(k, lua_tonumber(L, -2)); /* adjacent char */
if (k < 0) {
k = non_boundarychar;
}
} else if (lua_isstring(L, -2)) {
- if (luaS_ptr_eq(lua_tostring(L, -2), right_boundary)) {
+ s = lua_tostring(L, -2);
+ if (luaS_ptr_eq(s, right_boundary)) {
k = right_boundarychar;
if (!has_right_boundary(f))
set_right_boundary(f,
@@ -1396,7 +1425,8 @@ font_char_from_lua(lua_State * L, internal_font_number f, integer i,
}
if (r != -1 && k != non_boundarychar) {
t = enum_field(L, "type", 0, ligature_type_strings);
- set_ligature_item(cligs[ctr], (t * 2) + 1, k, r);
+ set_ligature_item(cligs[ctr], (char) ((t * 2) + 1), k,
+ r);
ctr++;
} else {
pdftex_warn
@@ -1422,9 +1452,9 @@ font_char_from_lua(lua_State * L, internal_font_number f, integer i,
-/* The caller has to fix the state of the lua stack when there is an error! */
-
+@ The caller has to fix the state of the lua stack when there is an error!
+@c
int font_from_lua(lua_State * L, int f)
{
int i, n, r, t;
@@ -1432,8 +1462,10 @@ int font_from_lua(lua_State * L, int f)
int bc; /* first char index */
int ec; /* last char index */
char *s;
- integer *l_fonts = NULL;
- integer save_ref = 1; /* unneeded, really */
+ const char *ss;
+ int *l_fonts = NULL;
+ int save_ref = 1; /* unneeded, really */
+ boolean no_math = false;
/* will we save a cache of the luat table? */
s = string_field(L, "cache", "yes");
@@ -1466,41 +1498,43 @@ int font_from_lua(lua_State * L, int f)
pdftex_fail("lua-loaded font [%d] has no name!", f);
return false;
}
+ s = string_field(L, "psname", NULL);
+ set_font_psname(f, s);
+ i = numeric_field(L, "units_per_em", 0);
+ set_font_units_per_em(f, i);
i = numeric_field(L, "designsize", 655360);
set_font_dsize(f, i);
i = numeric_field(L, "size", font_dsize(f));
set_font_size(f, i);
i = numeric_field(L, "checksum", 0);
- set_font_checksum(f, i);
+ set_font_checksum(f, (unsigned) i);
i = numeric_field(L, "direction", 0);
set_font_natural_dir(f, i);
i = numeric_field(L, "encodingbytes", 0);
- set_font_encodingbytes(f, i);
+ set_font_encodingbytes(f, (char) i);
i = numeric_field(L, "tounicode", 0);
- set_font_tounicode(f, i);
-
- i = numeric_field(L, "extend", 0);
- if (i < -2000)
- i = -2000;
- if (i > 2000)
- i = 2000;
- if (i == 1000)
- i = 0;
+ set_font_tounicode(f, (char) i);
+
+ i = numeric_field(L, "extend", 1000);
+ if (i < FONT_EXTEND_MIN)
+ i = FONT_EXTEND_MIN;
+ if (i > FONT_EXTEND_MAX)
+ i = FONT_EXTEND_MAX;
set_font_extend(f, i);
i = numeric_field(L, "slant", 0);
- if (i < -1000)
- i = -1000;
- if (i > 1000)
- i = 1000;
+ if (i < FONT_SLANT_MIN)
+ i = FONT_SLANT_MIN;
+ if (i > FONT_SLANT_MAX)
+ i = FONT_SLANT_MAX;
set_font_slant(f, i);
- i = numeric_field(L, "hyphenchar", get_default_hyphen_char());
+ i = numeric_field(L, "hyphenchar", int_par(default_hyphen_char_code));
set_hyphen_char(f, i);
- i = numeric_field(L, "skewchar", get_default_skew_char());
+ i = numeric_field(L, "skewchar", int_par(default_skew_char_code));
set_skew_char(f, i);
i = boolean_field(L, "used", 0);
- set_font_used(f, i);
+ set_font_used(f, (char) i);
s = string_field(L, "attributes", NULL);
if (s != NULL && strlen(s) > 0) {
@@ -1523,9 +1557,8 @@ int font_from_lua(lua_State * L, int f)
/* now fetch the base fonts, if needed */
n = count_hash_items(L, luaS_index(fonts));
if (n > 0) {
- const char *cs;
- l_fonts = xmalloc((n + 2) * sizeof(integer));
- memset(l_fonts, 0, (n + 2) * sizeof(integer));
+ l_fonts = xmalloc((unsigned) ((unsigned) (n + 2) * sizeof(int)));
+ memset(l_fonts, 0, (size_t) ((unsigned) (n + 2) * sizeof(int)));
lua_rawgeti(L, LUA_REGISTRYINDEX, luaS_index(fonts));
lua_rawget(L, -2);
for (i = 1; i <= n; i++) {
@@ -1533,33 +1566,33 @@ int font_from_lua(lua_State * L, int f)
if (lua_istable(L, -1)) {
lua_getfield(L, -1, "id");
if (lua_isnumber(L, -1)) {
- l_fonts[i] = lua_tonumber(L, -1);
+ lua_number2int(l_fonts[i], lua_tonumber(L, -1));
lua_pop(L, 2); /* pop id and entry */
continue;
}
lua_pop(L, 1); /* pop id */
};
- cs = NULL;
+ ss = NULL;
if (lua_istable(L, -1)) {
lua_getfield(L, -1, "name");
if (lua_isstring(L, -1)) {
- cs = lua_tostring(L, -1);
+ ss = lua_tostring(L, -1);
}
lua_pop(L, 1); /* pop name */
}
- if (cs != NULL) {
+ if (ss != NULL) {
lua_getfield(L, -1, "size");
t = (lua_isnumber(L, -1) ? lua_roundnumber(L, -1) : -1000);
lua_pop(L, 1);
- /* TODO: the stack is messed up, otherwise this
- * explicit resizing would not be needed
+ /* TODO: the stack is messed up, otherwise this
+ * explicit resizing would not be needed
*/
s_top = lua_gettop(L);
- if (strcmp(font_name(f), s) == 0)
+ if (strcmp(font_name(f), ss) == 0)
l_fonts[i] = f;
else
- l_fonts[i] = find_font_id(s, t);
+ l_fonts[i] = find_font_id(ss, t);
lua_settop(L, s_top);
} else {
pdftex_fail("Invalid local font in font %s!\n", font_name(f));
@@ -1571,7 +1604,7 @@ int font_from_lua(lua_State * L, int f)
if (font_type(f) == virtual_font_type) {
pdftex_fail("Invalid local fonts in font %s!\n", font_name(f));
} else {
- l_fonts = xmalloc(3 * sizeof(integer));
+ l_fonts = xmalloc(3 * sizeof(int));
l_fonts[0] = 0;
l_fonts[1] = f;
l_fonts[2] = 0;
@@ -1579,22 +1612,28 @@ int font_from_lua(lua_State * L, int f)
}
/* parameters */
+ no_math = boolean_field(L, "nomath", 0);
read_lua_parameters(L, f);
- read_lua_math_parameters(L, f);
+ if (!no_math) {
+ read_lua_math_parameters(L, f);
+ }
read_lua_cidinfo(L, f);
/* characters */
+
lua_getfield(L, -1, "characters");
if (lua_istable(L, -1)) {
/* find the array size values */
+ int num = 0; /* number of charinfo's to add */
ec = 0;
bc = -1;
lua_pushnil(L); /* first key */
while (lua_next(L, -2) != 0) {
if (lua_isnumber(L, -2)) {
- i = lua_tointeger(L, -2);
+ i = (int) lua_tointeger(L, -2);
if (i >= 0) {
if (lua_istable(L, -1)) {
+ num++;
if (i > ec)
ec = i;
if (bc < 0)
@@ -1606,31 +1645,35 @@ int font_from_lua(lua_State * L, int f)
}
lua_pop(L, 1);
}
-
if (bc != -1) {
- /* fprintf(stdout,"defined a font at %d with %d-%d\n",f,bc,ec); */
+#if 0
+ fprintf(stdout,"defined a font at %d with %d-%d\n",f,bc,ec);
+#endif
+ font_malloc_charinfo(f, num);
set_font_bc(f, bc);
set_font_ec(f, ec);
lua_pushnil(L); /* first key */
while (lua_next(L, -2) != 0) {
if (lua_isnumber(L, -2)) {
- i = lua_tonumber(L, -2);
+ lua_number2int(i, lua_tonumber(L, -2));
if (i >= 0) {
- font_char_from_lua(L, f, i, l_fonts);
+ font_char_from_lua(L, f, i, l_fonts, !no_math);
}
} else if (lua_isstring(L, -2)) {
- const char *cs = lua_tostring(L, -2);
- if (luaS_ptr_eq(cs, left_boundary)) {
- font_char_from_lua(L, f, left_boundarychar, l_fonts);
- } else if (luaS_ptr_eq(cs, right_boundary)) {
- font_char_from_lua(L, f, right_boundarychar, l_fonts);
+ const char *ss = lua_tostring(L, -2);
+ if (luaS_ptr_eq(ss, left_boundary)) {
+ font_char_from_lua(L, f, left_boundarychar, l_fonts,
+ !no_math);
+ } else if (luaS_ptr_eq(ss, right_boundary)) {
+ font_char_from_lua(L, f, right_boundarychar, l_fonts,
+ !no_math);
}
}
lua_pop(L, 1);
}
lua_pop(L, 1);
- /* handle font expansion last: the |copy_font| routine is called eventually,
+ /* handle font expansion last: the |copy_font| routine is called eventually,
and that needs to know |bc| and |ec|. */
if (font_type(f) != virtual_font_type) {
int fstep = numeric_field(L, "step", 0);
@@ -1666,10 +1709,10 @@ int font_from_lua(lua_State * L, int f)
}
if (save_ref > 0) {
- r = luaL_ref(Luas, LUA_REGISTRYINDEX); /* pops the table */
+ r = luaL_ref(L, LUA_REGISTRYINDEX); /* pops the table */
set_font_cache_id(f, r);
} else {
- lua_pop(Luas, 1);
+ lua_pop(L, 1);
set_font_cache_id(f, save_ref);
}
} else { /* jikes, no characters */
@@ -1682,23 +1725,24 @@ int font_from_lua(lua_State * L, int f)
return true;
}
-/* ====================================================================
- *
- * L I G A T U R I N G
- *
- * ==================================================================== */
+@* Ligaturing.
+
+@c
#define assert_disc(a) \
- assert(pre_break(a)!=null); /* expect head_node */ \
+ assert(pre_break(a)!=null); /* expect |head_node| */ \
assert(type(pre_break(a))==nesting_node); \
- assert((vlink_pre_break(a)==null && tlink_pre_break(a)==null) || tail_of_list(vlink_pre_break(a))==tlink_pre_break(a)); \
- assert(post_break(a)!=null); /* expect head_node */ \
+ assert((vlink_pre_break(a)==null && tlink_pre_break(a)==null) || \
+ tail_of_list(vlink_pre_break(a))==tlink_pre_break(a)); \
+ assert(post_break(a)!=null); /* expect |head_node| */ \
assert(type(post_break(a))==nesting_node); \
- assert((vlink_post_break(a)==null && tlink_post_break(a)==null) || tail_of_list(vlink_post_break(a))==tlink_post_break(a)); \
- assert(no_break(a)!=null); /* expect head_node */ \
+ assert((vlink_post_break(a)==null && tlink_post_break(a)==null) || \
+ tail_of_list(vlink_post_break(a))==tlink_post_break(a)); \
+ assert(no_break(a)!=null); /* expect |head_node| */ \
assert(type(no_break(a))==nesting_node); \
- assert((vlink_no_break(a)==null && tlink_no_break(a)==null) || tail_of_list(vlink_no_break(a))==tlink_no_break(a));
+ assert((vlink_no_break(a)==null && tlink_no_break(a)==null) || \
+ tail_of_list(vlink_no_break(a))==tlink_no_break(a));
static void nesting_append(halfword nest, halfword newn)
{
@@ -1785,7 +1829,7 @@ static int try_ligature(halfword * frst, halfword fwd)
set_is_ligature(newgl);
/* below might not be correct in contrived border case.
- * but we use it only for debugging, so ... */
+ but we use it only for debugging, so ... */
if (character(cur) < 0) {
set_is_leftboundary(newgl);
}
@@ -1805,8 +1849,8 @@ static int try_ligature(halfword * frst, halfword fwd)
}
/* TODO/FIXME if this ligature is consists of another ligature
- * we should add it's lig_ptr to the new glyphs lig_ptr (and
- * cleanup the no longer needed node) LOW PRIORITY */
+ we should add it's |lig_ptr| to the new glyphs |lig_ptr| (and
+ cleanup the no longer needed node) LOW PRIORITY */
/* left side */
if (keep_left) {
halfword new_first = copy_node(cur);
@@ -1827,7 +1871,7 @@ static int try_ligature(halfword * frst, halfword fwd)
/* right side */
if (keep_right) {
halfword new_second = copy_node(fwd);
- /* correct, because we _know_ lig_ptr points to _one_ node */
+ /* correct, because we {\it know\/} |lig_ptr| points to {\it one\/} node */
couple_nodes(lig_ptr(newgl), new_second);
couple_nodes(newgl, fwd);
if (move_after) {
@@ -1837,7 +1881,7 @@ static int try_ligature(halfword * frst, halfword fwd)
} else {
halfword next = vlink(fwd);
uncouple_node(fwd);
- /* correct, because we _know_ lig_ptr points to _one_ node */
+ /* correct, because we {\it know\/} |lig_ptr| points to {\it one\/} node */
couple_nodes(lig_ptr(newgl), fwd);
if (next != null) {
couple_nodes(newgl, next);
@@ -1845,7 +1889,6 @@ static int try_ligature(halfword * frst, halfword fwd)
}
/* check and return */
- /* assert(move_after==0); */
*frst = cur;
return 1;
}
@@ -1853,9 +1896,11 @@ static int try_ligature(halfword * frst, halfword fwd)
}
-/* there shouldn't be any ligatures here - we only add them at the end of
- * xxx_break in a DISC-1 - DISC-2 situation and we stop processing DISC-1
- * (we continue with DISC-1's post_ and no_break */
+@ there shouldn't be any ligatures here - we only add them at the end of
+ |xxx_break| in a \.{DISC-1 - DISC-2} situation and we stop processing \.{DISC-1}
+ (we continue with \.{DISC-1}'s |post_| and |no_break|.
+
+@c
static halfword handle_lig_nest(halfword root, halfword cur)
{
if (cur == null)
@@ -1876,11 +1921,10 @@ static halfword handle_lig_nest(halfword root, halfword cur)
static halfword handle_lig_word(halfword cur)
{
halfword right = null;
-
if (type(cur) == whatsit_node && subtype(cur) == cancel_boundary_node) {
halfword prev = alink(cur);
halfword fwd = vlink(cur);
- /* uncouple_node(cur); *//* not needed, it is freed */
+ /* no need to uncouple |cur|, it is freed */
flush_node(cur);
if (fwd == null) {
vlink(prev) = fwd;
@@ -1900,7 +1944,6 @@ static halfword handle_lig_word(halfword cur)
if (has_right_boundary(font(cur))) {
right = new_glyph(font(cur), right_boundarychar);
}
-
while (1) {
/* A glyph followed by ... */
if (type(cur) == glyph_node) {
@@ -1908,20 +1951,20 @@ static halfword handle_lig_word(halfword cur)
if (fwd == null) { /* last character of paragraph */
if (right == null)
break;
- /* --\par prohibits use of couple_nodes here */
+ /* \.{--\\par} prohibits use of |couple_nodes| here */
try_couple_nodes(cur, right);
right = null;
continue;
}
assert(alink(fwd) == cur);
- if (type(fwd) == glyph_node) { /* GLYPH - GLYPH */
+ if (type(fwd) == glyph_node) { /* |GLYPH - GLYPH| */
if (font(cur) != font(fwd))
break;
if (try_ligature(&cur, fwd))
continue;
- } else if (type(fwd) == disc_node) { /* GLYPH - DISC */
+ } else if (type(fwd) == disc_node) { /* |GLYPH - DISC| */
- /* if a{bx}{}{y} and a+b=>B convert to {Bx}{}{ay} */
+ /* if \.{a{bx}{}{y}} and \.{a+b=>B} convert to \.{{Bx}{}{ay}} */
halfword pre = vlink_pre_break(fwd);
halfword nob = vlink_no_break(fwd);
halfword next, tail;
@@ -1939,7 +1982,7 @@ static halfword handle_lig_word(halfword cur)
uncouple_node(cur);
couple_nodes(prev, fwd);
nesting_prepend(no_break(fwd), cur);
- /* now ligature the pre_break */
+ /* now ligature the |pre_break| */
nesting_prepend(pre_break(fwd), copy_node(cur));
/* As we have removed cur, we need to start again ... */
cur = prev;
@@ -1948,27 +1991,27 @@ static halfword handle_lig_word(halfword cur)
next = vlink(fwd);
if (nob == null && next != null && type(next) == glyph_node
&& test_ligature(&lig, cur, next)) {
- /* move cur from before disc to no_break part */
+ /* move |cur| from before |disc| to |no_break| part */
halfword prev = alink(cur);
assert(alink(next) == fwd);
assert(vlink(prev) == cur);
uncouple_node(cur);
couple_nodes(prev, fwd);
- couple_nodes(no_break(fwd), cur); /* we _know_ it's empty */
- /* now copy cur the pre_break */
+ couple_nodes(no_break(fwd), cur); /* we {\it know\/} it's empty */
+ /* now copy cur the |pre_break| */
nesting_prepend(pre_break(fwd), copy_node(cur));
- /* move next from after disc to no_break part */
+ /* move next from after disc to |no_break| part */
tail = vlink(next);
uncouple_node(next);
try_couple_nodes(fwd, tail);
- couple_nodes(cur, next); /* we _know_ this works */
+ couple_nodes(cur, next); /* we {\it know\/} this works */
tlink(no_break(fwd)) = next; /* and make sure the list is correct */
- /* now copy next to the post_break */
+ /* now copy next to the |post_break| */
nesting_append(post_break(fwd), copy_node(next));
/* As we have removed cur, we need to start again ... */
cur = prev;
}
- /* we are finished with the pre_break */
+ /* we are finished with the |pre_break| */
handle_lig_nest(pre_break(fwd), vlink_pre_break(fwd));
} else if (type(fwd) == whatsit_node
&& subtype(fwd) == cancel_boundary_node) {
@@ -1977,7 +2020,7 @@ static halfword handle_lig_word(halfword cur)
flush_node(fwd);
if (right != null) {
flush_node(right); /* Shame, didn't need it */
- /* right = null; *//* no need, we're going to leave the loop anyway */
+ /* no need to reset |right|, we're going to leave the loop anyway */
}
break;
} else { /* fwd is something unknown */
@@ -1992,10 +2035,21 @@ static halfword handle_lig_word(halfword cur)
} else if (type(cur) == disc_node) {
assert_disc(cur);
- /* If {?}{x}{?} or {?}{?}{y} then ... */
+ /* If \.{{?}{x}{?}} or \.{{?}{?}{y}} then ... */
if (vlink_no_break(cur) != null || vlink_post_break(cur) != null) {
+ halfword prev = 0;
halfword fwd;
liginfo lig;
+ if (subtype(cur) == select_disc) {
+ prev = alink(cur);
+ assert(type(prev) == disc_node
+ && subtype(prev) == init_disc);
+ if (vlink_post_break(cur) != null)
+ handle_lig_nest(post_break(prev),
+ vlink_post_break(prev));
+ if (vlink_no_break(cur) != null)
+ handle_lig_nest(no_break(prev), vlink_no_break(prev));
+ }
if (vlink_post_break(cur) != null)
handle_lig_nest(post_break(cur), vlink_post_break(cur));
if (vlink_no_break(cur) != null)
@@ -2004,13 +2058,40 @@ static halfword handle_lig_word(halfword cur)
halfword nob, pst, next;
if (type(fwd) != glyph_node)
break;
- nob = tlink_no_break(cur);
- pst = tlink_post_break(cur);
- if ((nob == null || !test_ligature(&lig, nob, fwd)) &&
- (pst == null || !test_ligature(&lig, pst, fwd)))
- break;
- nesting_append(no_break(cur), copy_node(fwd));
- handle_lig_nest(no_break(cur), nob);
+ if (subtype(cur) != select_disc) {
+ nob = tlink_no_break(cur);
+ pst = tlink_post_break(cur);
+ if ((nob == null || !test_ligature(&lig, nob, fwd)) &&
+ (pst == null || !test_ligature(&lig, pst, fwd)))
+ break;
+ nesting_append(no_break(cur), copy_node(fwd));
+ handle_lig_nest(no_break(cur), nob);
+ } else {
+ int dobreak = 0;
+ nob = tlink_no_break(prev);
+ pst = tlink_post_break(prev);
+ if ((nob == null || !test_ligature(&lig, nob, fwd)) &&
+ (pst == null || !test_ligature(&lig, pst, fwd)))
+ dobreak = 1;
+ if (!dobreak) {
+ nesting_append(no_break(prev), copy_node(fwd));
+ handle_lig_nest(no_break(prev), nob);
+ nesting_append(post_break(prev), copy_node(fwd));
+ handle_lig_nest(post_break(prev), pst);
+ }
+ dobreak = 0;
+ nob = tlink_no_break(cur);
+ pst = tlink_post_break(cur);
+ if ((nob == null || !test_ligature(&lig, nob, fwd)) &&
+ (pst == null || !test_ligature(&lig, pst, fwd)))
+ dobreak = 1;
+ if (!dobreak) {
+ nesting_append(no_break(cur), copy_node(fwd));
+ handle_lig_nest(no_break(cur), nob);
+ }
+ if (dobreak)
+ break;
+ }
next = vlink(fwd);
uncouple_node(fwd);
try_couple_nodes(cur, next);
@@ -2027,35 +2108,35 @@ static halfword handle_lig_word(halfword cur)
test_ligature(&lig, tlink_post_break(cur), next)) ||
(tlink_no_break(cur) != null &&
test_ligature(&lig, tlink_no_break(cur), next)))) {
- /* Building an init_disc followed by a select_disc
- * {a-}{b}{AB} {-}{}{} 'c'
+ /* Building an |init_disc| followed by a |select_disc|
+ \.{{a-}{b}{AB} {-}{}{}} 'c'
*/
halfword last = vlink(next), tail;
uncouple_node(next);
try_couple_nodes(fwd, last);
- /* {a-}{b}{AB} {-}{c}{} */
+ /* \.{{a-}{b}{AB} {-}{c}{}} */
nesting_append(post_break(fwd), copy_node(next));
- /* {a-}{b}{AB} {-}{c}{-} */
+ /* \.{{a-}{b}{AB} {-}{c}{-}} */
if (vlink_no_break(cur) != null) {
nesting_prepend(no_break(fwd),
copy_node(vlink_pre_break(fwd)));
}
- /* {a-}{b}{AB} {b-}{c}{-} */
+ /* \.{{a-}{b}{AB} {b-}{c}{-}} */
if (vlink_post_break(cur) != null)
nesting_prepend_list(pre_break(fwd),
copy_node_list(vlink_post_break
(cur)));
- /* {a-}{b}{AB} {b-}{c}{AB-} */
+ /* \.{{a-}{b}{AB} {b-}{c}{AB-}} */
if (vlink_no_break(cur) != null) {
nesting_prepend_list(no_break(fwd),
copy_node_list(vlink_no_break
(cur)));
}
- /* {a-}{b}{ABC} {b-}{c}{AB-} */
+ /* \.{{a-}{b}{ABC} {b-}{c}{AB-}} */
tail = tlink_no_break(cur);
nesting_append(no_break(cur), copy_node(next));
handle_lig_nest(no_break(cur), tail);
- /* {a-}{BC}{ABC} {b-}{c}{AB-} */
+ /* \.{{a-}{BC}{ABC} {b-}{c}{AB-}} */
tail = tlink_post_break(cur);
nesting_append(post_break(cur), next);
handle_lig_nest(post_break(cur), tail);
@@ -2067,14 +2148,16 @@ static halfword handle_lig_word(halfword cur)
}
} else { /* NO GLYPH NOR DISC */
- /* fprintf(stdout,"This is a %d node\n",type(cur)); */
- /* assert(0); *//* TODO howcome there can be a glue here? */
+#if 0
+ fprintf(stdout,"This is a %d node\n",type(cur));
+ assert(0); /* TODO howcome there can be a glue here? */
+#endif
return cur;
}
/* step-to-next-node */
{
halfword prev = cur;
- /* --\par allows vlink(cur) to be null */
+ /* \.{--\\par} allows |vlink(cur)| to be null */
cur = vlink(cur);
if (cur != null) {
assert(alink(cur) == prev);
@@ -2085,11 +2168,12 @@ static halfword handle_lig_word(halfword cur)
return cur;
}
-/* return = new tail, head should be a dummy */
+@ Return value is the new tail, head should be a dummy
+@c
halfword handle_ligaturing(halfword head, halfword tail)
{
- halfword save_tail; /* trick to allow explicit node==null tests */
+ halfword save_tail; /* trick to allow explicit |node==null| tests */
halfword cur, prev;
if (vlink(head) == null)
@@ -2097,7 +2181,7 @@ halfword handle_ligaturing(halfword head, halfword tail)
save_tail = vlink(tail);
vlink(tail) = null;
- /* if (fix_node_lists) */
+ /* |if (fix_node_lists)| */
fix_node_list(head);
prev = head;
@@ -2123,12 +2207,9 @@ halfword handle_ligaturing(halfword head, halfword tail)
}
-/* ====================================================================
- *
- * K E R N I N G
- *
- * ==================================================================== */
+@* Kerning.
+@c
static void add_kern_before(halfword left, halfword right)
{
if ((!is_rightghost(right)) &&
@@ -2253,12 +2334,9 @@ halfword handle_kerning(halfword head, halfword tail)
return tail;
}
-/* ====================================================================
- *
- * L I G A T U R I N G and K E R N I N G : L U A - I N T E R F A C E
- *
- * ==================================================================== */
+@* ligaturing and kerning : lua-interface.
+@c
static halfword
run_lua_ligkern_callback(halfword head, halfword tail, int callback_id)
{
diff --git a/Build/source/texk/web2c/luatexdir/font/luatexfont.h b/Build/source/texk/web2c/luatexdir/font/luatexfont.h
index 987517266ed..fa2d2ac6c6d 100644
--- a/Build/source/texk/web2c/luatexdir/font/luatexfont.h
+++ b/Build/source/texk/web2c/luatexdir/font/luatexfont.h
@@ -1,6 +1,6 @@
/* luatexfont.h --- General font definitions
- Copyright 2008 Taco Hoekwater <taco@luatex.org>
+ Copyright 2008-2010 Taco Hoekwater <taco@luatex.org>
This file is part of LuaTeX.
@@ -17,7 +17,7 @@
You should have received a copy of the GNU General Public License along
with LuaTeX; if not, see <http://www.gnu.org/licenses/>. */
-/* $Id: luatexfont.h 2332 2009-04-18 17:17:56Z hhenkel $ */
+/* $Id: luatexfont.h 3433 2010-02-20 10:03:04Z hhenkel $ */
#ifndef LUATEXFONT_H
# define LUATEXFONT_H
@@ -83,19 +83,18 @@ typedef struct {
} intparm;
typedef struct {
- integer fe_objnum; /* object number */
+ int fe_objnum; /* object number */
char *name; /* encoding file name */
char **glyph_names; /* array of glyph names */
struct avl_table *tx_tree; /* tree of encoding positions marked as used by TeX */
} fe_entry;
typedef struct fd_entry_ {
- integer fd_objnum; /* object number of the font descriptor object */
+ int fd_objnum; /* object number of the font descriptor object */
char *fontname; /* /FontName (without subset tag) */
char *subset_tag; /* 6-character subset tag */
boolean ff_found;
- integer ff_objnum; /* object number of the font program stream */
- integer fn_objnum; /* font name object number (embedded PDF) */
+ int ff_objnum; /* object number of the font program stream */
boolean all_glyphs; /* embed all glyphs? */
boolean write_ttf_glyph_names;
intparm font_dim[FONT_KEYS_NUM];
@@ -107,16 +106,16 @@ typedef struct fd_entry_ {
} fd_entry;
typedef struct fo_entry_ {
- integer fo_objnum; /* object number of the font dictionary */
- internalfontnumber tex_font; /* needed only for \pdffontattr{} */
+ int fo_objnum; /* object number of the font dictionary */
+ internal_font_number tex_font; /* needed only for \pdffontattr{} */
fm_entry *fm; /* pointer to font map structure for this font dictionary */
fd_entry *fd; /* pointer to /FontDescriptor object structure */
fe_entry *fe; /* pointer to encoding structure */
- integer cw_objnum; /* object number of the font program object */
- integer first_char; /* first character used in this font */
- integer last_char; /* last character used in this font */
+ int cw_objnum; /* object number of the font program object */
+ int first_char; /* first character used in this font */
+ int last_char; /* last character used in this font */
struct avl_table *tx_tree; /* tree of non-reencoded TeX characters marked as used */
- integer tounicode_objnum; /* object number of ToUnicode */
+ int tounicode_objnum; /* object number of ToUnicode */
} fo_entry;
typedef struct {
@@ -132,7 +131,7 @@ typedef struct glw_entry_ { /* subset glyphs for inclusion in CID-based font
} glw_entry;
typedef struct {
- integer charcode, cwidth, cheight, xoff, yoff, xescape, rastersize;
+ int charcode, cwidth, cheight, xoff, yoff, xescape, rastersize;
halfword *raster;
} chardesc;
@@ -141,41 +140,38 @@ typedef struct {
# include "texfont.h"
/* tounicode.c */
-integer write_cid_tounicode(fo_entry * fo, internalfontnumber f);
+int write_cid_tounicode(PDF, fo_entry *, internal_font_number);
void glyph_unicode_free(void);
void def_tounicode(str_number, str_number);
-integer write_tounicode(char **, char *);
+int write_tounicode(PDF, char **, char *);
/* vfpacket.c */
-void replace_packet_fonts(internal_font_number f, integer * old_fontid,
- integer * new_fontid, int count);
-integer *packet_local_fonts(internal_font_number f, integer * num);
+void replace_packet_fonts(internal_font_number f, int *old_fontid,
+ int *new_fontid, int count);
+int *packet_local_fonts(internal_font_number f, int *num);
-/* writeccf.c */
-void writetype1w(fd_entry * fd);
+/* writecff.c */
+void writetype1w(PDF pdf, fd_entry * fd);
/* writetype0.c */
-void writetype0(fd_entry * fd);
+void writetype0(PDF pdf, fd_entry * fd);
/* writefont.c */
-void do_pdf_font(integer, internalfontnumber);
-fd_entry *lookup_fd_entry(char *, integer, integer);
+void do_pdf_font(PDF, internal_font_number);
+fd_entry *lookup_fd_entry(char *);
fd_entry *new_fd_entry(void);
-void write_fontstuff(void);
-integer get_fd_objnum(fd_entry * fd);
-integer get_fn_objnum(fd_entry * fd);
-void embed_whole_font(fd_entry * fd);
+void write_fontstuff(PDF);
void register_fd_entry(fd_entry * fd);
/* writet1.c */
boolean t1_subset(char *, char *, unsigned char *);
char **load_enc_file(char *);
-void writet1(fd_entry *);
+void writet1(PDF, fd_entry *);
void t1_free(void);
-extern integer t1_length1, t1_length2, t1_length3;
+extern int t1_length1, t1_length2, t1_length3;
/* writetype2.c */
-void writetype2(fd_entry * fd);
+void writetype2(PDF, fd_entry *);
extern unsigned long cidtogid_obj;
pdf_obj *pdf_new_stream(void);
void pdf_add_stream(pdf_obj * stream, unsigned char *buf, long len);
@@ -188,37 +184,35 @@ boolean handle_subfont_fm(fm_entry *, int);
/* writeenc.c */
fe_entry *get_fe_entry(char *);
void enc_free(void);
-void write_fontencodings(void);
+void write_fontencodings(PDF pdf);
/* writettf.c */
-void writettf(fd_entry *);
-void writeotf(fd_entry *);
+void writettf(PDF, fd_entry *);
+void writeotf(PDF, fd_entry *);
void ttf_free(void);
-extern integer ttf_length;
+extern int ttf_length;
/* pkin.c */
int readchar(boolean, chardesc *);
/* macnames.c */
-extern const char notdef[];
+extern char notdef[];
/* vfovf.c */
void vf_expand_local_fonts(internal_font_number f);
internal_font_number letter_space_font(halfword u, internal_font_number f,
- integer e);
-internal_font_number auto_expand_font(internal_font_number f, integer e);
-str_number expand_font_name(internal_font_number f, integer e);
-void pdf_check_vf_cur_val(void);
+ int e);
+internal_font_number auto_expand_font(internal_font_number f, int e);
+void pdf_check_vf(internal_font_number f);
internal_font_number copy_font_info(internal_font_number f);
/* writet3.c */
extern FILE *t3_file;
-void writet3(int, internalfontnumber);
-scaled get_pk_char_width(internalfontnumber, scaled);
+void writet3(PDF, internal_font_number);
extern unsigned char *t3_buffer;
-extern integer t3_size;
-extern integer t3_curbyte;
+extern int t3_size;
+extern int t3_curbyte;
# define t3_read_file() readbinfile(t3_file, &t3_buffer, &t3_size)
# define t3_close() xfclose(t3_file, cur_file_name)
diff --git a/Build/source/texk/web2c/luatexdir/font/macnames.c b/Build/source/texk/web2c/luatexdir/font/macnames.c
deleted file mode 100644
index a62de50edcb..00000000000
--- a/Build/source/texk/web2c/luatexdir/font/macnames.c
+++ /dev/null
@@ -1,313 +0,0 @@
-/* macnames.c
-
- Copyright 1996-2006 Han The Thanh <thanh@pdftex.org>
- Copyright 2006-2008 Taco Hoekwater <taco@luatex.org>
-
- This file is part of LuaTeX.
-
- LuaTeX 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 2 of the License, or (at your
- option) any later version.
-
- LuaTeX 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 Lesser General Public
- License for more details.
-
- You should have received a copy of the GNU General Public License along
- with LuaTeX; if not, see <http://www.gnu.org/licenses/>. */
-
-static const char __svn_version[] =
- "$Id: macnames.c 2271 2009-04-12 23:42:21Z oneiros $ $URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.40.6/source/texk/web2c/luatexdir/font/macnames.c $";
-
-const char notdef[] = ".notdef";
-
-const char *mac_glyph_names[] = {
-/* 0x00 */
- notdef,
- ".null",
- "CR",
- "space",
- "exclam",
- "quotedbl",
- "numbersign",
- "dollar",
- "percent",
- "ampersand",
- "quotesingle",
- "parenleft",
- "parenright",
- "asterisk",
- "plus",
- "comma",
-/* 0x10 */
- "hyphen",
- "period",
- "slash",
- "zero",
- "one",
- "two",
- "three",
- "four",
- "five",
- "six",
- "seven",
- "eight",
- "nine",
- "colon",
- "semicolon",
- "less",
-/* 0x20 */
- "equal",
- "greater",
- "question",
- "at",
- "A",
- "B",
- "C",
- "D",
- "E",
- "F",
- "G",
- "H",
- "I",
- "J",
- "K",
- "L",
-/* 0x30 */
- "M",
- "N",
- "O",
- "P",
- "Q",
- "R",
- "S",
- "T",
- "U",
- "V",
- "W",
- "X",
- "Y",
- "Z",
- "bracketleft",
- "backslash",
-/* 0x40 */
- "bracketright",
- "asciicircum",
- "underscore",
- "grave",
- "a",
- "b",
- "c",
- "d",
- "e",
- "f",
- "g",
- "h",
- "i",
- "j",
- "k",
- "l",
-/* 0x50 */
- "m",
- "n",
- "o",
- "p",
- "q",
- "r",
- "s",
- "t",
- "u",
- "v",
- "w",
- "x",
- "y",
- "z",
- "braceleft",
- "bar",
-/* 0x60 */
- "braceright",
- "asciitilde",
- "Adieresis",
- "Aring",
- "Ccedilla",
- "Eacute",
- "Ntilde",
- "Odieresis",
- "Udieresis",
- "aacute",
- "agrave",
- "acircumflex",
- "adieresis",
- "atilde",
- "aring",
- "ccedilla",
-/* 0x70 */
- "eacute",
- "egrave",
- "ecircumflex",
- "edieresis",
- "iacute",
- "igrave",
- "icircumflex",
- "idieresis",
- "ntilde",
- "oacute",
- "ograve",
- "ocircumflex",
- "odieresis",
- "otilde",
- "uacute",
- "ugrave",
-/* 0x80 */
- "ucircumflex",
- "udieresis",
- "dagger",
- "degree",
- "cent",
- "sterling",
- "section",
- "bullet",
- "paragraph",
- "germandbls",
- "registered",
- "copyright",
- "trademark",
- "acute",
- "dieresis",
- "notequal",
-/* 0x90 */
- "AE",
- "Oslash",
- "infinity",
- "plusminus",
- "lessequal",
- "greaterequal",
- "yen",
- "mu",
- "partialdiff",
- "Sigma",
- "Pi",
- "pi",
- "integral",
- "ordfeminine",
- "ordmasculine",
- "Omega",
-/* 0xa0 */
- "ae",
- "oslash",
- "questiondown",
- "exclamdown",
- "logicalnot",
- "radical",
- "florin",
- "approxequal",
- "Delta",
- "guillemotleft",
- "guillemotright",
- "ellipsis",
- "nbspace",
- "Agrave",
- "Atilde",
- "Otilde",
-/* 0xb0 */
- "OE",
- "oe",
- "endash",
- "emdash",
- "quotedblleft",
- "quotedblright",
- "quoteleft",
- "quoteright",
- "divide",
- "lozenge",
- "ydieresis",
- "Ydieresis",
- "fraction",
- "currency",
- "guilsinglleft",
- "guilsinglright",
-/* 0xc0 */
- "fi",
- "fl",
- "daggerdbl",
- "periodcentered",
- "quotesinglbase",
- "quotedblbase",
- "perthousand",
- "Acircumflex",
- "Ecircumflex",
- "Aacute",
- "Edieresis",
- "Egrave",
- "Iacute",
- "Icircumflex",
- "Idieresis",
- "Igrave",
-/* 0xd0 */
- "Oacute",
- "Ocircumflex",
- "applelogo",
- "Ograve",
- "Uacute",
- "Ucircumflex",
- "Ugrave",
- "dotlessi",
- "circumflex",
- "tilde",
- "macron",
- "breve",
- "dotaccent",
- "ring",
- "cedilla",
- "hungarumlaut",
-/* 0xe0 */
- "ogonek",
- "caron",
- "Lslash",
- "lslash",
- "Scaron",
- "scaron",
- "Zcaron",
- "zcaron",
- "brokenbar",
- "Eth",
- "eth",
- "Yacute",
- "yacute",
- "Thorn",
- "thorn",
- "minus",
-/* 0xf0 */
- "multiply",
- "onesuperior",
- "twosuperior",
- "threesuperior",
- "onehalf",
- "onequarter",
- "threequarters",
- "franc",
- "Gbreve",
- "gbreve",
- "Idot",
- "Scedilla",
- "scedilla",
- "Cacute",
- "cacute",
- "Ccaron",
-/* 0x100 */
- "ccaron",
- "dmacron"
-};
-
-const char *ambiguous_names[] = {
- "Delta", /* increment */
- "Omega", /* Ohm */
- "Pi", /* product */
- "Sigma", /* summation */
- "dmacron", /* dslash */
- "macron", /* overscore */
- "periodcentered", /* middot */
- NULL
-};
diff --git a/Build/source/texk/web2c/luatexdir/font/mapfile.h b/Build/source/texk/web2c/luatexdir/font/mapfile.h
index e4242a21255..544ebd9c9c3 100644
--- a/Build/source/texk/web2c/luatexdir/font/mapfile.h
+++ b/Build/source/texk/web2c/luatexdir/font/mapfile.h
@@ -17,39 +17,48 @@
You should have received a copy of the GNU General Public License along
with LuaTeX; if not, see <http://www.gnu.org/licenses/>. */
-/* $Id: mapfile.h 2331 2009-04-18 16:39:50Z hhenkel $ */
+/* $Id: mapfile.h 3404 2010-01-28 11:17:10Z taco $ */
#ifndef MAPFILE_H
# define MAPFILE_H
-# define F_INCLUDED 0x01
-# define F_SUBSETTED 0x02
-# define F_STDT1FONT 0x04
-# define F_SUBFONT 0x08
-# define F_TYPE1 0x10
-# define F_TRUETYPE 0x20
-# define F_OTF 0x40
-# define F_CIDKEYED 0x80
-
-# define set_included(fm) ((fm)->type |= F_INCLUDED)
-# define set_subsetted(fm) ((fm)->type |= F_SUBSETTED)
-# define set_std_t1font(fm) ((fm)->type |= F_STDT1FONT)
-# define set_subfont(fm) ((fm)->type |= F_SUBFONT)
-# define set_type1(fm) ((fm)->type |= F_TYPE1)
-# define set_truetype(fm) ((fm)->type |= F_TRUETYPE)
-# define set_opentype(fm) ((fm)->type |= F_OTF)
-# define set_subfont(fm) ((fm)->type |= F_SUBFONT)
-# define set_cidkeyed(fm) ((fm)->type |= F_CIDKEYED)
-
-# define unset_included(fm) ((fm)->type &= ~F_INCLUDED)
-# define unset_subsetted(fm) ((fm)->type &= ~F_SUBSETTED)
-# define unset_std_t1font(fm)((fm)->type &= ~F_STDT1FONT)
-# define unset_subfont(fm) ((fm)->type &= ~F_SUBFONT)
-# define unset_type1(fm) ((fm)->type &= ~F_TYPE1)
-# define unset_truetype(fm) ((fm)->type &= ~F_TRUETYPE)
-# define unset_opentype(fm) ((fm)->type &= ~F_OTF)
-# define unset_subfont(fm) ((fm)->type &= ~F_SUBFONT)
-# define unset_cidkeyed(fm) ((fm)->type &= ~F_CIDKEYED)
+# define F_INCLUDED (1 << 0)
+# define F_SUBSETTED (1 << 1)
+# define F_STDT1FONT (1 << 2)
+# define F_SUBFONT (1 << 3)
+# define F_TYPE1 (1 << 4)
+# define F_TRUETYPE (1 << 5)
+# define F_OTF (1 << 6)
+# define F_CIDKEYED (1 << 7)
+# define F_SLANTSET (1 << 8)
+# define F_EXTENDSET (1 << 9)
+# define F_INUSE (1 << 10)
+
+typedef enum { MAPFILE, MAPLINE } maptype;
+
+# define set_included(fm) ((fm)->type = (unsigned short)((fm)->type | F_INCLUDED))
+# define set_subsetted(fm) ((fm)->type = (unsigned short)((fm)->type | F_SUBSETTED))
+# define set_std_t1font(fm) ((fm)->type = (unsigned short)((fm)->type | F_STDT1FONT))
+# define set_subfont(fm) ((fm)->type = (unsigned short)((fm)->type | F_SUBFONT))
+# define set_type1(fm) ((fm)->type = (unsigned short)((fm)->type | F_TYPE1))
+# define set_truetype(fm) ((fm)->type = (unsigned short)((fm)->type | F_TRUETYPE))
+# define set_opentype(fm) ((fm)->type = (unsigned short)((fm)->type | F_OTF))
+# define set_cidkeyed(fm) ((fm)->type = (unsigned short)((fm)->type | F_CIDKEYED))
+# define set_slantset(fm) ((fm)->type = (unsigned short)((fm)->type | F_SLANTSET))
+# define set_extendset(fm) ((fm)->type = (unsigned short)((fm)->type | F_EXTENDSET))
+# define set_inuse(fm) ((fm)->type = (unsigned short)((fm)->type | F_INUSE))
+
+# define unset_included(fm) ((fm)->type = (unsigned short)((fm)->type & ~F_INCLUDED))
+# define unset_subsetted(fm) ((fm)->type = (unsigned short)((fm)->type & ~F_SUBSETTED))
+# define unset_std_t1font(fm)((fm)->type = (unsigned short)((fm)->type & ~F_STDT1FONT))
+# define unset_subfont(fm) ((fm)->type = (unsigned short)((fm)->type & ~F_SUBFONT))
+# define unset_type1(fm) ((fm)->type = (unsigned short)((fm)->type & ~F_TYPE1))
+# define unset_truetype(fm) ((fm)->type = (unsigned short)((fm)->type & ~F_TRUETYPE))
+# define unset_opentype(fm) ((fm)->type = (unsigned short)((fm)->type & ~F_OTF))
+# define unset_cidkeyed(fm) ((fm)->type = (unsigned short)((fm)->type & ~F_CIDKEYED))
+# define unset_slantset(fm) ((fm)->type = (unsigned short)((fm)->type & ~F_SLANTSET))
+# define unset_extendset(fm) ((fm)->type = (unsigned short)((fm)->type & ~F_EXTENDSET))
+# define unset_inuse(fm) ((fm)->type = (unsigned short)((fm)->type & ~F_INUSE))
# define is_included(fm) (((fm)->type & F_INCLUDED) != 0)
# define is_subsetted(fm) (((fm)->type & F_SUBSETTED) != 0)
@@ -58,8 +67,10 @@
# define is_type1(fm) (((fm)->type & F_TYPE1) != 0)
# define is_truetype(fm) (((fm)->type & F_TRUETYPE) != 0)
# define is_opentype(fm) (((fm)->type & F_OTF) != 0)
-# define is_subfont(fm) (((fm)->type & F_SUBFONT) != 0)
# define is_cidkeyed(fm) (((fm)->type & F_CIDKEYED) != 0)
+# define is_slantset(fm) (((fm)->type & F_SLANTSET) != 0)
+# define is_extendset(fm) (((fm)->type & F_EXTENDSET) != 0)
+# define is_inuse(fm) (((fm)->type & F_INUSE) != 0)
# define fm_slant(fm) (fm)->slant
# define fm_extend(fm) (fm)->extend
@@ -70,15 +81,6 @@
# define is_t1fontfile(fm) (is_fontfile(fm) && is_type1(fm))
# define is_builtin(fm) (!is_fontfile(fm))
-# define LINK_TFM 0x01
-# define LINK_PS 0x02
-# define set_tfmlink(fm) ((fm)->links |= LINK_TFM)
-# define set_pslink(fm) ((fm)->links |= LINK_PS)
-# define unset_tfmlink(fm) ((fm)->links &= ~LINK_TFM)
-# define unset_pslink(fm) ((fm)->links &= ~LINK_PS)
-# define has_tfmlink(fm) ((fm)->links & LINK_TFM)
-# define has_pslink(fm) ((fm)->links & LINK_PS)
-
/**********************************************************************/
typedef struct {
@@ -86,9 +88,9 @@ typedef struct {
char *tfm_name; /* TFM file name (1st field in map line) */
char *sfd_name; /* subfont directory name, like @sfd_name@ */
char *ps_name; /* PostScript name (optional 2nd field in map line) */
- integer fd_flags; /* font descriptor /Flags (PDF Ref. section 5.7.1) */
- integer slant; /* SlantFont */
- integer extend; /* ExtendFont */
+ int fd_flags; /* font descriptor /Flags (PDF Ref. section 5.7.1) */
+ int slant; /* SlantFont */
+ int extend; /* ExtendFont */
char *encname; /* encoding file name */
char *ff_name; /* font file name */
unsigned short type; /* various flags */
@@ -96,8 +98,6 @@ typedef struct {
short eid; /* Eid for truetype fonts */
/* parameters NOT scanned from the map file: */
subfont_entry *subfont; /* subfont mapping */
- unsigned short links; /* link flags from tfm_tree and ps_tree */
- boolean in_use; /* true if this structure has been referenced already */
} fm_entry;
typedef struct {
@@ -107,18 +107,24 @@ typedef struct {
/**********************************************************************/
-fm_entry *lookup_fontmap(char *);
-boolean hasfmentry(internalfontnumber);
+# define FONT_SLANT_MIN -2000
+# define FONT_SLANT_MAX 2000
+# define FONT_EXTEND_MIN -5000
+# define FONT_EXTEND_MAX 5000
+
+/**********************************************************************/
+
+fm_entry *getfontmap(char *tfm_name);
void fm_free(void);
-void fm_read_info(void);
ff_entry *check_ff_exist(char *, boolean);
-void pdfmapfile(integer);
-void pdfmapline(integer);
-void pdf_init_map_file(string map_name);
+void pdfmapfile(int);
+void pdfmapline(int);
+void pdf_init_map_file(char *map_name);
fm_entry *new_fm_entry(void);
void delete_fm_entry(fm_entry *);
int avl_do_entry(fm_entry *, int);
int check_std_t1font(char *s);
int is_subsetable(fm_entry * fm);
+void process_map_item(char *s, int type);
#endif /* MAPFILE_H */
diff --git a/Build/source/texk/web2c/luatexdir/font/mapfile.c b/Build/source/texk/web2c/luatexdir/font/mapfile.w
index fe5155da23e..3d129183d6f 100644
--- a/Build/source/texk/web2c/luatexdir/font/mapfile.c
+++ b/Build/source/texk/web2c/luatexdir/font/mapfile.w
@@ -1,7 +1,8 @@
+@ @c
/* mapfile.c
-
- Copyright 1996-2006 Han The Thanh <thanh@pdftex.org>
- Copyright 2006-2008 Taco Hoekwater <taco@luatex.org>
+
+ Copyright 1996-2006 Han The Thanh <thanh@@pdftex.org>
+ Copyright 2006-2010 Taco Hoekwater <taco@@luatex.org>
This file is part of LuaTeX.
@@ -18,29 +19,26 @@
You should have received a copy of the GNU General Public License along
with LuaTeX; if not, see <http://www.gnu.org/licenses/>. */
+static const char _svn_version[] =
+ "$Id: mapfile.w 3584 2010-04-02 17:45:55Z hhenkel $ "
+ "$URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.60.0/source/texk/web2c/luatexdir/font/mapfile.w $";
+
#include <math.h>
#include "ptexlib.h"
#include <kpathsea/c-auto.h>
#include <kpathsea/c-memstr.h>
#include <string.h>
-#include "luatex-api.h"
-
-static const char _svn_version[] =
- "$Id: mapfile.c 2331 2009-04-18 16:39:50Z hhenkel $ "
- "$URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.40.6/source/texk/web2c/luatexdir/font/mapfile.c $";
#define FM_BUF_SIZE 1024
static FILE *fm_file;
static unsigned char *fm_buffer = NULL;
-static integer fm_size = 0;
-static integer fm_curbyte = 0;
+static int fm_size = 0;
+static int fm_curbyte = 0;
-#define fm_open() \
- (fm_file = fopen((char *) nameoffile + 1, FOPEN_RBIN_MODE))
-#define fm_read_file() \
- readbinfile(fm_file,&fm_buffer,&fm_size)
+#define fm_open(a) (fm_file = fopen((char *)(a), FOPEN_RBIN_MODE))
+#define fm_read_file() readbinfile(fm_file,&fm_buffer,&fm_size)
#define fm_close() xfclose(fm_file, cur_file_name)
#define fm_getchar() fm_buffer[fm_curbyte++]
#define fm_eof() (fm_curbyte>fm_size)
@@ -48,7 +46,6 @@ static integer fm_curbyte = 0;
(c == 10 || c == '*' || c == '#' || c == ';' || c == '%')
typedef enum { FM_DUPIGNORE, FM_REPLACE, FM_DELETE } updatemode;
-typedef enum { MAPFILE, MAPLINE } maptype;
typedef struct mitem {
updatemode mode; /* FM_DUPIGNORE or FM_REPLACE or FM_DELETE */
@@ -58,8 +55,6 @@ typedef struct mitem {
} mapitem;
mapitem *mitem = NULL;
-static const char nontfm[] = "<nontfm>";
-
#define read_field(r, q, buf) do { \
q = buf; \
while (*r != ' ' && *r != '<' && *r != '"' && *r != '\0') \
@@ -87,12 +82,13 @@ fm_entry *new_fm_entry(void)
fm->encname = NULL;
fm->type = 0;
fm->slant = 0;
- fm->extend = 0;
- fm->links = 0;
+ fm->extend = 1000;
fm->pid = -1;
fm->eid = -1;
fm->subfont = NULL;
- fm->in_use = false;
+ unset_slantset(fm);
+ unset_extendset(fm);
+ unset_inuse(fm);
return fm;
}
@@ -121,18 +117,11 @@ static void delete_ff_entry(ff_entry * ff)
xfree(ff);
}
-static fm_entry *dummy_fm_entry(void)
-{
- static const fm_entry const_fm_entry;
- return (fm_entry *) & const_fm_entry;
-}
-
/**********************************************************************/
-struct avl_table *tfm_tree = NULL;
-struct avl_table *ps_tree = NULL;
-struct avl_table *ff_tree = NULL;
-struct avl_table *encname_tree = NULL;
+static struct avl_table *tfm_tree = NULL;
+static struct avl_table *ff_tree = NULL;
+static struct avl_table *encname_tree = NULL;
/* AVL sort fm_entry into tfm_tree by tfm_name */
@@ -143,21 +132,6 @@ static int comp_fm_entry_tfm(const void *pa, const void *pb, void *p)
((const fm_entry *) pb)->tfm_name);
}
-/* AVL sort fm_entry into ps_tree by ps_name, slant, and extend */
-
-static int comp_fm_entry_ps(const void *pa, const void *pb, void *p)
-{
- int i;
- const fm_entry *p1 = (const fm_entry *) pa, *p2 = (const fm_entry *) pb;
- (void) p;
- assert(p1->ps_name != NULL && p2->ps_name != NULL);
- if ((i = strcmp(p1->ps_name, p2->ps_name)))
- return i;
- cmp_return(p1->slant, p2->slant);
- cmp_return(p1->extend, p2->extend);
- return 0;
-}
-
/* AVL sort ff_entry into ff_tree by ff_name */
static int comp_ff_entry(const void *pa, const void *pb, void *p)
@@ -172,9 +146,6 @@ static void create_avl_trees(void)
assert(tfm_tree == NULL);
tfm_tree = avl_create(comp_fm_entry_tfm, NULL, &avl_xallocator);
assert(tfm_tree != NULL);
- assert(ps_tree == NULL);
- ps_tree = avl_create(comp_fm_entry_ps, NULL, &avl_xallocator);
- assert(ps_tree != NULL);
assert(ff_tree == NULL);
ff_tree = avl_create(comp_ff_entry, NULL, &avl_xallocator);
assert(ff_tree != NULL);
@@ -183,90 +154,46 @@ static void create_avl_trees(void)
assert(encname_tree != NULL);
}
-/*
-The function avl_do_entry() is not completely symmetrical with regards
-to tfm_name and ps_name handling, e. g. a duplicate tfm_name gives a
-"goto exit", and no ps_name link is tried. This is to keep it compatible
-with the original version.
-*/
-
int avl_do_entry(fm_entry * fm, int mode)
{
fm_entry *p;
void *a;
void **aa;
-
- /* handle tfm_name link */
-
- if (strcmp(fm->tfm_name, nontfm)) {
- p = (fm_entry *) avl_find(tfm_tree, fm);
- if (p != NULL) {
- switch (mode) {
- case FM_DUPIGNORE:
+ int delete_new = 0;
+ if (tfm_tree == NULL)
+ create_avl_trees();
+ p = (fm_entry *) avl_find(tfm_tree, fm);
+ if (p != NULL) {
+ switch (mode) {
+ case FM_DUPIGNORE:
+ pdftex_warn
+ ("fontmap entry for `%s' already exists, duplicates ignored",
+ fm->tfm_name);
+ delete_new = 1;
+ break;
+ case FM_REPLACE:
+ case FM_DELETE:
+ if (is_inuse(p)) {
pdftex_warn
- ("fontmap entry for `%s' already exists, duplicates ignored",
+ ("fontmap entry for `%s' has been used, replace/delete not allowed",
fm->tfm_name);
- goto exit;
- break;
- case FM_REPLACE:
- case FM_DELETE:
- if (p->in_use) {
- pdftex_warn
- ("fontmap entry for `%s' has been used, replace/delete not allowed",
- fm->tfm_name);
- goto exit;
- }
+ delete_new = 1;
+ } else {
a = avl_delete(tfm_tree, p);
assert(a != NULL);
- unset_tfmlink(p);
- if (!has_pslink(p))
- delete_fm_entry(p);
- break;
- default:
- assert(0);
+ delete_fm_entry(p);
}
- }
- if (mode != FM_DELETE) {
- aa = avl_probe(tfm_tree, fm);
- assert(aa != NULL);
- set_tfmlink(fm);
- }
- }
-
- /* handle ps_name link */
-
- if (fm->ps_name != NULL) {
- p = (fm_entry *) avl_find(ps_tree, fm);
- if (p != NULL) {
- switch (mode) {
- case FM_DUPIGNORE:
- goto exit;
- break;
- case FM_REPLACE:
- case FM_DELETE:
- if (p->in_use)
- goto exit;
- a = avl_delete(ps_tree, p);
- assert(a != NULL);
- unset_pslink(p);
- if (!has_tfmlink(p))
- delete_fm_entry(p);
- break;
- default:
- assert(0);
- }
- }
- if (mode != FM_DELETE && is_t1fontfile(fm) && is_included(fm)) {
- aa = avl_probe(ps_tree, fm);
- assert(aa != NULL);
- set_pslink(fm);
+ break;
+ default:
+ assert(0);
}
}
- exit:
- if (!has_tfmlink(fm) && !has_pslink(fm)) /* e. g. after FM_DELETE */
- return 1; /* deallocation of fm_entry structure required */
- else
- return 0;
+ if ((mode == FM_DUPIGNORE || mode == FM_REPLACE) && delete_new == 0) {
+ aa = avl_probe(tfm_tree, fm);
+ assert(aa != NULL);
+ } else
+ delete_new = 1;
+ return delete_new;
}
/* add the encoding name to an AVL tree. this has nothing to do with writeenc.c */
@@ -320,25 +247,15 @@ static int check_fm_entry(fm_entry * fm, boolean warn)
a += 2;
}
- /* SlantFont and ExtendFont can be used only with Type1 fonts */
- if ((fm->slant != 0 || fm->extend != 0)
- && !(is_t1fontfile(fm) && is_included(fm))) {
- if (warn)
- pdftex_warn
- ("invalid entry for `%s': SlantFont/ExtendFont can be used only with embedded Type1 fonts",
- fm->tfm_name);
- a += 4;
- }
-
/* the value of SlantFont and ExtendFont must be reasonable */
- if (abs(fm->slant) > 1000) {
+ if (fm->slant < FONT_SLANT_MIN || fm->slant > FONT_SLANT_MAX) {
if (warn)
pdftex_warn
("invalid entry for `%s': too big value of SlantFont (%g)",
fm->tfm_name, fm->slant / 1000.0);
a += 8;
}
- if (abs(fm->extend) > 2000) {
+ if (fm->extend < FONT_EXTEND_MIN || fm->extend > FONT_EXTEND_MAX) {
if (warn)
pdftex_warn
("invalid entry for `%s': too big value of ExtendFont (%g)",
@@ -409,14 +326,14 @@ int check_std_t1font(char *s)
if (k > -1 && !strcmp(std_t1font_names[k], s))
return k;
return -1;
-};
-
+}
/**********************************************************************/
static void fm_scan_line(void)
{
int a, b, c, j, u = 0, v = 0;
+ char cc;
float d;
fm_entry *fm;
char fm_line[FM_BUF_SIZE], buf[FM_BUF_SIZE];
@@ -427,12 +344,12 @@ static void fm_scan_line(void)
while (!fm_eof()) {
if (fm_curbyte == fm_size) {
fm_curbyte++;
- c = 10;
+ cc = 10;
} else {
- c = fm_getchar();
+ cc = (char) fm_getchar();
}
- append_char_to_buf(c, p, fm_line, FM_BUF_SIZE);
- if (c == 10)
+ append_char_to_buf(cc, p, fm_line, FM_BUF_SIZE);
+ if (cc == 10)
break;
}
*(--p) = '\0';
@@ -476,14 +393,14 @@ static void fm_scan_line(void)
if (*(s - 1) == 'E' || *(s - 1) == 'e')
s--; /* e. g. 0.5ExtendFont: %f = 0.5E */
if (str_prefix(s, "SlantFont")) {
- d *= 1000.0; /* correct rounding also for neg. numbers */
- fm->slant = (integer) (d > 0 ? d + 0.5 : d - 0.5);
+ d *= (float) 1000.0; /* correct rounding also for neg. numbers */
+ fm->slant = (int) (d > 0 ? d + 0.5 : d - 0.5);
+ set_slantset(fm);
r = s + strlen("SlantFont");
} else if (str_prefix(s, "ExtendFont")) {
- d *= 1000.0;
- fm->extend = (integer) (d > 0 ? d + 0.5 : d - 0.5);
- if (fm->extend == 1000)
- fm->extend = 0;
+ d *= (float) 1000.0;
+ fm->extend = (int) (d > 0 ? d + 0.5 : d - 0.5);
+ set_extendset(fm);
r = s + strlen("ExtendFont");
} else { /* unknown name */
for (r = s; *r != ' ' && *r != '"' && *r != '\0'; r++); /* jump over name */
@@ -492,7 +409,7 @@ static void fm_scan_line(void)
pdftex_warn
("invalid entry for `%s': unknown name `%s' ignored",
fm->tfm_name, s);
- *r = c;
+ *r = (char) c;
}
} else
for (; *r != ' ' && *r != '"' && *r != '\0'; r++);
@@ -509,8 +426,8 @@ static void fm_scan_line(void)
break;
case 'P': /* handle cases for subfonts like 'PidEid=3,1' */
if (sscanf(r, "PidEid=%i, %i %n", &a, &b, &c) >= 2) {
- fm->pid = a;
- fm->eid = b;
+ fm->pid = (short) a;
+ fm->eid = (short) b;
r += c;
break;
}
@@ -552,6 +469,8 @@ static void fm_scan_line(void)
if (is_fontfile(fm) && strlen(fm_fontfile(fm)) > 3) {
if (strcasecmp(strend(fm_fontfile(fm)) - 4, ".ttf") == 0)
set_truetype(fm);
+ else if (strcasecmp(strend(fm_fontfile(fm)) - 4, ".ttc") == 0)
+ set_truetype(fm);
else if (strcasecmp(strend(fm_fontfile(fm)) - 4, ".otf") == 0)
set_opentype(fm);
else
@@ -567,7 +486,7 @@ static void fm_scan_line(void)
*/
if (handle_subfont_fm(fm, mitem->mode)) /* is this a subfont? */
return;
- if (avl_do_entry(fm, mitem->mode) == 0) /* if success */
+ if (avl_do_entry(fm, mitem->mode) == 0)
return;
bad_line:
delete_fm_entry(fm);
@@ -575,11 +494,11 @@ static void fm_scan_line(void)
/**********************************************************************/
-void fm_read_info(void)
+static void fm_read_info(void)
{
int callback_id;
int file_opened = 0;
- char *ftemp = NULL;
+
if (tfm_tree == NULL)
create_avl_trees();
if (mitem->line == NULL) /* nothing to do */
@@ -587,75 +506,49 @@ void fm_read_info(void)
mitem->lineno = 1;
switch (mitem->type) {
case MAPFILE:
- set_cur_file_name(mitem->line);
- if (fm_buffer != NULL) {
- xfree(fm_buffer);
- fm_buffer = NULL;
- }
+ xfree(fm_buffer);
fm_curbyte = 0;
fm_size = 0;
- callback_id = callback_defined(find_map_file_callback);
- if (callback_id > 0) {
- if (run_callback
- (callback_id, "S->S", (char *) (nameoffile + 1), &ftemp)) {
- if (ftemp != NULL && strlen(ftemp)) {
- free(nameoffile);
- namelength = strlen(ftemp);
- nameoffile = xmalloc(namelength + 2);
- strcpy((char *) (nameoffile + 1), ftemp);
- free(ftemp);
- }
- }
- } else {
- ftemp =
- kpse_find_file((char *) (nameoffile + 1), kpse_fontmap_format,
- 0);
- if (ftemp != NULL) {
- free(nameoffile);
- namelength = strlen(ftemp);
- nameoffile = xmalloc(namelength + 2);
- strcpy((char *) (nameoffile + 1), ftemp);
- free(ftemp);
- }
- }
- callback_id = callback_defined(read_map_file_callback);
- if (callback_id > 0) {
- if (run_callback(callback_id, "S->bSd", (char *) (nameoffile + 1),
- &file_opened, &fm_buffer, &fm_size)) {
- if (file_opened) {
- if (fm_size > 0) {
- cur_file_name = (char *) nameoffile + 1;
- if (tracefilenames)
- tex_printf("{%s", cur_file_name);
- while (!fm_eof()) {
- fm_scan_line();
- mitem->lineno++;
+ cur_file_name = luatex_find_file(mitem->line, find_map_file_callback);
+ if (cur_file_name) {
+ callback_id = callback_defined(read_map_file_callback);
+ if (callback_id > 0) {
+ if (run_callback(callback_id, "S->bSd", cur_file_name,
+ &file_opened, &fm_buffer, &fm_size)) {
+ if (file_opened) {
+ if (fm_size > 0) {
+ if (tracefilenames)
+ tex_printf("{%s", cur_file_name);
+ while (!fm_eof()) {
+ fm_scan_line();
+ mitem->lineno++;
+ }
+ if (tracefilenames)
+ tex_printf("}");
+ fm_file = NULL;
}
- if (tracefilenames)
- tex_printf("}");
- fm_file = NULL;
+ } else {
+ pdftex_warn("cannot open font map file");
}
} else {
pdftex_warn("cannot open font map file");
}
} else {
- pdftex_warn("cannot open font map file");
- }
- } else {
- if (!fm_open()) {
- pdftex_warn("cannot open font map file");
- } else {
- fm_read_file();
- cur_file_name = (char *) nameoffile + 1;
- tex_printf("{%s", cur_file_name);
- while (!fm_eof()) {
- fm_scan_line();
- mitem->lineno++;
+ if (!fm_open(cur_file_name)) {
+ pdftex_warn("cannot open font map file");
+ } else {
+ fm_read_file();
+ tex_printf("{%s", cur_file_name);
+ while (!fm_eof()) {
+ fm_scan_line();
+ mitem->lineno++;
+ }
+ fm_close();
+ tex_printf("}");
+ fm_file = NULL;
}
- fm_close();
- tex_printf("}");
- fm_file = NULL;
}
+ cur_file_name = NULL;
}
break;
case MAPLINE:
@@ -672,145 +565,20 @@ void fm_read_info(void)
/**********************************************************************/
-static fm_entry_ptr fmlookup(internalfontnumber f)
+fm_entry *getfontmap(char *tfm_name)
{
- char *tfm;
fm_entry *fm;
fm_entry tmp;
+ if (tfm_name == NULL) /* wide, lua loaded fonts may not have a name */
+ return NULL;
if (tfm_tree == NULL)
fm_read_info(); /* only to read default map file */
- tfm = font_name(f);
- assert(strcmp(tfm, nontfm));
-
- /* Look up for full <tfmname>[+-]<expand> */
- tmp.tfm_name = tfm;
+ tmp.tfm_name = tfm_name; /* Look up for tfmname */
fm = (fm_entry *) avl_find(tfm_tree, &tmp);
- if (fm != NULL) {
- fm->in_use = true;
- return (fm_entry_ptr) fm;
- }
- return (fm_entry_ptr) dummy_fm_entry();
-}
-
-boolean hasfmentry(internalfontnumber f)
-{
- if (font_map(f) == NULL)
- set_font_map(f, (fm_entry_ptr) fmlookup(f));
- assert(font_map(f) != NULL);
- return font_map(f) != (fm_entry_ptr) dummy_fm_entry();
-}
-
-/* check whether a map entry is valid for font replacement */
-
-static boolean fm_valid_for_font_replacement(fm_entry * fm)
-{
- ff_entry *ff;
-
- assert(fm != NULL);
- assert(is_fontfile(fm)); /* ps_tree should contain only entries with font file */
- assert(is_type1(fm)); /* ps_tree should contain only Type1 entries */
-
- ff = check_ff_exist(fm->ff_name, false);
- assert(ff != NULL);
- if (ff->ff_path == NULL) /* ...there is no font file available */
- return false;
- return true; /* all tests passed */
-}
-
-/**********************************************************************/
-/*
- * lookup fontmap by ps_name;
- * used for Type1 font replacement when embedding of PDF files
- */
-
-fm_entry *lookup_fontmap(char *ps_name)
-{
- fm_entry *fm, *fm2, tmp;
- char *a, *b, *c, *d, *e, *s;
- int i, sl, ex;
- struct avl_traverser t, t2;
- if (tfm_tree == NULL)
- fm_read_info(); /* only to read default map file */
- assert(ps_name != NULL);
- s = ps_name;
- if (strlen(ps_name) > 7) { /* check for subsetted name tag */
- for (i = 0; i < 6; i++, s++)
- if (*s < 'A' || *s > 'Z')
- break;
- if (i == 6 && *s == '+')
- s++; /* if name tag found, skip behind it */
- else
- s = ps_name;
- }
-
- /*
- * Scan -Slant_<slant> and -Extend_<extend> font name extensions;
- * three valid formats:
- * <fontname>-Slant_<slant>
- * <fontname>-Slant_<slant>-Extend_<extend>
- * <fontname>-Extend_<extend>
- * Slant entry must come _before_ Extend entry
- */
-
- tmp.slant = 0;
- tmp.extend = 0;
- if ((a = strstr(s, "-Slant_")) != NULL) {
- b = a + strlen("-Slant_");
- sl = (int) strtol(b, &e, 10);
- if ((e != b) && (e == strend(b))) {
- tmp.slant = sl;
- *a = '\0'; /* ps_name string ends before "-Slant_" */
- } else {
- if (e != b) { /* only if <slant> is valid number */
- if ((c = strstr(e, "-Extend_")) != NULL) {
- d = c + strlen("-Extend_");
- ex = (int) strtol(d, &e, 10);
- if ((e != d) && (e == strend(d))) {
- tmp.slant = sl;
- tmp.extend = ex;
- *a = '\0'; /* ps_name string ends before "-Slant_" */
- }
- }
- }
- }
- } else {
- if ((a = strstr(s, "-Extend_")) != NULL) {
- b = a + strlen("-Extend_");
- ex = (int) strtol(b, &e, 10);
- if ((e != b) && (e == strend(b))) {
- tmp.extend = ex;
- *a = '\0'; /* ps_name string ends before "-Extend_" */
- }
- }
- }
- tmp.ps_name = s;
-
- fm = (fm_entry *) avl_t_find(&t, ps_tree, &tmp);
if (fm == NULL)
- return NULL; /* no entry found */
-
- /* at this point we know there is at least one fm_entry with given ps_name;
- * we test all such entries and return the first one that is valid for font
- * replacement */
-
- t2 = t;
- fm2 = (fm_entry *) avl_t_prev(&t2);
-
- /* search forward */
- do {
- if (fm_valid_for_font_replacement(fm))
- return fm;
- fm = (fm_entry *) avl_t_next(&t);
- } while (fm != NULL && comp_fm_entry_ps(fm, &tmp, NULL) == 0);
-
- /* search backward */
- while (fm2 != NULL && comp_fm_entry_ps(fm2, &tmp, NULL) == 0) {
- if (fm_valid_for_font_replacement(fm2))
- return fm2;
- fm2 = (fm_entry *) avl_t_prev(&t2);
- }
-
- return NULL;
+ return NULL;
+ set_inuse(fm);
+ return fm;
}
/**********************************************************************/
@@ -821,7 +589,7 @@ fm_entry *lookup_fontmap(char *ps_name)
* ignored.
*/
-static void process_map_item(char *s, int type)
+void process_map_item(char *s, int type)
{
char *p;
int mode;
@@ -868,19 +636,21 @@ static void process_map_item(char *s, int type)
}
}
-void pdfmapfile(integer t)
+void pdfmapfile(int t)
{
- process_map_item(makecstring(tokens_to_string(t)), MAPFILE);
- flush_str(last_tokens_string);
+ char *s = tokenlist_to_cstring(t, true, NULL);
+ process_map_item(s, MAPFILE);
+ free(s);
}
-void pdfmapline(integer t)
+void pdfmapline(int t)
{
- process_map_item(makecstring(tokens_to_string(t)), MAPLINE);
- flush_str(last_tokens_string);
+ char *s = tokenlist_to_cstring(t, true, NULL);
+ process_map_item(s, MAPLINE);
+ free(s);
}
-void pdf_init_map_file(string map_name)
+void pdf_init_map_file(char *map_name)
{
assert(mitem == NULL);
mitem = xtalloc(1, mapitem);
@@ -898,7 +668,7 @@ void pdf_init_map_file(string map_name)
* same fonts are to be embedded.
*
* The ff_tree contains only font files, which are actually needed,
- * so this tree typically is much smaller than the tfm_tree or ps_tree.
+ * so this tree typically is much smaller than the tfm_tree.
*/
ff_entry *check_ff_exist(char *ff_name, boolean is_tt)
@@ -958,21 +728,7 @@ static void destroy_fm_entry_tfm(void *pa, void *pb)
fm_entry *fm;
(void) pb;
fm = (fm_entry *) pa;
- if (!has_pslink(fm))
- delete_fm_entry(fm);
- else
- unset_tfmlink(fm);
-}
-
-static void destroy_fm_entry_ps(void *pa, void *pb)
-{
- fm_entry *fm;
- (void) pb;
- fm = (fm_entry *) pa;
- if (!has_tfmlink(fm))
- delete_fm_entry(fm);
- else
- unset_pslink(fm);
+ delete_fm_entry(fm);
}
static void destroy_ff_entry(void *pa, void *pb)
@@ -989,15 +745,8 @@ void fm_free(void)
avl_destroy(tfm_tree, destroy_fm_entry_tfm);
tfm_tree = NULL;
}
- if (ps_tree != NULL) {
- avl_destroy(ps_tree, destroy_fm_entry_ps);
- ps_tree = NULL;
- }
if (ff_tree != NULL) {
avl_destroy(ff_tree, destroy_ff_entry);
ff_tree = NULL;
}
}
-
-/**********************************************************************/
-/* end of mapfile.c */
diff --git a/Build/source/texk/web2c/luatexdir/font/pkin.c b/Build/source/texk/web2c/luatexdir/font/pkin.w
index 0576901ba65..077680eb596 100644
--- a/Build/source/texk/web2c/luatexdir/font/pkin.c
+++ b/Build/source/texk/web2c/luatexdir/font/pkin.w
@@ -1,57 +1,65 @@
-/* pkin.c
-
- Copyright 1996-2006 Han The Thanh <thanh@pdftex.org>
- Copyright 2006-2008 Taco Hoekwater <taco@luatex.org>
-
- This file is part of LuaTeX.
-
- LuaTeX 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 2 of the License, or (at your
- option) any later version.
-
- LuaTeX 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 Lesser General Public
- License for more details.
-
- You should have received a copy of the GNU General Public License along
- with LuaTeX; if not, see <http://www.gnu.org/licenses/>. */
-
-/*
- * NAME
- * pkin.c - implementation of readchar()
- * DESCRIPTION
- * This implementation of readchar() uses parts of the program dvips
- * written by Tomas Rokicki--the inventor of the pkformat--(loadfont.c,
- * download.c and unpack.c). Dvips in turn is derived from pktype.
- * Pktype(TeX) is described in debt in ``The PKtype processor'',
- * which is available as pktype.weave as part of the METAFONTware.
- * What was needed to implement readchar() is rearranged in pkfile.c to
- * get more modularity in the style of MODULA2.
- * BUGFIXES
- * May 1997: Eric Delaunay <delaunay@lix.polytechnique.fr> reports a
- * problem with huge fonts (greater than 1008 DPI). The code for
- * handling PK characters in `extended format' was wrongly derived
- * from dvips. Made some minor improvements regarding error handling.
- * REDESIGN
- * Piet Tutelaers
- * rcpt@urc.tue.nl
- *
- * Modified for use with pdftex by Han The Thanh <thanh@fi.muni.cz>.
- */
-
+% pkin.w
+%
+% Copyright 1996-2006 Han The Thanh <thanh@@pdftex.org>
+% Copyright 2006-2008 Taco Hoekwater <taco@@luatex.org>
+%
+% This file is part of LuaTeX.
+%
+% LuaTeX 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 2 of the License, or (at your
+% option) any later version.
+%
+% LuaTeX 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 Lesser General Public
+% License for more details.
+%
+% You should have received a copy of the GNU General Public License along
+% with LuaTeX; if not, see <http://www.gnu.org/licenses/>.
+
+@
+NAME
+
+pkin.c - implementation of readchar()
+
+DESCRIPTION
+
+This implementation of readchar() uses parts of the program dvips
+written by Tomas Rokicki--the inventor of the pkformat--(loadfont.c,
+download.c and unpack.c). Dvips in turn is derived from pktype.
+Pktype(TeX) is described in debt in ``The PKtype processor'',
+which is available as pktype.weave as part of the METAFONTware.
+What was needed to implement readchar() is rearranged in pkfile.c to
+get more modularity in the style of MODULA2.
+
+BUGFIXES
+
+May 1997: Eric Delaunay <delaunay@@lix.polytechnique.fr> reports a
+problem with huge fonts (greater than 1008 DPI). The code for
+handling PK characters in `extended format' was wrongly derived
+from dvips. Made some minor improvements regarding error handling.
+
+REDESIGN
+
+Piet Tutelaers <rcpt@@urc.tue.nl>
+
+Modified for use with pdftex by Han The Thanh <thanh@@fi.muni.cz>.
+
+@c
#include "ptexlib.h"
-#include "luatexfont.h"
-static const char _svn_version[] =
- "$Id: pkin.c 2271 2009-04-12 23:42:21Z oneiros $ $URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.40.6/source/texk/web2c/luatexdir/font/pkin.c $";
-
-/*
- * Now we have some routines to get stuff from the pk file. pkbyte returns
- * the next byte from the pk file.
- */
+typedef short shalfword;
+static const char _svn_version[] =
+ "$Id: pkin.w 3584 2010-04-02 17:45:55Z hhenkel $"
+ "$URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.60.0/source/texk/web2c/luatexdir/font/pkin.w $";
+
+@
+Now we have some routines to get stuff from the pk file. pkbyte returns
+the next byte from the pk file.
+
+@c
static shalfword pkbyte(void)
{
register shalfword i;
@@ -61,9 +69,9 @@ static shalfword pkbyte(void)
return (i);
}
-static integer pkduo(void)
+static int pkduo(void)
{
- register integer i;
+ register int i;
i = pkbyte();
if (i > 127)
@@ -72,9 +80,9 @@ static integer pkduo(void)
return (i);
}
-static integer pktrio(void)
+static int pktrio(void)
{
- register integer i;
+ register int i;
i = pkbyte();
if (i > 127)
@@ -84,9 +92,9 @@ static integer pktrio(void)
return (i);
}
-static integer pkquad(void)
+static int pkquad(void)
{
- register integer i;
+ register int i;
i = pkbyte();
if (i > 127)
@@ -97,15 +105,14 @@ static integer pkquad(void)
return (i);
}
-/*
- * The next part is devoted to unpacking the character data.
- */
-/*
- * We need procedures to get a nybble, bit, and packed word from the
- * packed data structure.
- */
+@ The next part is devoted to unpacking the character data.
+
+@ We need procedures to get a nybble, bit, and packed word from the
+packed data structure.
+
+@c
static halfword inputbyte, flagbyte;
static halfword bitweight;
static halfword dynf;
@@ -122,7 +129,7 @@ static shalfword getnyb(void)
bitweight = 0;
temp = inputbyte & 15;
}
- return (temp);
+ return (shalfword) (temp);
}
static boolean getbit(void)
@@ -150,8 +157,8 @@ static halfword pkpackednum(void)
} while (!(j != 0));
if (i > 3) {
/*
- * Damn, we got a huge count! We *fake* it by giving an artificially
- * large repeat count.
+ Damn, we got a huge count! We {\it fake} it by giving an artificially
+ large repeat count.
*/
return (handlehuge(i, j));
} else {
@@ -189,7 +196,7 @@ static halfword rest(void)
pk_remainder = 4000 - pk_remainder;
return (4000);
} else {
- i = pk_remainder;
+ i = (halfword) pk_remainder;
pk_remainder = 0;
realfunc = pkpackednum;
return (i);
@@ -213,17 +220,17 @@ static halfword handlehuge(halfword i, halfword k)
return (rest());
}
-/*
- * And now we have our unpacking routine.
- */
+@ And now we have our unpacking routine.
+
+@c
static halfword gpower[17] = { 0, 1, 3, 7, 15, 31, 63, 127,
255, 511, 1023, 2047, 4095, 8191, 16383, 32767, 65535
};
static void unpack(chardesc * cd)
{
- register integer i, j;
+ register int i, j;
register halfword word, wordweight;
halfword *raster;
shalfword rowsleft;
@@ -232,14 +239,14 @@ static void unpack(chardesc * cd)
halfword count;
shalfword wordwidth;
- wordwidth = (cd->cwidth + 15) / 16;
- i = 2 * cd->cheight * (long) wordwidth;
+ wordwidth = (shalfword) ((cd->cwidth + 15) / 16);
+ i = (int) (2 * cd->cheight * (long) wordwidth);
if (i <= 0)
i = 2;
if (i > cd->rastersize) {
xfree(cd->raster);
cd->rastersize = i;
- cd->raster = xtalloc(cd->rastersize, halfword);
+ cd->raster = xtalloc((unsigned) cd->rastersize, halfword);
}
raster = cd->raster;
realfunc = pkpackednum;
@@ -264,8 +271,8 @@ static void unpack(chardesc * cd)
*raster++ = word;
}
} else {
- rowsleft = cd->cheight;
- hbit = cd->cwidth;
+ rowsleft = (shalfword) cd->cheight;
+ hbit = (shalfword) cd->cwidth;
repeatcount = 0;
wordweight = 16;
word = 0;
@@ -282,7 +289,7 @@ static void unpack(chardesc * cd)
if ((count < wordweight) && (count < hbit)) {
if (turnon)
word += gpower[wordweight] - gpower[wordweight - count];
- hbit -= count;
+ hbit = (shalfword) (hbit - count);
wordweight -= count;
count = 0;
} else if ((count >= hbit) && (hbit <= wordweight)) {
@@ -295,50 +302,44 @@ static void unpack(chardesc * cd)
raster++;
}
}
- rowsleft -= repeatcount + 1;
+ rowsleft = (shalfword) (rowsleft - repeatcount - 1);
repeatcount = 0;
word = 0;
wordweight = 16;
count -= hbit;
- hbit = cd->cwidth;
+ hbit = (shalfword) cd->cwidth;
} else {
if (turnon)
word += gpower[wordweight];
*raster++ = word;
word = 0;
count -= wordweight;
- hbit -= wordweight;
+ hbit = (shalfword) (hbit - wordweight);
wordweight = 16;
}
}
turnon = !turnon;
}
- if ((rowsleft != 0) || ((integer) hbit != cd->cwidth))
+ if ((rowsleft != 0) || ((int) hbit != cd->cwidth))
pdftex_fail("error while unpacking; more bits than required");
}
}
-/*
- * readchar(): the main routine
- * Reads the character definition of character `c' into `cd' if available,
- * return FALSE (0) otherwise.
- */
-
-/*
- * readchar(): the main routine
- * check pk preamble if necessary,
- * read the next character definition into `cd',
- * return EOF if no character definition is available
- */
+@
+|readchar()|: the main routine
+check pk preamble if necessary,
+Reads the character definition of character `c' into `cd' if available,
+return FALSE (0) otherwise.
+@c
int readchar(boolean check_preamble, chardesc * cd)
{
register shalfword i;
- register integer k;
- register integer length = 0;
+ register int k;
+ register int length = 0;
/*
- * Check the preamble of the pkfile
+ Check the preamble of the pkfile
*/
if (check_preamble) {
if (pkbyte() != 247)
@@ -353,7 +354,7 @@ int readchar(boolean check_preamble, chardesc * cd)
k = pkquad(); /* vppp */
}
/*
- * Now we skip to the desired character definition
+ Now we skip to the desired character definition
*/
while ((flagbyte = pkbyte()) != 245) {
if (flagbyte < 240) {
@@ -378,8 +379,8 @@ int readchar(boolean check_preamble, chardesc * cd)
case 4:
case 5:
case 6:
- length = (flagbyte & 3) * 65536L + pkbyte() * 256L;
- length = length + pkbyte() - 4L;
+ length = (int) ((flagbyte & 3) * 65536L + pkbyte() * 256L);
+ length = (int) (length + pkbyte() - 4L);
cd->charcode = pkbyte();
(void) pktrio(); /* TFMwidth */
cd->xescape = pkduo(); /* pixelwidth */
@@ -389,7 +390,7 @@ int readchar(boolean check_preamble, chardesc * cd)
cd->yoff = pkduo();
break;
case 7:
- length = pkquad() - 9L;
+ length = (int) (pkquad() - 9L);
cd->charcode = pkquad();
(void) pkquad(); /* TFMwidth */
cd->xescape = pkquad(); /* pixelwidth */
diff --git a/Build/source/texk/web2c/luatexdir/font/sfnt.h b/Build/source/texk/web2c/luatexdir/font/sfnt.h
index 5d9bd2c973f..d41c019ffcf 100644
--- a/Build/source/texk/web2c/luatexdir/font/sfnt.h
+++ b/Build/source/texk/web2c/luatexdir/font/sfnt.h
@@ -19,7 +19,7 @@
You should have received a copy of the GNU General Public License along
with LuaTeX; if not, see <http://www.gnu.org/licenses/>. */
-/* $Id: sfnt.h 2271 2009-04-12 23:42:21Z oneiros $ */
+/* $Id: sfnt.h 3404 2010-01-28 11:17:10Z taco $ */
#ifndef _SFNT_H_
# define _SFNT_H_
@@ -157,7 +157,7 @@ extern int put_big_endian(void *s, LONG q, int n);
# ifdef XETEX
extern sfnt *sfnt_open(FT_Face face, int accept_types);
# elif defined(pdfTeX)
-extern sfnt *sfnt_open(unsigned char *buffer, integer buflen);
+extern sfnt *sfnt_open(unsigned char *buffer, int buflen);
# else
extern sfnt *sfnt_open(FILE * fp);
# endif
@@ -181,8 +181,8 @@ typedef struct {
# define ASSERT(a) assert(a)
# define RELEASE(a) free(a)
-# define NEW(a,b) xmalloc((a)*sizeof(b))
-# define RENEW(a,b,c) xrealloc(a, ((b)*sizeof(c)))
+# define NEW(a,b) xmalloc((unsigned)((unsigned)(a)*sizeof(b)))
+# define RENEW(a,b,c) xrealloc(a, (unsigned)((unsigned)(b)*sizeof(c)))
# define TT_ERROR pdftex_fail
# define WARN printf
diff --git a/Build/source/texk/web2c/luatexdir/font/sfnt.c b/Build/source/texk/web2c/luatexdir/font/sfnt.w
index 8812cd7fa6c..25fb3fcd086 100644
--- a/Build/source/texk/web2c/luatexdir/font/sfnt.c
+++ b/Build/source/texk/web2c/luatexdir/font/sfnt.w
@@ -1,168 +1,62 @@
-/* sfnt.c
-
- Copyright 2002 by Jin-Hwan Cho and Shunsaku Hirata,
- the dvipdfmx project team <dvipdfmx@project.ktug.or.kr>
- Copyright 2006-2008 Taco Hoekwater <taco@luatex.org>
+% sfnt.w
+%
+% Copyright 2002 by Jin-Hwan Cho and Shunsaku Hirata,
+% the dvipdfmx project team <dvipdfmx@@project.ktug.or.kr>
+% Copyright 2006-2008 Taco Hoekwater <taco@@luatex.org>
- This file is part of LuaTeX.
+% This file is part of LuaTeX.
- LuaTeX 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 2 of the License, or (at your
- option) any later version.
+% LuaTeX 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 2 of the License, or (at your
+% option) any later version.
- LuaTeX 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 Lesser General Public
- License for more details.
+% LuaTeX 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 Lesser General Public
+% License for more details.
- You should have received a copy of the GNU General Public License along
- with LuaTeX; if not, see <http://www.gnu.org/licenses/>. */
+% You should have received a copy of the GNU General Public License along
+% with LuaTeX; if not, see <http://www.gnu.org/licenses/>.
-/* Based on dvipdfmx-0.13.2c */
+@ Based on dvipdfmx-0.13.2c
+@c
#if HAVE_CONFIG_H
# include "config.h"
-#endif /* HAVE_CONFIG_H_ */
+#endif /* |HAVE_CONFIG_H_| */
#include <string.h>
-#ifndef pdfTeX
-# include "system.h"
-
-# include "error.h"
-# include "mem.h"
-# include "mfileio.h"
-#else
# include "ptexlib.h"
-#endif
-
-#include "sfnt.h"
+#include "font/sfnt.h"
static const char _svn_version[] =
- "$Id: sfnt.c 2271 2009-04-12 23:42:21Z oneiros $ $URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.40.6/source/texk/web2c/luatexdir/font/sfnt.c $";
-
-#ifdef XETEX
-UNSIGNED_BYTE ft_unsigned_byte(sfnt * f)
-{
- unsigned char byte;
- unsigned long length = 1;
-
- if (FT_Load_Sfnt_Table(f->ft_face, 0, f->loc, &byte, &length) != 0)
- TT_ERROR("sfnt: Freetype failure...");
- f->loc += 1;
-
- return byte;
-}
-
-SIGNED_BYTE ft_signed_byte(sfnt * f)
-{
- int b = ft_unsigned_byte(f);
- if (b >= 0x80)
- b -= 0x100;
- return (SIGNED_BYTE) b;
-}
-
-UNSIGNED_PAIR ft_unsigned_pair(sfnt * f)
-{
- unsigned char buf[2];
- unsigned long length = 2;
+ "$Id: sfnt.w 3584 2010-04-02 17:45:55Z hhenkel $ "
+"$URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.60.0/source/texk/web2c/luatexdir/font/sfnt.w $";
- if (FT_Load_Sfnt_Table(f->ft_face, 0, f->loc, buf, &length) != 0)
- TT_ERROR("sfnt: Freetype failure...");
- f->loc += 2;
- return (UNSIGNED_PAIR) ((unsigned) buf[0] << 8) + buf[1];
-}
-SIGNED_PAIR ft_signed_pair(sfnt * f)
-{
- int p = ft_unsigned_pair(f);
- if (p >= 0x8000U)
- p -= 0x10000U;
+@ type:
- return (SIGNED_PAIR) p;
-}
+ `true' (0x74727565): TrueType (Mac)
-UNSIGNED_QUAD ft_unsigned_quad(sfnt * f)
-{
- unsigned char buf[4];
- unsigned long length = 4;
+ `typ1' (0x74797031) (Mac): PostScript font housed in a sfnt wrapper
- if (FT_Load_Sfnt_Table(f->ft_face, 0, f->loc, buf, &length) != 0)
- TT_ERROR("sfnt: Freetype failure...");
- f->loc += 4;
+ 0x00010000: TrueType (Win)/OpenType
- return ((unsigned long) buf[0] << 24) + ((unsigned long) buf[1] << 16)
- + ((unsigned long) buf[2] << 8) + (unsigned long) buf[3];
-}
-
-unsigned long ft_read(unsigned char *buf, unsigned long len, sfnt * f)
-{
- unsigned long length = len;
- if (FT_Load_Sfnt_Table(f->ft_face, 0, f->loc, buf, &length) != 0)
- TT_ERROR("sfnt: Freetype failure...");
- f->loc += len;
-
- return length;
-}
-#endif
+ `OTTO': PostScript CFF font with OpenType wrapper
+ `ttcf': TrueType Collection
-/*
- * type:
- * `true' (0x74727565): TrueType (Mac)
- * `typ1' (0x74797031) (Mac): PostScript font housed in a sfnt wrapper
- * 0x00010000: TrueType (Win)/OpenType
- * `OTTO': PostScript CFF font with OpenType wrapper
- * `ttcf': TrueType Collection
-*/
+@c
#define SFNT_TRUETYPE 0x00010000UL
#define SFNT_MAC_TRUE 0x74727565UL
#define SFNT_OPENTYPE 0x00010000UL
#define SFNT_POSTSCRIPT 0x4f54544fUL
#define SFNT_TTC 0x74746366UL
-#ifdef XETEX
-sfnt *sfnt_open(FT_Face face, int accept_types)
-{
- sfnt *sfont;
- ULONG type;
-
- if (!face || !FT_IS_SFNT(face))
- return NULL;
-
- sfont = NEW(1, sfnt);
- sfont->ft_face = face;
- sfont->loc = 0;
- sfont->type = 0;
-
- type = sfnt_get_ulong(sfont);
-
- if (type == SFNT_TRUETYPE || type == SFNT_MAC_TRUE) {
- sfont->type = SFNT_TYPE_TRUETYPE;
- } else if (type == SFNT_OPENTYPE) {
- sfont->type = SFNT_TYPE_OPENTYPE;
- } else if (type == SFNT_POSTSCRIPT) {
- sfont->type = SFNT_TYPE_POSTSCRIPT;
- } else if (type == SFNT_TTC) {
- sfont->type = SFNT_TYPE_TTC;
- }
-
- if ((sfont->type & accept_types) == 0) {
- RELEASE(sfont);
- return NULL;
- }
-
- sfont->loc = 0;
-
- sfont->directory = NULL;
-
- return sfont;
-}
-#else /* not XETEX */
-# ifdef pdfTeX
-sfnt *sfnt_open(unsigned char *buffer, integer buflen)
+sfnt *sfnt_open(unsigned char *buffer, int buflen)
{
sfnt *sfont;
ULONG type;
@@ -188,40 +82,6 @@ sfnt *sfnt_open(unsigned char *buffer, integer buflen)
sfont->directory = NULL;
return sfont;
}
-# else
-sfnt *sfnt_open(FILE * fp)
-{
- sfnt *sfont;
- ULONG type;
-
- ASSERT(fp);
-
- rewind(fp);
-
- sfont = NEW(1, sfnt);
-
- sfont->stream = fp;
-
- type = sfnt_get_ulong(sfont);
-
- if (type == SFNT_TRUETYPE || type == SFNT_MAC_TRUE) {
- sfont->type = SFNT_TYPE_TRUETYPE;
- } else if (type == SFNT_OPENTYPE) {
- sfont->type = SFNT_TYPE_OPENTYPE;
- } else if (type == SFNT_POSTSCRIPT) {
- sfont->type = SFNT_TYPE_POSTSCRIPT;
- } else if (type == SFNT_TTC) {
- sfont->type = SFNT_TYPE_TTC;
- }
-
- rewind(sfont->stream);
-
- sfont->directory = NULL;
-
- return sfont;
-}
-# endif
-#endif
static void release_directory(struct sfnt_table_directory *td)
{
@@ -269,9 +129,9 @@ int put_big_endian(void *s, LONG q, int n)
return n;
}
-/* Convert four-byte number to big endianess
- * in a machine independent way.
- */
+@ Convert four-byte number to big endianess in a machine independent way.
+
+@c
static void convert_tag(char *tag, unsigned long u_tag)
{
int i;
@@ -284,9 +144,10 @@ static void convert_tag(char *tag, unsigned long u_tag)
return;
}
-/*
- * Computes the max power of 2 <= n
- */
+
+@ Computes the max power of 2 <= n
+
+@c
static unsigned max2floor(unsigned n)
{
int val = 1;
@@ -296,12 +157,13 @@ static unsigned max2floor(unsigned n)
val *= 2;
}
- return val;
+ return (unsigned) val;
}
-/*
- * Computes the log2 of the max power of 2 <= n
- */
+
+@ Computes the log2 of the max power of 2 <= n
+
+@c
static unsigned log2floor(unsigned n)
{
unsigned val = 0;
@@ -314,16 +176,17 @@ static unsigned log2floor(unsigned n)
return val;
}
+@ @c
static ULONG sfnt_calc_checksum(void *data, ULONG length)
{
ULONG chksum = 0;
BYTE *p, *endptr;
- int count = 0;
+ ULONG count = 0;
p = (BYTE *) data;
endptr = p + length;
while (p < endptr) {
- chksum += (p[0] << (8 * (3 - count)));
+ chksum = chksum + (ULONG) (p[0] << (8 * (3 - count)));
count = ((count + 1) & 3);
p++;
}
@@ -331,6 +194,7 @@ static ULONG sfnt_calc_checksum(void *data, ULONG length)
return chksum;
}
+@ @c
static int find_table_index(struct sfnt_table_directory *td, const char *tag)
{
int idx;
@@ -346,6 +210,7 @@ static int find_table_index(struct sfnt_table_directory *td, const char *tag)
return -1;
}
+@ @c
void sfnt_set_table(sfnt * sfont, const char *tag, void *data, ULONG length)
{
struct sfnt_table_directory *td;
@@ -371,6 +236,7 @@ void sfnt_set_table(sfnt * sfont, const char *tag, void *data, ULONG length)
return;
}
+@ @c
ULONG sfnt_find_table_len(sfnt * sfont, const char *tag)
{
ULONG length;
@@ -390,6 +256,7 @@ ULONG sfnt_find_table_len(sfnt * sfont, const char *tag)
return length;
}
+@ @c
ULONG sfnt_find_table_pos(sfnt * sfont, const char *tag)
{
ULONG offset;
@@ -409,6 +276,7 @@ ULONG sfnt_find_table_pos(sfnt * sfont, const char *tag)
return offset;
}
+@ @c
ULONG sfnt_locate_table(sfnt * sfont, const char *tag)
{
ULONG offset;
@@ -419,11 +287,12 @@ ULONG sfnt_locate_table(sfnt * sfont, const char *tag)
if (offset == 0)
TT_ERROR("sfnt: table not found...");
- sfnt_seek_set(sfont, offset);
+ sfnt_seek_set(sfont, (long) offset);
return offset;
}
+@ @c
int sfnt_read_table_directory(sfnt * sfont, ULONG offset)
{
struct sfnt_table_directory *td;
@@ -435,15 +304,8 @@ int sfnt_read_table_directory(sfnt * sfont, ULONG offset)
release_directory(sfont->directory);
sfont->directory = td = NEW(1, struct sfnt_table_directory);
-#ifdef XETEX
- ASSERT(sfont->ft_face);
-#elif defined(pdfTeX)
ASSERT(sfont->buffer);
-#else
- ASSERT(sfont->stream);
-#endif
-
- sfnt_seek_set(sfont, offset);
+ sfnt_seek_set(sfont, (long) offset);
td->version = sfnt_get_ulong(sfont);
td->num_tables = sfnt_get_ushort(sfont);
@@ -471,6 +333,7 @@ int sfnt_read_table_directory(sfnt * sfont, ULONG offset)
return 0;
}
+@ @c
int sfnt_require_table(sfnt * sfont, const char *tag, int must_exist)
{
struct sfnt_table_directory *td;
@@ -491,36 +354,28 @@ int sfnt_require_table(sfnt * sfont, const char *tag, int must_exist)
return 0;
}
-#ifndef pdfTeX
-# include "pdfobj.h"
-#endif
-
-/*
- * o All tables begin on four byte boundries, and pad any remaining space
- * between tables with zeros
- *
- * o Entries in the Table Directory must be sorted in ascending order by tag
- *
- * o The head table contains checksum of the whole font file.
- * To compute: first set it to 0, sum the entire font as ULONG,
- * then store 0xB1B0AFBA - sum.
- */
-
-#ifdef pdfTeX
-# include "luatexfont.h"
+
+
+@ All tables begin on four byte boundries, and pad any remaining space
+ between tables with zeros
+
+ Entries in the Table Directory must be sorted in ascending order by tag
+
+ The head table contains checksum of the whole font file.
+ To compute: first set it to 0, sum the entire font as ULONG,
+ then store 0xB1B0AFBA - sum.
+
+@c
+# include "font/luatexfont.h"
# undef MIN
# define MIN(a, b) (((a) < (b)) ? (a) : (b))
# define STREAM_COMPRESS
-#endif
static unsigned char wbuf[1024], padbytes[4] = { 0, 0, 0, 0 };
pdf_obj *sfnt_create_FontFile_stream(sfnt * sfont)
{
pdf_obj *stream;
-#ifndef pdfTeX
- pdf_obj *stream_dict;
-#endif
struct sfnt_table_directory *td;
long offset, nb_read, length;
int i, sr;
@@ -534,9 +389,9 @@ pdf_obj *sfnt_create_FontFile_stream(sfnt * sfont)
/* Header */
p = (char *) wbuf;
- p += sfnt_put_ulong(p, td->version);
+ p += sfnt_put_ulong(p, (LONG) td->version);
p += sfnt_put_ushort(p, td->num_kept_tables);
- sr = max2floor(td->num_kept_tables) * 16;
+ sr = (int) (max2floor(td->num_kept_tables) * 16);
p += sfnt_put_ushort(p, sr);
p += sfnt_put_ushort(p, log2floor(td->num_kept_tables));
p += sfnt_put_ushort(p, td->num_kept_tables * 16 - sr);
@@ -544,7 +399,7 @@ pdf_obj *sfnt_create_FontFile_stream(sfnt * sfont)
pdf_add_stream(stream, wbuf, 12);
/*
- * Compute start of actual tables (after headers).
+ Compute start of actual tables (after headers).
*/
offset = 12 + 16 * td->num_kept_tables;
for (i = 0; i < td->num_tables; i++) {
@@ -557,12 +412,12 @@ pdf_obj *sfnt_create_FontFile_stream(sfnt * sfont)
p = (char *) wbuf;
memcpy(p, td->tables[i].tag, 4);
p += 4;
- p += sfnt_put_ulong(p, td->tables[i].check_sum);
+ p += sfnt_put_ulong(p, (LONG) td->tables[i].check_sum);
p += sfnt_put_ulong(p, offset);
- p += sfnt_put_ulong(p, td->tables[i].length);
+ p += sfnt_put_ulong(p, (LONG) td->tables[i].length);
pdf_add_stream(stream, wbuf, 16);
- offset += td->tables[i].length;
+ offset = (long) (offset + (long) td->tables[i].length);
}
}
@@ -575,23 +430,17 @@ pdf_obj *sfnt_create_FontFile_stream(sfnt * sfont)
offset += length;
}
if (!td->tables[i].data) {
-#ifdef XETEX
- if (!sfont->ft_face)
-#elif defined(pdfTeX)
if (!sfont->buffer)
-#else
- if (!sfont->stream)
-#endif
{
pdf_release_obj(stream);
TT_ERROR("Font file not opened or already closed...");
return NULL;
}
- length = td->tables[i].length;
- sfnt_seek_set(sfont, td->tables[i].offset);
+ length = (long) td->tables[i].length;
+ sfnt_seek_set(sfont, (long) td->tables[i].offset);
while (length > 0) {
- nb_read = sfnt_read(wbuf, MIN(length, 1024), sfont);
+ nb_read = sfnt_read(wbuf, (int) MIN(length, 1024), sfont);
if (nb_read < 0) {
pdf_release_obj(stream);
TT_ERROR("Reading file failed...");
@@ -604,18 +453,14 @@ pdf_obj *sfnt_create_FontFile_stream(sfnt * sfont)
} else {
pdf_add_stream(stream,
(unsigned char *) td->tables[i].data,
- td->tables[i].length);
+ (long) td->tables[i].length);
RELEASE(td->tables[i].data);
td->tables[i].data = NULL;
}
/* Set offset for next table */
- offset += td->tables[i].length;
+ offset = (long) (offset + (long) td->tables[i].length);
}
}
-#ifndef pdfTeX
- stream_dict = pdf_stream_dict(stream);
- pdf_add_dict(stream_dict, pdf_new_name("Length1"), pdf_new_number(offset));
-#endif
return stream;
}
diff --git a/Build/source/texk/web2c/luatexdir/font/subfont.txt b/Build/source/texk/web2c/luatexdir/font/subfont.txt
index 9fe053cbb9c..eaefae02813 100644
--- a/Build/source/texk/web2c/luatexdir/font/subfont.txt
+++ b/Build/source/texk/web2c/luatexdir/font/subfont.txt
@@ -1,74 +1,43 @@
-map entry:
+map entry:cyberb @ Unicode @ <cyberbit.ttf PidEid = 3, 1 means cyberb < INFIX > = >look at Unicode.sfd = >find the mapping = >charcode = >PidEid = 3, 1 = >glyphs eg cyberb01 = >subfont 01 in Unicode.sfd = >charcodes Infix can be anything, thus the question:given a tfm name, how to find out
+ whether this is a subfont ?
+ It is safe to limit the infix to be composed from hexadecimal digits only ?
+ If so, one possibility is : (1)
+ while last
+ -char -of - tfmname is a hexdigit
+ do
+ remove the last char from tfmname
+ do
+ a lookup for the tfmname
+ if found an entry with subfont flag then break enddo(2)
+ Or, when a map entry with subfont flag is scanned,
+ let pdftex create all the relevant entries.
+ Which may be a safer and faster solution(but wastes more memory)
-cyberb@Unicode@ <cyberbit.ttf PidEid=3,1
-means
-
-cyberb<INFIX> => look at Unicode.sfd => find the mapping => charcode
- => PidEid=3,1 => glyphs
-
-eg cyberb01 => subfont 01 in Unicode.sfd => charcodes
-
-Infix can be anything, thus the question: given a tfm name, how to find out
-whether this is a subfont?
-
-It is safe to limit the infix to be composed from hexadecimal digits only?
-
-If so, one possibility is:
-
-(1)
-while last-char-of-tfmname is a hexdigit do
- remove the last char from tfmname
- do a lookup for the tfmname
- if found an entry with subfont flag then
- break
-enddo
-
-(2)
-Or, when a map entry with subfont flag is scanned, let pdftex create all
-the relevant entries. Which may be a safer and faster solution (but wastes more
-memory)
-
-
-Let's do (2), as infix can be any word.
+ Let 's do (2), as infix can be any word.
Implementation:
-- let's have a map entry:
-
-cyberb@Unicode@ <cyberbit.ttf PidEid=3,1
-
-- actions:
- - read Unicode.sfd
- - create corresponding sfd mapping like ("01", "Unicode") => long[256]
- - added those subfont to an AVL tree
- - create map entries for cyberb01--cyberbff, each has a pointer to the
- corresponding sfd mapping entry
-
-- extended attributes for map entry:
- - Pid
- - Eid
- - sfd_map
-
-- sfd_mapping:
- - name: sfd name, eg "Unicode"
- - infix, eg "01"
- - mapping: long[256]
-
-- how to find out whether a sfd has been loaded:
- - lookup for any entry with the given sfd name
-
-- functions:
- - load_sfd
- - lookup_subfont
- - extend reading map entries
-
-- when writting ttf:
- - if re-encoded --> process like in case of type1 fonts
- - if PidEid is being used:
- - read cmap tables: store (ttfname, pid, eid)
- - search for used chars
- - use sfd to find the charcodes
- - look into cmap to
+- let' s have a map entry : cyberb @ Unicode @ <cyberbit.ttf PidEid = 3, 1 - actions:
+ -read Unicode.sfd
+ - create corresponding sfd mapping like("01", "Unicode") =
+ >long[256]
+ - added those subfont to an AVL tree -
+ create map entries for cyberb01-- cyberbff,
+ each has a pointer to the corresponding sfd mapping entry -
+ extended attributes for map entry:-Pid - Eid - sfd_map -
+ sfd_mapping:-name:sfd name, eg "Unicode" - infix,
+ eg "01" - mapping:long[256]
+
+-how to find out whether a sfd has been loaded:
+ -lookup for any entry with the given sfd
+ name - functions:-load_sfd -
+ lookup_subfont -
+ extend reading map entries -
+ when writting ttf:-if re - encoded-- >
+ process like in case of type1 fonts -
+ if PidEid is being used:-read cmap
+ tables:store(ttfname, pid, eid)
+ -search for used chars - use sfd to find the charcodes - look into cmap to
diff --git a/Build/source/texk/web2c/luatexdir/font/subfont.c b/Build/source/texk/web2c/luatexdir/font/subfont.w
index 183c78b4f34..5ae8639bb41 100644
--- a/Build/source/texk/web2c/luatexdir/font/subfont.c
+++ b/Build/source/texk/web2c/luatexdir/font/subfont.w
@@ -1,39 +1,42 @@
-/* subfont.c
-
- Copyright 2005-2006 Han The Thanh <thanh@pdftex.org>
- Copyright 2006-2008 Taco Hoekwater <taco@luatex.org>
+% subfont.w
+%
+% Copyright 2005-2006 Han The Thanh <thanh@@pdftex.org>
+% Copyright 2006-2008 Taco Hoekwater <taco@@luatex.org>
- This file is part of LuaTeX.
+% This file is part of LuaTeX.
- LuaTeX 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 2 of the License, or (at your
- option) any later version.
+% LuaTeX 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 2 of the License, or (at your
+% option) any later version.
- LuaTeX 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 Lesser General Public
- License for more details.
+% LuaTeX 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 Lesser General Public
+% License for more details.
- You should have received a copy of the GNU General Public License along
- with LuaTeX; if not, see <http://www.gnu.org/licenses/>. */
+% You should have received a copy of the GNU General Public License along
+% with LuaTeX; if not, see <http://www.gnu.org/licenses/>.
+@ @c
#include "ptexlib.h"
#include <string.h>
static const char _svn_version[] =
- "$Id: subfont.c 2448 2009-06-08 07:43:50Z taco $ $URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.40.6/source/texk/web2c/luatexdir/font/subfont.c $";
+ "$Id: subfont.w 3584 2010-04-02 17:45:55Z hhenkel $ "
+"$URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.60.0/source/texk/web2c/luatexdir/font/subfont.w $";
+@ @c
static struct avl_table *sfd_tree = NULL;
static unsigned char *sfd_buffer = NULL;
-static integer sfd_size = 0;
-static integer sfd_curbyte = 0;
+static int sfd_size = 0;
+static int sfd_curbyte = 0;
#define SFD_BUF_SIZE SMALL_BUF_SIZE
#define sfd_close() xfclose(sfd_file, cur_file_name)
-#define sfd_open() (sfd_file = fopen((char *) nameoffile + 1, FOPEN_RBIN_MODE))
+#define sfd_open(a) (sfd_file = fopen((char *)(a), FOPEN_RBIN_MODE))
#define sfd_read_file() readbinfile(sfd_file,&sfd_buffer,&sfd_size)
#define sfd_getchar() sfd_buffer[sfd_curbyte++]
@@ -96,7 +99,7 @@ void sfd_free(void)
static void sfd_getline(boolean expect_eof)
{
char *p;
- int c;
+ char c;
restart:
if (sfd_eof()) {
if (expect_eof)
@@ -106,7 +109,7 @@ static void sfd_getline(boolean expect_eof)
}
p = sfd_line;
do {
- c = sfd_getchar();
+ c = (char) sfd_getchar();
append_char_to_buf(c, p, sfd_line, SFD_BUF_SIZE);
} while (c != 10 && !sfd_eof());
append_eol(p, sfd_line, SFD_BUF_SIZE);
@@ -114,12 +117,13 @@ static void sfd_getline(boolean expect_eof)
goto restart;
}
+@ @c
static sfd_entry *read_sfd(char *sfd_name)
{
void **aa;
sfd_entry *sfd, tmp_sfd;
subfont_entry *sf;
- char *ftemp = NULL;
+
char buf[SMALL_BUF_SIZE], *p;
long int i, j, k;
int n;
@@ -134,44 +138,30 @@ static sfd_entry *read_sfd(char *sfd_name)
sfd = (sfd_entry *) avl_find(sfd_tree, &tmp_sfd);
if (sfd != NULL)
return sfd;
- set_cur_file_name(sfd_name);
- if (sfd_buffer != NULL) {
- xfree(sfd_buffer);
- sfd_buffer = NULL;
- }
+ xfree(sfd_buffer);
sfd_curbyte = 0;
sfd_size = 0;
- callback_id = callback_defined(find_sfd_file_callback);
- if (callback_id > 0) {
- if (run_callback(callback_id, "S->S", cur_file_name, &ftemp)) {
- if (ftemp != NULL && strlen(ftemp)) {
- if (cur_file_name)
- free(cur_file_name);
- cur_file_name = xstrdup(ftemp);
- free(ftemp);
+ cur_file_name = luatex_find_file(sfd_name, find_sfd_file_callback);
+ if (cur_file_name) {
+ callback_id = callback_defined(read_sfd_file_callback);
+ if (callback_id > 0) {
+ if (!(run_callback(callback_id, "S->bSd", cur_file_name,
+ &file_opened, &sfd_buffer, &sfd_size) &&
+ file_opened && sfd_size > 0)) {
+ pdftex_warn("cannot open SFD file for reading");
+ cur_file_name = NULL;
+ return NULL;
}
+ } else {
+ if (!sfd_open(cur_file_name)) {
+ pdftex_warn("cannot open SFD file for reading");
+ cur_file_name = NULL;
+ return NULL;
+ }
+ sfd_read_file();
+ sfd_close();
}
- } else {
- cur_file_name = kpse_find_file(cur_file_name, kpse_sfd_format, 0);
- }
- callback_id = callback_defined(read_sfd_file_callback);
- if (callback_id > 0) {
- if (!(run_callback(callback_id, "S->bSd", cur_file_name,
- &file_opened, &sfd_buffer, &sfd_size) &&
- file_opened && sfd_size > 0)) {
- pdftex_warn("cannot open SFD file for reading");
- cur_file_name = NULL;
- return NULL;
- }
- } else {
- if (!sfd_open()) {
- pdftex_warn("cannot open SFD file for reading");
- cur_file_name = NULL;
- return NULL;
- }
- sfd_read_file();
- sfd_close();
}
tex_printf("{");
tex_printf("%s", cur_file_name);
@@ -220,6 +210,7 @@ static sfd_entry *read_sfd(char *sfd_name)
return sfd;
}
+@ @c
boolean handle_subfont_fm(fm_entry * fm, int mode)
{
size_t l;
@@ -230,16 +221,16 @@ boolean handle_subfont_fm(fm_entry * fm, int mode)
char buf[SMALL_BUF_SIZE];
assert(fm->tfm_name != NULL);
p = fm->tfm_name;
- q = strchr(p, '@'); /* search for the first '@' */
+ q = strchr(p, '@@'); /* search for the first '@@' */
if (q == NULL)
return false;
- r = strchr(q + 1, '@'); /* search for the second '@' */
+ r = strchr(q + 1, '@@'); /* search for the second '@@' */
if (r == NULL)
return false;
if (q <= p || r <= q + 1 /* prefix or sfd name is empty */
- || r - p != (int) strlen(p) - 1) /* or the second '@' is not the last char yet */
+ || r - p != (int) strlen(p) - 1) /* or the second '@@' is not the last char yet */
return false;
- l = r - (q + 1); /* length of sfd name */
+ l = (size_t) (r - (q + 1)); /* length of sfd name */
strncpy(buf, q + 1, l);
buf[l] = 0;
check_buf(strlen(buf) + 4, SMALL_BUF_SIZE);
@@ -250,13 +241,12 @@ boolean handle_subfont_fm(fm_entry * fm, int mode)
/* at this point we know fm is a subfont */
set_subfont(fm);
xfree(fm->ps_name);
- fm->ps_name = NULL;
/* set default values for PidEid */
if (fm->pid == -1) {
fm->pid = 3;
fm->eid = 1;
}
- l = q - p; /* length of base tfm name (prefix) */
+ l = (size_t) (q - p); /* length of base tfm name (prefix) */
for (sf = sfd->subfont; sf != NULL; sf = sf->next) {
strncpy(buf, p, l);
buf[l] = 0;
diff --git a/Build/source/texk/web2c/luatexdir/font/texfont.h b/Build/source/texk/web2c/luatexdir/font/texfont.h
index 4963f71cad2..6a021726748 100644
--- a/Build/source/texk/web2c/luatexdir/font/texfont.h
+++ b/Build/source/texk/web2c/luatexdir/font/texfont.h
@@ -1,6 +1,6 @@
/* texfont.h Main font API implementation for the pascal parts
-
- Copyright 2006-2008 Taco Hoekwater <taco@luatex.org>
+
+ Copyright 2006-2010 Taco Hoekwater <taco@luatex.org>
This file is part of LuaTeX.
@@ -17,31 +17,29 @@
You should have received a copy of the GNU General Public License along
with LuaTeX; if not, see <http://www.gnu.org/licenses/>. */
-/* $Id: texfont.h 2448 2009-06-08 07:43:50Z taco $ */
+/* $Id: texfont.h 3482 2010-03-13 11:18:28Z taco $ */
/* Here we have the interface to LuaTeX's font system, as seen from the
main pascal program. There is a companion list in luatex.defines to
keep web2c happy */
/* this file is read at the end of ptexlib.h, which is called for at
- the end of luatexcoerce.h, as well as from the C sources
+ the end of luatexcoerce.h, as well as from the C sources
*/
#ifndef TEXFONT_H
# define TEXFONT_H
-# include "luatexdir/managed-sa.h"
-
# define pointer halfword
typedef struct liginfo {
- integer adj;
- integer lig;
+ int adj;
+ int lig;
char type;
} liginfo;
typedef struct kerninfo {
- integer adj;
+ int adj;
scaled sc;
} kerninfo;
@@ -53,23 +51,23 @@ typedef struct extinfo {
int advance;
int extender;
} extinfo;
-
+/* todo: maybe create a 'math info structure' */
typedef struct charinfo {
char *name; /* postscript character name */
liginfo *ligatures; /* ligature items */
kerninfo *kerns; /* kern items */
- real_eight_bits *packets; /* virtual commands. */
+ eight_bits *packets; /* virtual commands. */
unsigned short index; /* CID index */
- integer remainder; /* spare value for odd items, could be union-ed with extensible */
+ int remainder; /* spare value for odd items, could be union-ed with extensible */
scaled width; /* width */
scaled height; /* height */
scaled depth; /* depth */
scaled italic; /* italic correction */
scaled top_accent; /* top accent alignment */
scaled bot_accent; /* bot accent alignment */
- integer ef; /* font expansion factor */
- integer lp; /* left protruding factor */
- integer rp; /* right protruding factor */
+ int ef; /* font expansion factor */
+ int lp; /* left protruding factor */
+ int rp; /* right protruding factor */
char tag; /* list / ext taginfo */
char used; /* char is typeset ? */
char *tounicode; /* unicode equivalent */
@@ -85,20 +83,6 @@ typedef struct charinfo {
scaled *bottom_left_math_kern_array;
} charinfo;
-
-/* this is for speed reasons, it is called from the web source
- when more than two of the traditional four char values are needed
- at the same time. the structure |charinfo_short| is defined in
- web */
-
-# ifndef luaTeX
-typedef struct charinfo_short {
- scaled ci_wd; /* width */
- scaled ci_ht; /* height */
- scaled ci_dp; /* depth */
-} charinfo_short;
-# endif
-
# define EXT_NORMAL 0
# define EXT_REPEAT 1
@@ -114,66 +98,69 @@ extern extinfo *copy_variants(extinfo * o);
extern extinfo *new_variant(int glyph, int startconnect, int endconnect,
int advance, int repeater);
-extern charinfo_short char_info_short(internal_font_number f, integer c);
+extern scaled_whd get_charinfo_whd(internal_font_number f, int c);
typedef struct texfont {
- integer _font_size;
- integer _font_dsize;
+ int _font_size;
+ int _font_dsize;
+ int _font_units_per_em;
char *_font_name;
char *_font_area;
char *_font_filename;
char *_font_fullname;
+ char *_font_psname;
char *_font_encodingname;
char *_font_cidregistry;
char *_font_cidordering;
- integer _font_cidversion;
- integer _font_cidsupplement;
+ int _font_cidversion;
+ int _font_cidsupplement;
- integer _font_ec;
+ int _font_ec;
unsigned _font_checksum; /* internal information */
char _font_used; /* internal information */
char _font_touched; /* internal information */
- integer _font_cache_id; /* internal information */
+ int _font_cache_id; /* internal information */
char _font_encodingbytes; /* 1 or 2 bytes */
- integer _font_slant; /* a slant in ppt */
- integer _font_extend; /* an extension in ppt, or 0 */
+
+ int _font_slant; /* a slant in ppt */
+ int _font_extend; /* an extension in ppt, or 1000 */
+ int _font_expand_ratio; /* expansion ratio of a particular font */
+ internal_font_number _font_shrink; /* font at limit of shrinking */
+ internal_font_number _font_stretch; /* font at limit of stretching */
+ int _font_step; /* amount of one step of expansion */
+ boolean _font_auto_expand; /* this font is auto-expanded? */
+
char _font_tounicode; /* 1 if info is present */
- fm_entry_ptr _font_map;
- integer _font_type;
- integer _font_format;
- integer _font_embedding;
- integer _font_bc;
- integer _hyphen_char;
- integer _skew_char;
- integer _font_natural_dir;
+ fm_entry *_font_map;
+ int _font_type;
+ int _font_format;
+ int _font_embedding;
+ int _font_bc;
+ int _hyphen_char;
+ int _skew_char;
+ int _font_natural_dir;
charinfo *_left_boundary;
charinfo *_right_boundary;
- integer _font_params;
+ int _font_params;
scaled *_param_base;
- integer _font_math_params;
+ int _font_math_params;
scaled *_math_param_base;
sa_tree characters;
- integer charinfo_count;
- integer charinfo_size;
+ int charinfo_count;
+ int charinfo_size;
charinfo *charinfo;
int *charinfo_cache;
- integer ligatures_disabled;
+ int ligatures_disabled;
- integer _pdf_font_num; /* maps to a PDF resource ID */
- scaled _pdf_font_size; /* maps to a PDF font size */
+ int _pdf_font_num; /* maps to a PDF resource ID */
internal_font_number _pdf_font_blink; /* link to base font for expanded fonts */
internal_font_number _pdf_font_elink; /* link to expanded fonts for base font */
- integer _pdf_font_expand_ratio; /* expansion ratio of a particular font */
- internal_font_number _pdf_font_shrink; /* font at limit of shrinking */
- internal_font_number _pdf_font_stretch; /* font at limit of stretching */
- integer _pdf_font_step; /* amount of one step of expansion */
- boolean _pdf_font_auto_expand; /* this font is auto-expanded? */
str_number _pdf_font_attr; /* pointer to additional attributes */
} texfont;
@@ -216,19 +203,20 @@ extern const char *font_embedding_strings[];
# define font_dsize(a) font_tables[a]->_font_dsize
# define set_font_dsize(a,b) font_dsize(a) = b
+# define font_units_per_em(a) font_tables[a]->_font_units_per_em
+# define set_font_units_per_em(a,b) font_units_per_em(a) = b
+
# define font_name(a) font_tables[a]->_font_name
# define get_font_name(a) (unsigned char *)font_name(a)
# define set_font_name(f,b) font_name(f) = b
# define tex_font_name(a) maketexstring(font_name(a))
-boolean cmp_font_name(integer, str_number);
-
# define font_area(a) font_tables[a]->_font_area
# define get_font_area(a) (unsigned char *)font_area(a)
# define set_font_area(f,b) font_area(f) = b
# define tex_font_area(a) maketexstring(font_area(a))
-boolean cmp_font_area(integer, str_number);
+boolean cmp_font_area(int, str_number);
# define font_reassign(a,b) { if (a!=NULL) free(a); a = b; }
@@ -238,11 +226,12 @@ boolean cmp_font_area(integer, str_number);
# define font_fullname(a) font_tables[a]->_font_fullname
# define set_font_fullname(f,b) font_reassign(font_fullname(f),b)
+# define font_psname(a) font_tables[a]->_font_psname
+# define set_font_psname(f,b) font_reassign(font_psname(f),b)
+
# define font_encodingname(a) font_tables[a]->_font_encodingname
# define set_font_encodingname(f,b) font_reassign(font_encodingname(f),b)
-boolean font_shareable(internal_font_number, internal_font_number);
-
# define cmp_font_filename(a,b) (!(font_filename(a)!=NULL || font_filename(b)!=NULL || \
strcmp(font_filename(a),font_filename(b))))
# define cmp_font_fullname(a,b) (!(font_fullname(a)!=NULL || font_fullname(b)!=NULL || \
@@ -300,6 +289,21 @@ boolean font_shareable(internal_font_number, internal_font_number);
# define font_extend(a) font_tables[a]->_font_extend
# define set_font_extend(a,b) font_extend(a) = b
+# define font_expand_ratio(a) font_tables[a]->_font_expand_ratio
+# define set_font_expand_ratio(a,b) font_expand_ratio(a) = b
+
+# define font_shrink(a) font_tables[a]->_font_shrink
+# define set_font_shrink(a,b) font_shrink(a) = b
+
+# define font_stretch(a) font_tables[a]->_font_stretch
+# define set_font_stretch(a,b) font_stretch(a) = b
+
+# define font_step(a) font_tables[a]->_font_step
+# define set_font_step(a,b) font_step(a) = b
+
+# define font_auto_expand(a) font_tables[a]->_font_auto_expand
+# define set_font_auto_expand(a,b) font_auto_expand(a) = b
+
# define font_tounicode(a) font_tables[a]->_font_tounicode
# define set_font_tounicode(a,b) font_tounicode(a) = b
@@ -312,32 +316,14 @@ boolean font_shareable(internal_font_number, internal_font_number);
# define font_natural_dir(a) font_tables[a]->_font_natural_dir
# define set_font_natural_dir(a,b) font_natural_dir(a) = b
-# define pdf_font_size(a) font_tables[a]->_pdf_font_size
-# define set_pdf_font_size(a,b) pdf_font_size(a) = b
-
# define pdf_font_num(a) font_tables[a]->_pdf_font_num
# define set_pdf_font_num(a,b) pdf_font_num(a) = b
-# define pdf_font_blink(a) font_tables[a]->_pdf_font_blink
-# define set_pdf_font_blink(a,b) pdf_font_blink(a) = b
-
-# define pdf_font_elink(a) font_tables[a]->_pdf_font_elink
-# define set_pdf_font_elink(a,b) pdf_font_elink(a) = b
-
-# define pdf_font_expand_ratio(a) font_tables[a]->_pdf_font_expand_ratio
-# define set_pdf_font_expand_ratio(a,b) pdf_font_expand_ratio(a) = b
-
-# define pdf_font_shrink(a) font_tables[a]->_pdf_font_shrink
-# define set_pdf_font_shrink(a,b) pdf_font_shrink(a) = b
-
-# define pdf_font_stretch(a) font_tables[a]->_pdf_font_stretch
-# define set_pdf_font_stretch(a,b) pdf_font_stretch(a) = b
+# define pdf_font_blink(a) font_tables[a]->_pdf_font_blink
+# define set_pdf_font_blink(a,b) pdf_font_blink(a) = b
-# define pdf_font_step(a) font_tables[a]->_pdf_font_step
-# define set_pdf_font_step(a,b) pdf_font_step(a) = b
-
-# define pdf_font_auto_expand(a) font_tables[a]->_pdf_font_auto_expand
-# define set_pdf_font_auto_expand(a,b) pdf_font_auto_expand(a) = b
+# define pdf_font_elink(a) font_tables[a]->_pdf_font_elink
+# define set_pdf_font_elink(a,b) pdf_font_elink(a) = b
# define pdf_font_attr(a) font_tables[a]->_pdf_font_attr
# define set_pdf_font_attr(a,b) pdf_font_attr(a) = b
@@ -412,9 +398,15 @@ typedef enum {
top_left_kern = 4
} font_math_kern_codes;
-extern charinfo *get_charinfo(internal_font_number f, integer c);
-extern integer char_exists(internal_font_number f, integer c);
-extern charinfo *char_info(internal_font_number f, integer c);
+extern charinfo *get_charinfo(internal_font_number f, int c);
+extern int char_exists(internal_font_number f, int c);
+extern charinfo *char_info(internal_font_number f, int c);
+
+/* Here is a quick way to test if a glyph exists, when you are
+already certain the font |f| exists, and that the |c| is a regular
+glyph id, not one of the two special boundary objects.
+*/
+# define quick_char_exists(f,c) get_sa_item(font_tables[f]->characters,c)
extern void set_charinfo_width(charinfo * ci, scaled val);
extern void set_charinfo_height(charinfo * ci, scaled val);
@@ -430,7 +422,7 @@ extern void set_charinfo_name(charinfo * ci, char *val);
extern void set_charinfo_tounicode(charinfo * ci, char *val);
extern void set_charinfo_ligatures(charinfo * ci, liginfo * val);
extern void set_charinfo_kerns(charinfo * ci, kerninfo * val);
-extern void set_charinfo_packets(charinfo * ci, real_eight_bits * val);
+extern void set_charinfo_packets(charinfo * ci, eight_bits * val);
extern void set_charinfo_extensible(charinfo * ci, int a, int b, int c, int d);
extern void set_charinfo_ef(charinfo * ci, scaled val);
extern void set_charinfo_lp(charinfo * ci, scaled val);
@@ -452,23 +444,23 @@ extern scaled get_charinfo_italic(charinfo * ci);
extern scaled get_charinfo_top_accent(charinfo * ci);
extern scaled get_charinfo_bot_accent(charinfo * ci);
extern char get_charinfo_tag(charinfo * ci);
-extern integer get_charinfo_remainder(charinfo * ci);
+extern int get_charinfo_remainder(charinfo * ci);
extern char get_charinfo_used(charinfo * ci);
-extern integer get_charinfo_index(charinfo * ci);
+extern int get_charinfo_index(charinfo * ci);
extern char *get_charinfo_name(charinfo * ci);
extern char *get_charinfo_tounicode(charinfo * ci);
extern liginfo *get_charinfo_ligatures(charinfo * ci);
extern kerninfo *get_charinfo_kerns(charinfo * ci);
-extern real_eight_bits *get_charinfo_packets(charinfo * ci);
-extern integer get_charinfo_ef(charinfo * ci);
-extern integer get_charinfo_rp(charinfo * ci);
-extern integer get_charinfo_lp(charinfo * ci);
-extern integer get_charinfo_extensible(charinfo * ci, int which);
+extern eight_bits *get_charinfo_packets(charinfo * ci);
+extern int get_charinfo_ef(charinfo * ci);
+extern int get_charinfo_rp(charinfo * ci);
+extern int get_charinfo_lp(charinfo * ci);
+extern int get_charinfo_extensible(charinfo * ci, int which);
-extern integer ext_top(internal_font_number f, integer c);
-extern integer ext_bot(internal_font_number f, integer c);
-extern integer ext_rep(internal_font_number f, integer c);
-extern integer ext_mid(internal_font_number f, integer c);
+extern int ext_top(internal_font_number f, int c);
+extern int ext_bot(internal_font_number f, int c);
+extern int ext_rep(internal_font_number f, int c);
+extern int ext_mid(internal_font_number f, int c);
# define set_ligature_item(f,b,c,d) { f.type = b; f.adj = c; f.lig = d; }
@@ -514,30 +506,30 @@ extern integer ext_mid(internal_font_number f, integer c);
# define list_tag 2 /* character has a successor in a charlist */
# define ext_tag 3 /* character is extensible */
-extern scaled char_height(internal_font_number f, integer c);
-extern scaled char_width(internal_font_number f, integer c);
-extern scaled char_depth(internal_font_number f, integer c);
-extern scaled char_italic(internal_font_number f, integer c);
-extern scaled char_top_accent(internal_font_number f, integer c);
-extern scaled char_bot_accent(internal_font_number f, integer c);
+extern scaled char_height(internal_font_number f, int c);
+extern scaled char_width(internal_font_number f, int c);
+extern scaled char_depth(internal_font_number f, int c);
+extern scaled char_italic(internal_font_number f, int c);
+extern scaled char_top_accent(internal_font_number f, int c);
+extern scaled char_bot_accent(internal_font_number f, int c);
-extern liginfo *char_ligatures(internal_font_number f, integer c);
-extern kerninfo *char_kerns(internal_font_number f, integer c);
-extern real_eight_bits *char_packets(internal_font_number f, integer c);
+extern liginfo *char_ligatures(internal_font_number f, int c);
+extern kerninfo *char_kerns(internal_font_number f, int c);
+extern eight_bits *char_packets(internal_font_number f, int c);
# define has_lig(f,b) (char_exists(f,b) &&( char_ligatures(f,b) != NULL))
# define has_kern(f,b) (char_exists(f,b) && (char_kerns(f,b) != NULL))
# define has_packet(f,b) (char_exists(f,b) && (char_packets(f,b) != NULL))
-extern integer char_remainder(internal_font_number f, integer c);
-extern char char_tag(internal_font_number f, integer c);
-extern char char_used(internal_font_number f, integer c);
-extern char *char_name(internal_font_number f, integer c);
-extern integer char_index(internal_font_number f, integer c);
+extern int char_remainder(internal_font_number f, int c);
+extern char char_tag(internal_font_number f, int c);
+extern char char_used(internal_font_number f, int c);
+extern char *char_name(internal_font_number f, int c);
+extern int char_index(internal_font_number f, int c);
-scaled raw_get_kern(internalfontnumber f, integer lc, integer rc);
-scaled get_kern(internalfontnumber f, integer lc, integer rc);
-liginfo get_ligature(internalfontnumber f, integer lc, integer rc);
+scaled raw_get_kern(internal_font_number f, int lc, int rc);
+scaled get_kern(internal_font_number f, int lc, int rc);
+liginfo get_ligature(internal_font_number f, int lc, int rc);
# define EXT_TOP 0
# define EXT_BOT 1
@@ -546,44 +538,43 @@ liginfo get_ligature(internalfontnumber f, integer lc, integer rc);
extern texfont **font_tables;
-integer new_font(void);
-integer copy_font(integer id);
-integer scale_font(integer id, integer atsize);
-integer max_font_id(void);
-void set_max_font_id(integer id);
-integer new_font_id(void);
+int new_font(void);
+extern void font_malloc_charinfo(internal_font_number f, int num);
+int copy_font(int id);
+int scale_font(int id, int atsize);
+int max_font_id(void);
+void set_max_font_id(int id);
+int new_font_id(void);
void create_null_font(void);
-void delete_font(integer id);
-boolean is_valid_font(integer id);
+void delete_font(int id);
+boolean is_valid_font(int id);
void dump_font(int font_number);
void undump_font(int font_number);
-integer test_no_ligatures(internal_font_number f);
+int test_no_ligatures(internal_font_number f);
void set_no_ligatures(internal_font_number f);
-extern integer get_tag_code(internal_font_number f, integer c);
-extern integer get_lp_code(internal_font_number f, integer c);
-extern integer get_rp_code(internal_font_number f, integer c);
-extern integer get_ef_code(internal_font_number f, integer c);
+extern int get_tag_code(internal_font_number f, int c);
+extern int get_lp_code(internal_font_number f, int c);
+extern int get_rp_code(internal_font_number f, int c);
+extern int get_ef_code(internal_font_number f, int c);
-extern void set_tag_code(internal_font_number f, integer c, integer i);
-extern void set_lp_code(internal_font_number f, integer c, integer i);
-extern void set_rp_code(internal_font_number f, integer c, integer i);
-extern void set_ef_code(internal_font_number f, integer c, integer i);
+extern void set_tag_code(internal_font_number f, int c, int i);
+extern void set_lp_code(internal_font_number f, int c, int i);
+extern void set_rp_code(internal_font_number f, int c, int i);
+extern void set_ef_code(internal_font_number f, int c, int i);
int read_tfm_info(internal_font_number f, const char *nom, scaled s);
/* from dofont.c */
-extern int read_font_info(pointer u, str_number nom, scaled s, integer ndir);
+extern int read_font_info(pointer u, char *cnom, scaled s, int ndir);
extern int find_font_id(const char *nom, scaled s);
/* for and from vfpacket.c */
-# define scan_special 3 /* look into special text */ /* this is a hack */
-
typedef enum { packet_char_code,
packet_font_code,
packet_pop_code,
@@ -598,11 +589,23 @@ typedef enum { packet_char_code,
packet_end_code
} packet_command_codes;
-extern scaled store_scaled_f(scaled sq, integer fw);
+extern scaled store_scaled_f(scaled sq, int fw);
-extern void do_vf_packet(internal_font_number vf_f, integer c);
+extern void do_vf_packet(PDF pdf, internal_font_number vf_f, int c);
extern int vf_packet_bytes(charinfo * co);
-charinfo *copy_charinfo(charinfo * ci);
+extern charinfo *copy_charinfo(charinfo * ci);
+
+/* this function is in vfovf.c for the moment */
+extern int make_vf_table(lua_State * L, const char *name, scaled s);
+
+/* some bits of the old interface, used by e.g. writet3.c */
+
+# define get_x_height(f) x_height(f)
+# define get_quad(f) quad(f)
+# define get_slant(f) slant(f)
+# define get_charwidth(f,c) (char_exists(f,c) ? char_width(f,c) : 0)
+# define get_charheight(f,c) (char_exists(f,c) ? char_height(f,c) : 0)
+# define get_chardepth(f,c) (char_exists(f,c) ? char_depth(f,c) : 0)
#endif /* TEXFONT_H */
diff --git a/Build/source/texk/web2c/luatexdir/font/texfont.c b/Build/source/texk/web2c/luatexdir/font/texfont.w
index 6e64053aa9a..19dcb0769af 100644
--- a/Build/source/texk/web2c/luatexdir/font/texfont.c
+++ b/Build/source/texk/web2c/luatexdir/font/texfont.w
@@ -1,60 +1,65 @@
-/* texfont.c Main font API implementation for the pascal parts
-
- Copyright 2006-2008 Taco Hoekwater <taco@luatex.org>
-
- This file is part of LuaTeX.
-
- LuaTeX 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 2 of the License, or (at your
- option) any later version.
-
- LuaTeX 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 Lesser General Public
- License for more details.
-
- You should have received a copy of the GNU General Public License along
- with LuaTeX; if not, see <http://www.gnu.org/licenses/>. */
-
-/* Main font API implementation for the pascal parts */
-
-/* stuff to watch out for:
- *
- * - Knuth had a 'null_character' that was used when a character could
- * not be found by the fetch() routine, to signal an error. This has
- * been deleted, but it may mean that the output of luatex is
- * incompatible with TeX after fetch() has detected an error condition.
- *
- * - Knuth also had a font_glue() optimization. I've removed that
- * because it was a bit of dirty programming and it also was
- * problematic if 0 != null.
- */
+% texfont.w
-#include "ptexlib.h"
-#include "luatex-api.h"
-#include "luatexfont.h"
+% Copyright 2006-2010 Taco Hoekwater <taco@@luatex.org>
-#define noDEBUG
+% This file is part of LuaTeX.
+
+% LuaTeX 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 2 of the License, or (at your
+% option) any later version.
+
+% LuaTeX 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 Lesser General Public
+% License for more details.
+
+% You should have received a copy of the GNU General Public License along
+% with LuaTeX; if not, see <http://www.gnu.org/licenses/>.
+
+
+@* Main font API implementation for the original pascal parts.
+
+Stuff to watch out for:
+\item{} Knuth had a |'null_character'| that was used when a character could
+not be found by the |fetch()| routine, to signal an error. This has
+been deleted, but it may mean that the output of luatex is
+incompatible with TeX after |fetch()| has detected an error condition.
+
+\item{} Knuth also had a |font_glue()| optimization. I've removed that
+because it was a bit of dirty programming and it also was
+problematic |if 0 != null|.
+
+@c
static const char _svn_version[] =
- "$Id: texfont.c 2448 2009-06-08 07:43:50Z taco $ $URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.40.6/source/texk/web2c/luatexdir/font/texfont.c $";
+ "$Id: texfont.w 3584 2010-04-02 17:45:55Z hhenkel $ "
+"$URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.60.0/source/texk/web2c/luatexdir/font/texfont.w $";
+
+#include "ptexlib.h"
+#include "lua/luatex-api.h"
+
+@ @c
+#define noDEBUG
#define proper_char_index(c) (c<=font_ec(f) && c>=font_bc(f))
-#define dxfree(a,b) { xfree(a); a = b ; }
-#define do_realloc(a,b,d) a = xrealloc(a,(b)*sizeof(d))
+#define do_realloc(a,b,d) a = xrealloc(a,(unsigned)((unsigned)(b)*sizeof(d)))
texfont **font_tables = NULL;
-static integer font_arr_max = 0;
-static integer font_id_maxval = 0;
+static int font_arr_max = 0;
+static int font_id_maxval = 0;
-static void grow_font_table(integer id)
+@ @c
+static void grow_font_table(int id)
{
int j;
if (id >= font_arr_max) {
- font_bytes += (font_arr_max - id + 8) * sizeof(texfont *);
- font_tables = xrealloc(font_tables, (id + 8) * sizeof(texfont *));
+ font_bytes +=
+ (int) (((id + 8 - font_arr_max) * (int) sizeof(texfont *)));
+ font_tables =
+ xrealloc(font_tables,
+ (unsigned) (((unsigned) id + 8) * sizeof(texfont *)));
j = 8;
while (j--) {
font_tables[id + j] = NULL;
@@ -63,7 +68,7 @@ static void grow_font_table(integer id)
}
}
-integer new_font_id(void)
+int new_font_id(void)
{
int i;
for (i = 0; i < font_arr_max; i++) {
@@ -78,29 +83,31 @@ integer new_font_id(void)
return i;
}
-integer max_font_id(void)
+int max_font_id(void)
{
return font_id_maxval;
}
-void set_max_font_id(integer i)
+void set_max_font_id(int i)
{
font_id_maxval = i;
}
-integer new_font(void)
+@ @c
+int new_font(void)
{
int k;
int id;
charinfo *ci;
id = new_font_id();
- font_bytes += sizeof(texfont);
+ font_bytes += (int) sizeof(texfont);
/* most stuff is zero */
font_tables[id] = xcalloc(1, sizeof(texfont));
font_tables[id]->_font_name = NULL;
font_tables[id]->_font_area = NULL;
font_tables[id]->_font_filename = NULL;
font_tables[id]->_font_fullname = NULL;
+ font_tables[id]->_font_psname = NULL;
font_tables[id]->_font_encodingname = NULL;
font_tables[id]->_font_cidregistry = NULL;
font_tables[id]->_font_cidordering = NULL;
@@ -112,6 +119,8 @@ integer new_font(void)
set_font_bc(id, 1); /* ec = 0 */
set_hyphen_char(id, '-');
set_skew_char(id, -1);
+ font_slant(id) = 0; /* vertical */
+ font_extend(id) = 1000; /* normal width */
/* allocate eight values including 0 */
set_font_params(id, 7);
@@ -130,9 +139,21 @@ integer new_font(void)
return id;
}
+@ @c
+void font_malloc_charinfo(internal_font_number f, int num)
+{
+ int glyph = font_tables[f]->charinfo_size;
+ font_bytes += (int) (num * (int) sizeof(charinfo));
+ do_realloc(font_tables[f]->charinfo, (unsigned) (glyph + num), charinfo);
+ memset(&(font_tables[f]->charinfo[glyph]), 0,
+ (size_t) (num * (int) sizeof(charinfo)));
+ font_tables[f]->charinfo_size += num;
+}
+
+@ @c
#define find_charinfo_id(f,c) get_sa_item(font_tables[f]->characters,c)
-charinfo *get_charinfo(internal_font_number f, integer c)
+charinfo *get_charinfo(internal_font_number f, int c)
{
sa_tree_item glyph;
charinfo *ci;
@@ -140,29 +161,26 @@ charinfo *get_charinfo(internal_font_number f, integer c)
glyph = get_sa_item(font_tables[f]->characters, c);
if (!glyph) {
- glyph = ++font_tables[f]->charinfo_count;
- if (glyph >= (unsigned) font_tables[f]->charinfo_size) {
- font_bytes += (16 * sizeof(charinfo));
- do_realloc(font_tables[f]->charinfo, (glyph + 16), charinfo);
- memset(&(font_tables[f]->charinfo[glyph]), 0,
- (16 * sizeof(charinfo)));
- font_tables[f]->charinfo_size += 16;
+ int tglyph = ++font_tables[f]->charinfo_count;
+ if (tglyph >= font_tables[f]->charinfo_size) {
+ font_malloc_charinfo(f, 256);
}
- font_tables[f]->charinfo[glyph].ef = 1000; /* init */
- set_sa_item(font_tables[f]->characters, c, glyph, 1); /* 1= global */
+ font_tables[f]->charinfo[tglyph].ef = 1000; /* init */
+ set_sa_item(font_tables[f]->characters, c, (sa_tree_item) tglyph, 1); /* 1= global */
+ glyph = (sa_tree_item) tglyph;
}
return &(font_tables[f]->charinfo[glyph]);
} else if (c == left_boundarychar) {
if (left_boundary(f) == NULL) {
ci = xcalloc(1, sizeof(charinfo));
- font_bytes += sizeof(charinfo);
+ font_bytes += (int) sizeof(charinfo);
set_left_boundary(f, ci);
}
return left_boundary(f);
} else if (c == right_boundarychar) {
if (right_boundary(f) == NULL) {
ci = xcalloc(1, sizeof(charinfo));
- font_bytes += sizeof(charinfo);
+ font_bytes += (int) sizeof(charinfo);
set_right_boundary(f, ci);
}
return right_boundary(f);
@@ -170,7 +188,8 @@ charinfo *get_charinfo(internal_font_number f, integer c)
return &(font_tables[f]->charinfo[0]);
}
-static void set_charinfo(internal_font_number f, integer c, charinfo * ci)
+@ @c
+void set_charinfo(internal_font_number f, int c, charinfo * ci)
{
sa_tree_item glyph;
if (proper_char_index(c)) {
@@ -187,14 +206,13 @@ static void set_charinfo(internal_font_number f, integer c, charinfo * ci)
}
}
-
-
+@ @c
charinfo *copy_charinfo(charinfo * ci)
{
- int x;
+ int x, k;
kerninfo *kern;
liginfo *lig;
- real_eight_bits *packet;
+ eight_bits *packet;
charinfo *co = NULL;
if (ci == NULL)
return NULL;
@@ -221,8 +239,8 @@ charinfo *copy_charinfo(charinfo * ci)
x++;
}
x++;
- co->kerns = xmalloc(x * sizeof(kerninfo));
- memcpy(co->kerns, ci->kerns, (x * sizeof(kerninfo)));
+ co->kerns = xmalloc((unsigned) (x * (int) sizeof(kerninfo)));
+ memcpy(co->kerns, ci->kerns, (size_t) (x * (int) sizeof(kerninfo)));
}
/* ligs */
if ((lig = get_charinfo_ligatures(ci)) != NULL) {
@@ -231,14 +249,15 @@ charinfo *copy_charinfo(charinfo * ci)
x++;
}
x++;
- co->ligatures = xmalloc(x * sizeof(liginfo));
- memcpy(co->ligatures, ci->ligatures, (x * sizeof(liginfo)));
+ co->ligatures = xmalloc((unsigned) (x * (int) sizeof(liginfo)));
+ memcpy(co->ligatures, ci->ligatures,
+ (size_t) (x * (int) sizeof(liginfo)));
}
/* packets */
if ((packet = get_charinfo_packets(ci)) != NULL) {
x = vf_packet_bytes(ci);
- co->packets = xmalloc(x);
- memcpy(co->packets, ci->packets, x);
+ co->packets = xmalloc((unsigned) x);
+ memcpy(co->packets, ci->packets, (size_t) x);
}
/* horizontal and vertical extenders */
@@ -251,11 +270,11 @@ charinfo *copy_charinfo(charinfo * ci)
set_charinfo_hor_variants(co,
copy_variants(get_charinfo_hor_variants(ci)));
}
- /* TODO: copy mathkerns */
x = ci->top_left_math_kerns;
co->top_left_math_kerns = x;
if (x > 0) {
- co->top_left_math_kern_array = xmalloc(2 * sizeof(scaled) * x);
+ co->top_left_math_kern_array =
+ xmalloc((unsigned) (2 * (int) sizeof(scaled) * x));
for (k = 0; k < co->top_left_math_kerns; k++) {
co->top_left_math_kern_array[(2 * k)] =
ci->top_left_math_kern_array[(2 * k)];
@@ -266,7 +285,8 @@ charinfo *copy_charinfo(charinfo * ci)
x = ci->top_right_math_kerns;
co->top_right_math_kerns = x;
if (x > 0) {
- co->top_right_math_kern_array = xmalloc(2 * sizeof(scaled) * x);
+ co->top_right_math_kern_array =
+ xmalloc((unsigned) (2 * (int) sizeof(scaled) * x));
for (k = 0; k < co->top_right_math_kerns; k++) {
co->top_right_math_kern_array[(2 * k)] =
ci->top_right_math_kern_array[(2 * k)];
@@ -277,7 +297,8 @@ charinfo *copy_charinfo(charinfo * ci)
x = ci->bottom_right_math_kerns;
co->bottom_right_math_kerns = x;
if (x > 0) {
- co->bottom_right_math_kern_array = xmalloc(2 * sizeof(scaled) * x);
+ co->bottom_right_math_kern_array =
+ xmalloc((unsigned) (2 * (int) sizeof(scaled) * x));
for (k = 0; k < co->bottom_right_math_kerns; k++) {
co->bottom_right_math_kern_array[(2 * k)] =
ci->bottom_right_math_kern_array[(2 * k)];
@@ -288,7 +309,8 @@ charinfo *copy_charinfo(charinfo * ci)
x = ci->bottom_left_math_kerns;
co->bottom_left_math_kerns = x;
if (x > 0) {
- co->bottom_left_math_kern_array = xmalloc(2 * sizeof(scaled) * x);
+ co->bottom_left_math_kern_array =
+ xmalloc((unsigned) (2 * (int) sizeof(scaled) * x));
for (k = 0; k < co->bottom_left_math_kerns; k++) {
co->bottom_left_math_kern_array[(2 * k)] =
ci->bottom_left_math_kern_array[(2 * k)];
@@ -301,12 +323,12 @@ charinfo *copy_charinfo(charinfo * ci)
return co;
}
-charinfo *char_info(internal_font_number f, integer c)
+charinfo *char_info(internal_font_number f, int c)
{
if (f > font_id_maxval)
return 0;
if (proper_char_index(c)) {
- register int glyph = find_charinfo_id(f, c);
+ register int glyph = (int) find_charinfo_id(f, c);
return &(font_tables[f]->charinfo[glyph]);
} else if (c == left_boundarychar && left_boundary(f) != NULL) {
return left_boundary(f);
@@ -316,23 +338,25 @@ charinfo *char_info(internal_font_number f, integer c)
return &(font_tables[f]->charinfo[0]);
}
-charinfo_short char_info_short(internal_font_number f, integer c)
+@ @c
+scaled_whd get_charinfo_whd(internal_font_number f, int c)
{
- charinfo_short s;
+ scaled_whd s;
charinfo *i;
i = char_info(f, c);
- s.ci_wd = i->width;
- s.ci_dp = i->depth;
- s.ci_ht = i->height;
+ s.wd = i->width;
+ s.dp = i->depth;
+ s.ht = i->height;
return s;
}
-integer char_exists(internal_font_number f, integer c)
+@ @c
+int char_exists(internal_font_number f, int c)
{
if (f > font_id_maxval)
return 0;
if (proper_char_index(c)) {
- return find_charinfo_id(f, c);
+ return (int) find_charinfo_id(f, c);
} else if ((c == left_boundarychar) && has_left_boundary(f)) {
return 1;
} else if ((c == right_boundarychar) && has_right_boundary(f)) {
@@ -341,10 +365,10 @@ integer char_exists(internal_font_number f, integer c)
return 0;
}
-#if 0 /* unused */
-static int lua_char_exists_callback(internal_font_number f, integer c)
+@ @c
+int lua_char_exists_callback(internal_font_number f, int c)
{
- integer callback_id;
+ int callback_id;
lua_State *L = Luas;
int ret = 0;
callback_id = callback_defined(char_exists_callback);
@@ -365,9 +389,9 @@ static int lua_char_exists_callback(internal_font_number f, integer c)
}
return ret;
}
-#endif
+@ @c
extinfo *new_variant(int glyph, int startconnect, int endconnect,
int advance, int repeater)
{
@@ -383,7 +407,8 @@ extinfo *new_variant(int glyph, int startconnect, int endconnect,
}
-static extinfo *copy_variant(extinfo * old)
+@ @c
+extinfo *copy_variant(extinfo * old)
{
extinfo *ext;
ext = xmalloc(sizeof(extinfo));
@@ -396,7 +421,8 @@ static extinfo *copy_variant(extinfo * old)
return ext;
}
-static void dump_variant(extinfo * ext)
+@ @c
+void dump_variant(extinfo * ext)
{
dump_int(ext->glyph);
dump_int(ext->start_overlap);
@@ -407,9 +433,10 @@ static void dump_variant(extinfo * ext)
}
-static extinfo *undump_variant(void)
+@ @c
+extinfo *undump_variant(void)
{
- integer x;
+ int x;
extinfo *ext;
undump_int(x);
if (x == 0)
@@ -428,6 +455,7 @@ static extinfo *undump_variant(void)
return ext;
}
+@ @c
void add_charinfo_vert_variant(charinfo * ci, extinfo * ext)
{
if (ci->vert_variants == NULL) {
@@ -441,6 +469,7 @@ void add_charinfo_vert_variant(charinfo * ci, extinfo * ext)
}
+@ @c
void add_charinfo_hor_variant(charinfo * ci, extinfo * ext)
{
if (ci->hor_variants == NULL) {
@@ -454,6 +483,7 @@ void add_charinfo_hor_variant(charinfo * ci, extinfo * ext)
}
+@ @c
extinfo *copy_variants(extinfo * o)
{
extinfo *c, *t = NULL, *h = NULL;
@@ -471,7 +501,8 @@ extinfo *copy_variants(extinfo * o)
}
-static void dump_charinfo_variants(extinfo * o)
+@ @c
+void dump_charinfo_variants(extinfo * o)
{
while (o != NULL) {
dump_variant(o);
@@ -481,7 +512,8 @@ static void dump_charinfo_variants(extinfo * o)
return;
}
-static extinfo *undump_charinfo_variants(void)
+@ @c
+extinfo *undump_charinfo_variants(void)
{
extinfo *c, *t, *h = NULL;
c = undump_variant();
@@ -497,6 +529,9 @@ static extinfo *undump_charinfo_variants(void)
}
+@ Note that mant more small things like this are implemented
+as macros in the header file.
+@c
void set_charinfo_width(charinfo * ci, scaled val)
{
ci->width = val;
@@ -529,7 +564,7 @@ void set_charinfo_bot_accent(charinfo * ci, scaled val)
void set_charinfo_tag(charinfo * ci, scaled val)
{
- ci->tag = val;
+ ci->tag = (char) val;
}
void set_charinfo_remainder(charinfo * ci, scaled val)
@@ -539,20 +574,24 @@ void set_charinfo_remainder(charinfo * ci, scaled val)
void set_charinfo_used(charinfo * ci, scaled val)
{
- ci->used = val;
+ ci->used = (char) val;
}
void set_charinfo_index(charinfo * ci, scaled val)
{
- ci->index = val;
+ ci->index = (unsigned short) val;
}
+
void set_charinfo_name(charinfo * ci, char *val)
{
- dxfree(ci->name, val);
+ xfree(ci->name);
+ ci->name = val;
}
+
void set_charinfo_tounicode(charinfo * ci, char *val)
{
- dxfree(ci->tounicode, val);
+ xfree(ci->tounicode);
+ ci->tounicode = val;
}
void set_charinfo_ligatures(charinfo * ci, liginfo * val)
@@ -565,7 +604,7 @@ void set_charinfo_kerns(charinfo * ci, kerninfo * val)
dxfree(ci->kerns, val);
}
-void set_charinfo_packets(charinfo * ci, real_eight_bits * val)
+void set_charinfo_packets(charinfo * ci, eight_bits * val)
{
dxfree(ci->packets, val);
}
@@ -585,6 +624,7 @@ void set_charinfo_rp(charinfo * ci, scaled val)
ci->rp = val;
}
+@ @c
void set_charinfo_vert_variants(charinfo * ci, extinfo * ext)
{
extinfo *c, *lst;
@@ -599,6 +639,7 @@ void set_charinfo_vert_variants(charinfo * ci, extinfo * ext)
ci->vert_variants = ext;
}
+@ @c
void set_charinfo_hor_variants(charinfo * ci, extinfo * ext)
{
extinfo *c, *lst;
@@ -614,10 +655,11 @@ void set_charinfo_hor_variants(charinfo * ci, extinfo * ext)
}
+@ @c
int get_charinfo_math_kerns(charinfo * ci, int id)
{
- int k = 0; /* all callers check for result>0 */
+ int k = 0; /* all callers check for |result>0| */
if (id == top_left_kern) {
k = ci->top_left_math_kerns;
} else if (id == bottom_left_kern) {
@@ -627,11 +669,12 @@ int get_charinfo_math_kerns(charinfo * ci, int id)
} else if (id == top_right_kern) {
k = ci->top_right_math_kerns;
} else {
- tconfusion("get_charinfo_math_kerns");
+ confusion("get_charinfo_math_kerns");
}
return k;
}
+@ @c
void add_charinfo_math_kern(charinfo * ci, int id, scaled ht, scaled krn)
{
int k;
@@ -663,14 +706,15 @@ void add_charinfo_math_kern(charinfo * ci, int id, scaled ht, scaled krn)
ci->top_right_math_kern_array[(2 * (k)) + 1] = krn;
ci->top_right_math_kerns++;
} else {
- tconfusion("add_charinfo_math_kern");
+ confusion("add_charinfo_math_kern");
}
}
+@ @c
static void dump_math_kerns(charinfo * ci)
{
- integer k, l;
+ int k, l;
l = ci->top_left_math_kerns;
dump_int(l);
for (k = 0; k < l; k++) {
@@ -697,14 +741,16 @@ static void dump_math_kerns(charinfo * ci)
}
}
+@ @c
static void undump_math_kerns(charinfo * ci)
{
int k;
- integer x;
+ int x;
undump_int(x);
- ci->top_left_math_kerns = (int) x;
+ ci->top_left_math_kerns = x;
if (x > 0)
- ci->top_left_math_kern_array = xmalloc(2 * sizeof(scaled) * x);
+ ci->top_left_math_kern_array =
+ xmalloc((unsigned) (2 * (int) sizeof(scaled) * x));
for (k = 0; k < ci->top_left_math_kerns; k++) {
undump_int(x);
ci->top_left_math_kern_array[(2 * k)] = (scaled) x;
@@ -712,9 +758,10 @@ static void undump_math_kerns(charinfo * ci)
ci->top_left_math_kern_array[(2 * k) + 1] = (scaled) x;
}
undump_int(x);
- ci->bottom_left_math_kerns = (int) x;
+ ci->bottom_left_math_kerns = x;
if (x > 0)
- ci->bottom_left_math_kern_array = xmalloc(2 * sizeof(scaled) * x);
+ ci->bottom_left_math_kern_array =
+ xmalloc((unsigned) (2 * (int) sizeof(scaled) * x));
for (k = 0; k < ci->bottom_left_math_kerns; k++) {
undump_int(x);
ci->bottom_left_math_kern_array[(2 * k)] = (scaled) x;
@@ -722,9 +769,10 @@ static void undump_math_kerns(charinfo * ci)
ci->bottom_left_math_kern_array[(2 * k) + 1] = (scaled) x;
}
undump_int(x);
- ci->bottom_right_math_kerns = (int) x;
+ ci->bottom_right_math_kerns = x;
if (x > 0)
- ci->bottom_right_math_kern_array = xmalloc(2 * sizeof(scaled) * x);
+ ci->bottom_right_math_kern_array =
+ xmalloc((unsigned) (2 * (int) sizeof(scaled) * x));
for (k = 0; k < ci->bottom_right_math_kerns; k++) {
undump_int(x);
ci->bottom_right_math_kern_array[(2 * k)] = (scaled) x;
@@ -732,9 +780,10 @@ static void undump_math_kerns(charinfo * ci)
ci->bottom_right_math_kern_array[(2 * k) + 1] = (scaled) x;
}
undump_int(x);
- ci->top_right_math_kerns = (int) x;
+ ci->top_right_math_kerns = x;
if (x > 0)
- ci->top_right_math_kern_array = xmalloc(2 * sizeof(scaled) * x);
+ ci->top_right_math_kern_array =
+ xmalloc((unsigned) (2 * (int) sizeof(scaled) * x));
for (k = 0; k < ci->top_right_math_kerns; k++) {
undump_int(x);
ci->top_right_math_kern_array[(2 * k)] = (scaled) x;
@@ -744,15 +793,16 @@ static void undump_math_kerns(charinfo * ci)
}
-/* In TeX, extensibles were fairly simple things.
+@ In TeX, extensibles were fairly simple things.
This function squeezes a TFM extensible into the vertical extender structures.
- |advance==0| is a special case for TFM fonts, because finding the proper
- advance width during tfm reading can be tricky
-*/
+ |advance==0| is a special case for TFM fonts, because finding the proper
+ advance width during tfm reading can be tricky
-/* a small complication arises if |rep| is the only non-zero: it needs to be
+
+ a small complication arises if |rep| is the only non-zero: it needs to be
doubled as a non-repeatable to avoid mayhem */
+@c
void set_charinfo_extensible(charinfo * ci, int top, int bot, int mid, int rep)
{
extinfo *ext;
@@ -786,6 +836,10 @@ void set_charinfo_extensible(charinfo * ci, int top, int bot, int mid, int rep)
}
}
+@ Note that many more simple things like this are implemented as macros
+in the header file.
+
+@c
scaled get_charinfo_width(charinfo * ci)
{
return ci->width;
@@ -821,7 +875,7 @@ char get_charinfo_tag(charinfo * ci)
return ci->tag;
}
-integer get_charinfo_remainder(charinfo * ci)
+int get_charinfo_remainder(charinfo * ci)
{
return ci->remainder;
}
@@ -831,7 +885,7 @@ char get_charinfo_used(charinfo * ci)
return ci->used;
}
-integer get_charinfo_index(charinfo * ci)
+int get_charinfo_index(charinfo * ci)
{
return ci->index;
}
@@ -856,22 +910,22 @@ kerninfo *get_charinfo_kerns(charinfo * ci)
return ci->kerns;
}
-real_eight_bits *get_charinfo_packets(charinfo * ci)
+eight_bits *get_charinfo_packets(charinfo * ci)
{
return ci->packets;
}
-integer get_charinfo_ef(charinfo * ci)
+int get_charinfo_ef(charinfo * ci)
{
return ci->ef;
}
-integer get_charinfo_rp(charinfo * ci)
+int get_charinfo_rp(charinfo * ci)
{
return ci->rp;
}
-integer get_charinfo_lp(charinfo * ci)
+int get_charinfo_lp(charinfo * ci)
{
return ci->lp;
}
@@ -893,105 +947,103 @@ extinfo *get_charinfo_hor_variants(charinfo * ci)
}
-scaled char_width(internal_font_number f, integer c)
+scaled char_width(internal_font_number f, int c)
{
charinfo *ci = char_info(f, c);
scaled w = get_charinfo_width(ci);
- /*fprintf(stdout,"width of char 0x%x in font %s: %i\n",c,font_name(f),w); */
return w;
}
-scaled char_depth(internal_font_number f, integer c)
+scaled char_depth(internal_font_number f, int c)
{
charinfo *ci = char_info(f, c);
scaled w = get_charinfo_depth(ci);
- /*fprintf(stdout,"depth of char 0x%x in font %s: %i\n",c,font_name(f),w); */
return w;
}
-scaled char_height(internal_font_number f, integer c)
+scaled char_height(internal_font_number f, int c)
{
charinfo *ci = char_info(f, c);
scaled w = get_charinfo_height(ci);
- /*fprintf(stdout,"height of char 0x%x in font %s: %i\n",c,font_name(f),w); */
return w;
}
-scaled char_italic(internal_font_number f, integer c)
+scaled char_italic(internal_font_number f, int c)
{
charinfo *ci = char_info(f, c);
return get_charinfo_italic(ci);
}
-scaled char_top_accent(internal_font_number f, integer c)
+scaled char_top_accent(internal_font_number f, int c)
{
charinfo *ci = char_info(f, c);
return get_charinfo_top_accent(ci);
}
-scaled char_bot_accent(internal_font_number f, integer c)
+scaled char_bot_accent(internal_font_number f, int c)
{
charinfo *ci = char_info(f, c);
return get_charinfo_bot_accent(ci);
}
-integer char_remainder(internal_font_number f, integer c)
+int char_remainder(internal_font_number f, int c)
{
charinfo *ci = char_info(f, c);
return get_charinfo_remainder(ci);
}
-char char_tag(internal_font_number f, integer c)
+char char_tag(internal_font_number f, int c)
{
charinfo *ci = char_info(f, c);
return get_charinfo_tag(ci);
}
-char char_used(internal_font_number f, integer c)
+char char_used(internal_font_number f, int c)
{
charinfo *ci = char_info(f, c);
return get_charinfo_used(ci);
}
-char *char_name(internal_font_number f, integer c)
+char *char_name(internal_font_number f, int c)
{
charinfo *ci = char_info(f, c);
return get_charinfo_name(ci);
}
-integer char_index(internal_font_number f, integer c)
+int char_index(internal_font_number f, int c)
{
charinfo *ci = char_info(f, c);
return get_charinfo_index(ci);
}
-liginfo *char_ligatures(internal_font_number f, integer c)
+liginfo *char_ligatures(internal_font_number f, int c)
{
charinfo *ci = char_info(f, c);
return get_charinfo_ligatures(ci);
}
-kerninfo *char_kerns(internal_font_number f, integer c)
+kerninfo *char_kerns(internal_font_number f, int c)
{
charinfo *ci = char_info(f, c);
return get_charinfo_kerns(ci);
}
-real_eight_bits *char_packets(internal_font_number f, integer c)
+eight_bits *char_packets(internal_font_number f, int c)
{
charinfo *ci = char_info(f, c);
return get_charinfo_packets(ci);
}
-
+@ @c
void set_font_params(internal_font_number f, int b)
{
int i;
i = font_params(f);
if (i != b) {
- font_bytes += (b - font_params(f) + 1) * sizeof(scaled);
- do_realloc(param_base(f), (b + 2), integer);
+ font_bytes +=
+ (int) ((b - (int) font_params(f) + 1) * (int) sizeof(scaled));
+ do_realloc(param_base(f), (b + 2), int);
font_params(f) = b;
if (b > i) {
while (i < b) {
@@ -1002,13 +1054,15 @@ void set_font_params(internal_font_number f, int b)
}
}
+@ @c
void set_font_math_params(internal_font_number f, int b)
{
int i;
i = font_math_params(f);
if (i != b) {
- font_bytes += (b - font_math_params(f) + 1) * sizeof(scaled);
- do_realloc(math_param_base(f), (b + 2), integer);
+ font_bytes +=
+ ((b - (int) font_math_params(f) + 1) * (int) sizeof(scaled));
+ do_realloc(math_param_base(f), (b + 2), int);
font_math_params(f) = b;
if (b > i) {
while (i < b) {
@@ -1020,14 +1074,24 @@ void set_font_math_params(internal_font_number f, int b)
}
-
-integer copy_font(integer f)
+@ @c
+int copy_font(int f)
{
- int i;
+ int i, ci_cnt, ci_size;
charinfo *ci;
- integer k = new_font();
- memcpy(font_tables[k], font_tables[f], sizeof(texfont));
+ int k = new_font();
+
+ {
+ ci = font_tables[k]->charinfo;
+ ci_cnt = font_tables[k]->charinfo_count;
+ ci_size = font_tables[k]->charinfo_size;
+ memcpy(font_tables[k], font_tables[f], sizeof(texfont));
+ font_tables[k]->charinfo = ci;
+ font_tables[k]->charinfo_count = ci_cnt;
+ font_tables[k]->charinfo_size = ci_size;
+ }
+ font_malloc_charinfo(k, font_tables[f]->charinfo_count);
set_font_cache_id(k, 0);
set_font_used(k, 0);
set_font_touched(k, 0);
@@ -1035,6 +1099,7 @@ integer copy_font(integer f)
font_tables[k]->_font_name = NULL;
font_tables[k]->_font_filename = NULL;
font_tables[k]->_font_fullname = NULL;
+ font_tables[k]->_font_psname = NULL;
font_tables[k]->_font_encodingname = NULL;
font_tables[k]->_font_area = NULL;
font_tables[k]->_font_cidregistry = NULL;
@@ -1047,6 +1112,8 @@ integer copy_font(integer f)
set_font_filename(k, xstrdup(font_filename(f)));
if (font_fullname(f) != NULL)
set_font_fullname(k, xstrdup(font_fullname(f)));
+ if (font_psname(f) != NULL)
+ set_font_psname(k, xstrdup(font_psname(f)));
if (font_encodingname(f) != NULL)
set_font_encodingname(k, xstrdup(font_encodingname(f)));
if (font_area(f) != NULL)
@@ -1056,23 +1123,20 @@ integer copy_font(integer f)
if (font_cidordering(f) != NULL)
set_font_cidordering(k, xstrdup(font_cidordering(f)));
- i = sizeof(*param_base(f)) * font_params(f);
+ i = (int) (sizeof(*param_base(f)) * (unsigned) font_params(f));
font_bytes += i;
- param_base(k) = xmalloc(i);
- memcpy(param_base(k), param_base(f), i);
+ param_base(k) = xmalloc((unsigned) i);
+ memcpy(param_base(k), param_base(f), (size_t) i);
if (font_math_params(f) > 0) {
- i = sizeof(*math_param_base(f)) * font_math_params(f);
+ i = (int) (sizeof(*math_param_base(f)) *
+ (unsigned) font_math_params(f));
font_bytes += i;
- math_param_base(k) = xmalloc(i);
- memcpy(math_param_base(k), math_param_base(f), i);
+ math_param_base(k) = xmalloc((unsigned) i);
+ memcpy(math_param_base(k), math_param_base(f), (size_t) i);
}
- i = sizeof(charinfo) * (font_tables[f]->charinfo_size + 1);
- font_bytes += i;
- font_tables[k]->charinfo = xmalloc(i);
- memset(font_tables[k]->charinfo, 0, i);
- for (i = 0; i < font_tables[k]->charinfo_size; i++) {
+ for (i = 0; i <= font_tables[f]->charinfo_count; i++) {
ci = copy_charinfo(&font_tables[f]->charinfo[i]);
font_tables[k]->charinfo[i] = *ci;
}
@@ -1089,7 +1153,8 @@ integer copy_font(integer f)
return k;
}
-void delete_font(integer f)
+@ @c
+void delete_font(int f)
{
int i;
charinfo *co;
@@ -1098,6 +1163,7 @@ void delete_font(integer f)
set_font_name(f, NULL);
set_font_filename(f, NULL);
set_font_fullname(f, NULL);
+ set_font_psname(f, NULL);
set_font_encodingname(f, NULL);
set_font_area(f, NULL);
set_font_cidregistry(f, NULL);
@@ -1106,7 +1172,7 @@ void delete_font(integer f)
set_right_boundary(f, NULL);
for (i = font_bc(f); i <= font_ec(f); i++) {
- if (char_exists(f, i)) {
+ if (quick_char_exists(f, i)) {
co = char_info(f, i);
set_charinfo_name(co, NULL);
set_charinfo_tounicode(co, NULL);
@@ -1134,6 +1200,7 @@ void delete_font(integer f)
}
}
+@ @c
void create_null_font(void)
{
int i = new_font();
@@ -1143,7 +1210,8 @@ void create_null_font(void)
set_font_touched(i, 1);
}
-boolean is_valid_font(integer id)
+@ @c
+boolean is_valid_font(int id)
{
int ret = 0;
if (id >= 0 && id <= font_id_maxval && font_tables[id] != NULL)
@@ -1151,22 +1219,8 @@ boolean is_valid_font(integer id)
return ret;
}
-/* return 1 == identical */
-boolean cmp_font_name(integer id, str_number t)
-{
- char *tid, *tt;
- if (!is_valid_font(id))
- return 0;
- tt = makecstring(t);
- tid = font_name(id);
- if (tt == NULL && tid == NULL)
- return 1;
- if (tt == NULL || tid == NULL || strcmp(tid, tt) != 0)
- return 0;
- return 1;
-}
-
-boolean cmp_font_area(integer id, str_number t)
+@ @c
+boolean cmp_font_area(int id, str_number t)
{
char *tt = NULL;
char *tid = font_area(id);
@@ -1181,68 +1235,23 @@ boolean cmp_font_area(integer id, str_number t)
return 1;
if (tt == NULL || strcmp(tid, tt) != 0)
return 0;
+ free(tt);
return 1;
}
-
-static boolean same_font_name(integer id, integer t)
-{
- int ret = 0;
- if (font_name(t) == NULL ||
- font_name(id) == NULL || strcmp(font_name(t), font_name(id)) != 0) {
- ;
- } else {
- ret = 1;
- }
- return ret;
-}
-
-boolean font_shareable(internal_font_number f, internal_font_number k)
-{
- int ret = 0;
- /* For some lua-loaded (for instance AFM) fonts, it is normal to have
- a zero cidregistry, and such fonts do not have a fontmap entry yet
- at this point, so the test shoulh use the other branch */
- if (font_cidregistry(f) == NULL && font_cidregistry(k) == NULL &&
- font_encodingbytes(f) != 2 && font_encodingbytes(k) != 2) {
- if (hasfmentry(k)
- && (font_map(k) == font_map(f))
- && (same_font_name(k, f)
- || (pdf_font_auto_expand(f)
- && (pdf_font_blink(f) != 0) /* 0 = nullfont */
- &&same_font_name(k, pdf_font_blink(f))))) {
- ret = 1;
- }
- } else {
- if ((font_filename(k) != NULL && font_filename(f) != NULL &&
- strcmp(font_filename(k), font_filename(f)) == 0 &&
- font_fullname(k) != NULL && font_fullname(f) != NULL &&
- strcmp(font_fullname(k), font_fullname(f)) == 0)
- || (pdf_font_auto_expand(f)
- && (pdf_font_blink(f) != 0) /* 0 = nullfont */
- &&same_font_name(k, pdf_font_blink(f)))) {
- ret = 1;
- }
-#ifdef DEBUG
- printf("font_shareable(%d:%s:%s,%d:%s:%s): => %d\n",
- f, font_filename(f), font_fullname(f),
- k, font_filename(k), font_fullname(k), ret);
-#endif
- }
- return ret;
-}
-
-integer test_no_ligatures(internal_font_number f)
+@ @c
+int test_no_ligatures(internal_font_number f)
{
- integer c;
+ int c;
for (c = font_bc(f); c <= font_ec(f); c++) {
- if (has_lig(f, c)) /* char_exists(f,c) */
+ if (has_lig(f, c)) /* |char_exists(f,c)| */
return 0;
}
return 1;
}
-integer get_tag_code(internal_font_number f, integer c)
+@ @c
+int get_tag_code(internal_font_number f, int c)
{
small_number i;
if (char_exists(f, c)) {
@@ -1259,30 +1268,32 @@ integer get_tag_code(internal_font_number f, integer c)
return -1;
}
-integer get_lp_code(internal_font_number f, integer c)
+@ @c
+int get_lp_code(internal_font_number f, int c)
{
charinfo *ci = char_info(f, c);
return get_charinfo_lp(ci);
}
-integer get_rp_code(internal_font_number f, integer c)
+int get_rp_code(internal_font_number f, int c)
{
charinfo *ci = char_info(f, c);
return get_charinfo_rp(ci);
}
-integer get_ef_code(internal_font_number f, integer c)
+int get_ef_code(internal_font_number f, int c)
{
charinfo *ci = char_info(f, c);
return get_charinfo_ef(ci);
}
-void set_tag_code(internal_font_number f, integer c, integer i)
+@ @c
+void set_tag_code(internal_font_number f, int c, int i)
{
- integer fixedi;
+ int fixedi;
charinfo *co;
if (char_exists(f, c)) {
- /* abs(fix_int(i-7,0)) */
+ /* |abs(fix_int(i-7,0))| */
fixedi = -(i < -7 ? -7 : (i > 0 ? 0 : i));
co = char_info(f, c);
if (fixedi >= 4) {
@@ -1305,7 +1316,8 @@ void set_tag_code(internal_font_number f, integer c, integer i)
}
-void set_lp_code(internal_font_number f, integer c, integer i)
+@ @c
+void set_lp_code(internal_font_number f, int c, int i)
{
charinfo *co;
if (char_exists(f, c)) {
@@ -1314,7 +1326,7 @@ void set_lp_code(internal_font_number f, integer c, integer i)
}
}
-void set_rp_code(internal_font_number f, integer c, integer i)
+void set_rp_code(internal_font_number f, int c, int i)
{
charinfo *co;
if (char_exists(f, c)) {
@@ -1323,7 +1335,7 @@ void set_rp_code(internal_font_number f, integer c, integer i)
}
}
-void set_ef_code(internal_font_number f, integer c, integer i)
+void set_ef_code(internal_font_number f, int c, int i)
{
charinfo *co;
if (char_exists(f, c)) {
@@ -1332,9 +1344,10 @@ void set_ef_code(internal_font_number f, integer c, integer i)
}
}
+@ @c
void set_no_ligatures(internal_font_number f)
{
- integer c;
+ int c;
charinfo *co;
if (font_tables[f]->ligatures_disabled)
@@ -1351,8 +1364,10 @@ void set_no_ligatures(internal_font_number f)
font_tables[f]->ligatures_disabled = 1;
}
-liginfo get_ligature(internal_font_number f, integer lc, integer rc)
+@ @c
+liginfo get_ligature(internal_font_number f, int lc, int rc)
{
+ int k;
liginfo t, u;
charinfo *co;
t.lig = 0;
@@ -1379,9 +1394,10 @@ liginfo get_ligature(internal_font_number f, integer lc, integer rc)
}
-scaled raw_get_kern(internal_font_number f, integer lc, integer rc)
+@ @c
+scaled raw_get_kern(internal_font_number f, int lc, int rc)
{
- integer k;
+ int k;
kerninfo u;
charinfo *co;
if (lc == non_boundarychar || rc == non_boundarychar)
@@ -1404,7 +1420,8 @@ scaled raw_get_kern(internal_font_number f, integer lc, integer rc)
}
-scaled get_kern(internal_font_number f, integer lc, integer rc)
+@ @c
+scaled get_kern(internal_font_number f, int lc, int rc)
{
if (lc == non_boundarychar || rc == non_boundarychar || (!has_kern(f, lc)))
return 0;
@@ -1412,20 +1429,21 @@ scaled get_kern(internal_font_number f, integer lc, integer rc)
}
-/* dumping and undumping fonts */
+@ dumping and undumping fonts
-#define dump_string(a) \
- if (a!=NULL) { \
- x = strlen(a)+1; \
- dump_int(x); dump_things(*a, x); \
- } else { \
- x = 0; dump_int(x); \
- }
+@c
+#define dump_string(a) \
+ if (a!=NULL) { \
+ x = (int)(strlen(a)+1); \
+ dump_int(x); dump_things(*a, x); \
+ } else { \
+ x = 0; dump_int(x); \
+ }
-static void dump_charinfo(int f, int c)
+void dump_charinfo(int f, int c)
{
charinfo *co;
- integer x;
+ int x;
liginfo *lig;
kerninfo *kern;
dump_int(c);
@@ -1485,20 +1503,27 @@ static void dump_charinfo(int f, int c)
dump_math_kerns(co);
}
-static void dump_font_entry(texfont * f)
+void dump_font_entry(texfont * f)
{
+ int x;
dump_int(f->_font_size);
dump_int(f->_font_dsize);
dump_int(f->_font_cidversion);
dump_int(f->_font_cidsupplement);
dump_int(f->_font_ec);
- dump_int(f->_font_checksum);
+ x = (int) f->_font_checksum;
+ dump_int(x);
dump_int(f->_font_used);
dump_int(f->_font_touched);
dump_int(f->_font_cache_id);
dump_int(f->_font_encodingbytes);
dump_int(f->_font_slant);
dump_int(f->_font_extend);
+ dump_int(f->_font_expand_ratio);
+ dump_int(f->_font_shrink);
+ dump_int(f->_font_stretch);
+ dump_int(f->_font_step);
+ dump_int(f->_font_auto_expand);
dump_int(f->_font_tounicode);
dump_int(f->_font_type);
dump_int(f->_font_format);
@@ -1511,20 +1536,14 @@ static void dump_font_entry(texfont * f)
dump_int(f->_font_math_params);
dump_int(f->ligatures_disabled);
dump_int(f->_pdf_font_num);
- dump_int(f->_pdf_font_size);
dump_int(f->_pdf_font_blink);
dump_int(f->_pdf_font_elink);
- dump_int(f->_pdf_font_expand_ratio);
- dump_int(f->_pdf_font_shrink);
- dump_int(f->_pdf_font_stretch);
- dump_int(f->_pdf_font_step);
- dump_int(f->_pdf_font_auto_expand);
dump_int(f->_pdf_font_attr);
}
void dump_font(int f)
{
- integer i, x;
+ int i, x;
set_font_used(f, 0);
font_tables[f]->charinfo_cache = NULL;
@@ -1533,6 +1552,7 @@ void dump_font(int f)
dump_string(font_area(f));
dump_string(font_filename(f));
dump_string(font_fullname(f));
+ dump_string(font_psname(f));
dump_string(font_encodingname(f));
dump_string(font_cidregistry(f));
dump_string(font_cidordering(f));
@@ -1556,20 +1576,21 @@ void dump_font(int f)
}
for (i = font_bc(f); i <= font_ec(f); i++) {
- if (char_exists(f, i)) {
+ if (quick_char_exists(f, i)) {
dump_charinfo(f, i);
}
}
}
-static int undump_charinfo(int f)
+@ @c
+int undump_charinfo(int f)
{
charinfo *co;
- integer x, i;
+ int x, i;
char *s = NULL;
liginfo *lig = NULL;
kerninfo *kern = NULL;
- real_eight_bits *packet = NULL;
+ eight_bits *packet = NULL;
undump_int(i);
co = get_charinfo(f, i);
@@ -1604,7 +1625,7 @@ static int undump_charinfo(int f)
undump_int(x);
if (x > 0) {
font_bytes += x;
- s = xmalloc(x);
+ s = xmalloc((unsigned) x);
undump_things(*s, x);
}
set_charinfo_name(co, s);
@@ -1612,23 +1633,23 @@ static int undump_charinfo(int f)
undump_int(x);
if (x > 0) {
font_bytes += x;
- s = xmalloc(x);
+ s = xmalloc((unsigned) x);
undump_things(*s, x);
}
set_charinfo_tounicode(co, s);
/* ligatures */
undump_int(x);
if (x > 0) {
- font_bytes += x * sizeof(liginfo);
- lig = xmalloc(x * sizeof(liginfo));
+ font_bytes += (int) ((unsigned) x * sizeof(liginfo));
+ lig = xmalloc((unsigned) ((unsigned) x * sizeof(liginfo)));
undump_things(*lig, x);
}
set_charinfo_ligatures(co, lig);
/* kerns */
undump_int(x);
if (x > 0) {
- font_bytes += x * sizeof(kerninfo);
- kern = xmalloc(x * sizeof(kerninfo));
+ font_bytes += (int) ((unsigned) x * sizeof(kerninfo));
+ kern = xmalloc((unsigned) ((unsigned) x * sizeof(kerninfo)));
undump_things(*kern, x);
}
set_charinfo_kerns(co, kern);
@@ -1637,7 +1658,7 @@ static int undump_charinfo(int f)
undump_int(x);
if (x > 0) {
font_bytes += x;
- packet = xmalloc(x);
+ packet = xmalloc((unsigned) x);
undump_things(*packet, x);
}
set_charinfo_packets(co, packet);
@@ -1650,30 +1671,35 @@ static int undump_charinfo(int f)
return i;
}
-#define undump_font_string(a) undump_int (x); \
- if (x>0) { \
- font_bytes += x; \
- s = xmalloc(x); undump_things(*s,x); \
+#define undump_font_string(a) undump_int (x); \
+ if (x>0) { \
+ font_bytes += x; \
+ s = xmalloc((unsigned)x); undump_things(*s,x); \
a(f,s); }
-static void undump_font_entry(texfont * f)
+void undump_font_entry(texfont * f)
{
- integer x = 0;
- /* *INDENT-OFF* */
+ int x = 0;
+ /* *INDENT-OFF* */
undump_int(x); f->_font_size = x;
undump_int(x); f->_font_dsize = x;
undump_int(x); f->_font_cidversion = x;
undump_int(x); f->_font_cidsupplement = x;
undump_int(x); f->_font_ec = x;
- undump_int(x); f->_font_checksum = x;
- undump_int(x); f->_font_used = x;
- undump_int(x); f->_font_touched = x;
+ undump_int(x); f->_font_checksum = (unsigned)x;
+ undump_int(x); f->_font_used = (char)x;
+ undump_int(x); f->_font_touched = (char)x;
undump_int(x); f->_font_cache_id = x;
- undump_int(x); f->_font_encodingbytes = x;
+ undump_int(x); f->_font_encodingbytes = (char)x;
undump_int(x); f->_font_slant = x;
undump_int(x); f->_font_extend = x;
- undump_int(x); f->_font_tounicode = x;
+ undump_int(x); f->_font_expand_ratio = x;
+ undump_int(x); f->_font_shrink = x;
+ undump_int(x); f->_font_stretch = x;
+ undump_int(x); f->_font_step = x;
+ undump_int(x); f->_font_auto_expand = x;
+ undump_int(x); f->_font_tounicode = (char)x;
undump_int(x); f->_font_type = x;
undump_int(x); f->_font_format = x;
undump_int(x); f->_font_embedding = x;
@@ -1685,30 +1711,24 @@ static void undump_font_entry(texfont * f)
undump_int(x); f->_font_math_params = x;
undump_int(x); f->ligatures_disabled = x;
undump_int(x); f->_pdf_font_num = x;
- undump_int(x); f->_pdf_font_size = x;
undump_int(x); f->_pdf_font_blink = x;
undump_int(x); f->_pdf_font_elink = x;
- undump_int(x); f->_pdf_font_expand_ratio = x;
- undump_int(x); f->_pdf_font_shrink = x;
- undump_int(x); f->_pdf_font_stretch = x;
- undump_int(x); f->_pdf_font_step = x;
- undump_int(x); f->_pdf_font_auto_expand = x;
undump_int(x); f->_pdf_font_attr = x;
- /* *INDENT-ON* */
+ /* *INDENT-ON* */
}
void undump_font(int f)
{
- integer x, i;
+ int x, i;
texfont *tt;
charinfo *ci;
char *s;
grow_font_table(f);
tt = xmalloc(sizeof(texfont));
memset(tt, 0, sizeof(texfont));
- font_bytes += sizeof(texfont);
+ font_bytes += (int) sizeof(texfont);
undump_font_entry(tt);
font_tables[f] = tt;
@@ -1716,19 +1736,21 @@ void undump_font(int f)
undump_font_string(set_font_area);
undump_font_string(set_font_filename);
undump_font_string(set_font_fullname);
+ undump_font_string(set_font_psname);
undump_font_string(set_font_encodingname);
undump_font_string(set_font_cidregistry);
undump_font_string(set_font_cidordering);
- i = sizeof(*param_base(f)) * (font_params(f) + 1);
+ i = (int) (sizeof(*param_base(f)) * ((unsigned) font_params(f) + 1));
font_bytes += i;
- param_base(f) = xmalloc(i);
+ param_base(f) = xmalloc((unsigned) i);
undump_things(*param_base(f), (font_params(f) + 1));
if (font_math_params(f) > 0) {
- i = sizeof(*math_param_base(f)) * (font_math_params(f) + 1);
+ i = (int) (sizeof(*math_param_base(f)) *
+ ((unsigned) font_math_params(f) + 1));
font_bytes += i;
- math_param_base(f) = xmalloc(i);
+ math_param_base(f) = xmalloc((unsigned) i);
undump_things(*math_param_base(f), (font_math_params(f) + 1));
}
diff --git a/Build/source/texk/web2c/luatexdir/font/tfmofm.c b/Build/source/texk/web2c/luatexdir/font/tfmofm.w
index 6c99a9dd498..842af38b405 100644
--- a/Build/source/texk/web2c/luatexdir/font/tfmofm.c
+++ b/Build/source/texk/web2c/luatexdir/font/tfmofm.w
@@ -1,31 +1,31 @@
-/* tfmofm.c
-
- Copyright 2006-2009 Taco Hoekwater <taco@luatex.org>
+% tfmofm.w
+%
+% Copyright 2006-2010 Taco Hoekwater <taco@@luatex.org>
- This file is part of LuaTeX.
+% This file is part of LuaTeX.
- LuaTeX 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 2 of the License, or (at your
- option) any later version.
+% LuaTeX 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 2 of the License, or (at your
+% option) any later version.
- LuaTeX 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 Lesser General Public
- License for more details.
+% LuaTeX 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 Lesser General Public
+% License for more details.
- You should have received a copy of the GNU General Public License along
- with LuaTeX; if not, see <http://www.gnu.org/licenses/>. */
+% You should have received a copy of the GNU General Public License along
+% with LuaTeX; if not, see <http://www.gnu.org/licenses/>.
+@ @c
#include "ptexlib.h"
-#include "luatex-api.h"
-#include "luatexfont.h"
static const char _svn_version[] =
- "$Id: tfmofm.c 2448 2009-06-08 07:43:50Z taco $ $URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.40.6/source/texk/web2c/luatexdir/font/tfmofm.c $";
-
-/* Here are some macros that help process ligatures and kerns */
+ "$Id: tfmofm.w 3584 2010-04-02 17:45:55Z hhenkel $ "
+"$URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.60.0/source/texk/web2c/luatexdir/font/tfmofm.w $";
+@ Here are some macros that help process ligatures and kerns
+@c
#define lig_kern_start(f,c) char_remainder(f,c)
#define stop_flag 128 /* value indicating `\.{STOP}' in a lig/kern program */
#define kern_flag 128 /* op code for a kern step */
@@ -36,8 +36,8 @@ static const char _svn_version[] =
#define rem_byte(z) lig_kerns[z].b3
#define lig_kern_restart(c) (256*op_byte(c)+rem_byte(c))
-/*
+@
The information in a \.{TFM} file appears in a sequence of 8-bit bytes.
Since the number of bytes is always a multiple of 4, we could
also regard the file as a sequence of 32-bit words, but \TeX\ uses the
@@ -54,9 +54,9 @@ is not aware of this.
The documentation below describes \.{TFM} files, with slight additions
to show where \.{OFM} files differ.
- */
-/*
-@ The first 24 bytes (6 words) of a \.{TFM} file contain twelve 16-bit
+
+@
+The first 24 bytes (6 words) of a \.{TFM} file contain twelve 16-bit
integers that give the lengths of the various subsequent portions
of the file. These twelve integers are, in order:
$$\vbox{\halign{\hfil#&$\null=\null$#\hfil\cr
@@ -94,11 +94,12 @@ $$\hbox{|lf=13+lh+2*(ec-bc+1)+nw+nh+nd+ni+nl+nk+ne+np|.}$$
Note that an \.{OFM} font may contain as many as 65536 characters
(if |bc=0| and |ec=65535|), and as few as 0 characters (if |bc=ec+1|).
-@ The rest of the \.{TFM} file may be regarded as a sequence of ten data
+The rest of the \.{TFM} file may be regarded as a sequence of ten data
arrays having the informal specification
$$\def\arr$[#1]#2${\&{array} $[#1]$ \&{of} #2}
-\vbox{\halign{\hfil\\{#}&$\,:\,$\arr#\hfil\cr
-header&|[0..lh-1]@t\\{stuff}@>|\cr
+\def\doarr\PB#1{\arr#1}
+\vbox{\halign{\hfil\\{#}&$\,:\,$\doarr#\hfil\cr
+header&|[0..lh-1]stuff|\cr
char\_info&|[bc..ec]char_info_word|\cr
width&|[0..nw-1]fix_word|\cr
height&|[0..nh-1]fix_word|\cr
@@ -107,7 +108,7 @@ italic&|[0..ni-1]fix_word|\cr
lig\_kern&|[0..nl-1]lig_kern_command|\cr
kern&|[0..nk-1]fix_word|\cr
exten&|[0..ne-1]extensible_recipe|\cr
-param&|[1..np]fix_word|\cr}}$$
+param&\omit |[1..np]fix_word|\cr}}$$
The most important data type used here is a |@!fix_word|, which is
a 32-bit representation of a binary fraction. A |fix_word| is a signed
quantity, with the two's complement of the entire word used to represent
@@ -116,7 +117,7 @@ binary point; thus, the largest |fix_word| value is $2048-2^{-20}$, and
the smallest is $-2048$. We will see below, however, that all but two of
the |fix_word| values must lie between $-16$ and $+16$.
-@ The first data array is a block of header information, which contains
+The first data array is a block of header information, which contains
general facts about the font. The header must contain at least two words,
|header[0]| and |header[1]|, whose meaning is explained below.
Additional header information of use to other software routines might
@@ -160,7 +161,7 @@ value; thus, |header[1]| and |param[1]| are the only |fix_word|
entries in the whole \.{TFM} file whose first byte might be something
besides 0 or 255.
-@ Next comes the |char_info| array, which contains one |@!char_info_word|
+Next comes the |char_info| array, which contains one |@!char_info_word|
per character. Each word in this part of a \.{TFM} file contains six fields
packed into four bytes as follows.
@@ -203,9 +204,8 @@ Incidentally, the relation $\\{width}[0]=\\{height}[0]=\\{depth}[0]=
value of zero. The |width_index| should never be zero unless the
character does not exist in the font, since a character is valid if and
only if it lies between |bc| and |ec| and has a nonzero |width_index|.
-*/
-/*
+
@ \TeX\ checks the information of a \.{TFM} file for validity as the
file is being read in, so that no further checks will be needed when
typesetting is going on. The somewhat tedious subroutine that does this
@@ -222,22 +222,17 @@ It returns the value of the internal font number that was just loaded.
If an error is detected, an error message is issued and no font
information is stored; |null_font| is returned in this case.
-@d bad_tfm=11 {label for |read_font_info|}
-@d abort==goto bad_tfm {do this when the \.{TFM} data is wrong}
-
-*/
-
-/*
+@
The |tag| field in a |char_info_word| has four values that explain how to
interpret the |remainder| field.
-\yskip\hangg|tag=0| (|no_tag|) means that |remainder| is unused.\par
-\hangg|tag=1| (|lig_tag|) means that this character has a ligature/kerning
+\yskip\hang|tag=0| (|no_tag|) means that |remainder| is unused.\par
+\hang|tag=1| (|lig_tag|) means that this character has a ligature/kerning
program starting at position |remainder| in the |lig_kern| array.\par
-\hangg|tag=2| (|list_tag|) means that this character is part of a chain of
+\hang|tag=2| (|list_tag|) means that this character is part of a chain of
characters of ascending sizes, and not the largest in the chain. The
|remainder| field gives the character code of the next larger character.\par
-\hangg|tag=3| (|ext_tag|) means that this character code represents an
+\hang|tag=3| (|ext_tag|) means that this character code represents an
extensible character, i.e., a character that is built up of smaller pieces
so that it can be made arbitrarily large. The pieces are specified in
|@!exten[remainder]|.\par
@@ -246,9 +241,9 @@ Characters with |tag=2| and |tag=3| are treated as characters with |tag=0|
unless they are used in special circumstances in math formulas. For example,
the \.{\\sum} operation looks for a |list_tag|, and the \.{\\left}
operation looks for both |list_tag| and |ext_tag|.
-*/
-/* The |lig_kern| array contains instructions in a simple programming language
+
+@ The |lig_kern| array contains instructions in a simple programming language
that explains what to do for special letter pairs. Each word in this array,
in a \.{TFM} file, is a |@!lig_kern_command| of four bytes.
@@ -299,10 +294,9 @@ $$\hbox{|256*op_byte+remainder<nl|.}$$
If such an instruction is encountered during
normal program execution, it denotes an unconditional halt; no ligature
or kerning command is performed.
-*/
-/*
- Extensible characters are specified by an |@!extensible_recipe|, which
+
+@ Extensible characters are specified by an |@!extensible_recipe|, which
consists of four bytes in a \.{TFM} file,
called |@!top|, |@!mid|, |@!bot|, and |@!rep| (in this order).
In an \.{OFM} file, each field takes two bytes, for eight in total.
@@ -318,9 +312,9 @@ in the latter case we can have $TR^kB$ for both even and odd values of~|k|.
The width of the extensible character is the width of $R$; and the
height-plus-depth is the sum of the individual height-plus-depths of the
components used, since the pieces are butted together in a vertical list.
-*/
-/*
+
+@
The final portion of a \.{TFM} file is the |param| array, which is another
sequence of |fix_word| values.
@@ -350,17 +344,16 @@ ends of sentences.
If fewer than seven parameters are present, \TeX\ sets the missing parameters
to zero. Fonts used for math symbols are required to have
additional parameter information, which is explained later.
-*/
-/*
+
+@
There are programs called \.{TFtoPL} and \.{PLtoTF} that convert
between the \.{TFM} format and a symbolic property-list format
that can be easily edited. These programs contain extensive
diagnostic information, so \TeX\ does not have to bother giving
precise details about why it rejects a particular \.{TFM} file.
-*/
-
+@c
#define tfm_abort { font_tables[f]->_font_name = NULL; \
font_tables[f]->_font_area = NULL; \
xfree(tfm_buffer); xfree(kerns); \
@@ -374,32 +367,31 @@ additional parameter information, which is explained later.
xfree(italics); xfree(extens); xfree(lig_kerns); \
xfree(xligs); xfree(xkerns); return 1; }
-
-static int open_tfm_file(const char *nom, unsigned char **tfm_buf, integer * tfm_siz)
+@ @c
+static int open_tfm_file(const char *nom, unsigned char **tfm_buf, int *tfm_siz)
{
boolean res; /* was the callback successful? */
boolean opened; /* was |tfm_file| successfully opened? */
- integer callback_id;
+ int callback_id;
FILE *tfm_file;
- /* packfilename(nom,aire,getnullstr()); */
- if (nameoffile != NULL)
- xfree(nameoffile);
- nameoffile = malloc(strlen(nom) + 2);
- strcpy(stringcast(nameoffile + 1), nom);
- namelength = strlen(nom);
+ char *fname = luatex_find_file(nom, find_font_file_callback);
+ if (!fname)
+ return -1;
callback_id = callback_defined(read_font_file_callback);
if (callback_id > 0) {
- res = run_callback(callback_id, "S->bSd", stringcast(nameoffile + 1),
- &opened, tfm_buf, tfm_siz);
+ res =
+ run_callback(callback_id, "S->bSd", fname, &opened, tfm_buf,
+ tfm_siz);
if (res && opened && (*tfm_siz > 0)) {
return 1;
}
if (!opened)
return -1;
} else {
- if (ofm_open_in(tfm_file)) {
+ if (luatex_open_input
+ (&(tfm_file), fname, kpse_ofm_format, FOPEN_RBIN_MODE, true)) {
res = read_tfm_file(tfm_file, tfm_buf, tfm_siz);
- b_close(tfm_file);
+ close_file(tfm_file);
if (res) {
return 1;
}
@@ -411,7 +403,7 @@ static int open_tfm_file(const char *nom, unsigned char **tfm_buf, integer * tfm
}
-/*
+@
Note: A malformed \.{TFM} file might be shorter than it claims to be;
thus |eof(tfm_file)| might be true when |read_font_info| refers to
|tfm_file^| or when it says |get(tfm_file)|. If such circumstances
@@ -419,7 +411,7 @@ static int open_tfm_file(const char *nom, unsigned char **tfm_buf, integer * tfm
for example by defining |fget| to be `\ignorespaces|begin get(tfm_file);|
|if eof(tfm_file) then abort; end|\unskip'.
@^system dependencies@>
-*/
+@c
#define fget tfm_byte++
#define fbyte tfm_buffer[tfm_byte]
@@ -456,7 +448,7 @@ static int open_tfm_file(const char *nom, unsigned char **tfm_buf, integer * tfm
ci._depth_index=b%256; \
fget; read_sixteen_unsigned(c); \
ci._italic_index=c>>8; \
- ci._tag=c%4; \
+ ci._tag=(unsigned char)(c%4); \
fget; read_sixteen_unsigned(d); \
ci._remainder=d; \
} else { \
@@ -467,28 +459,28 @@ static int open_tfm_file(const char *nom, unsigned char **tfm_buf, integer * tfm
ci._depth_index=b%16; \
c=tfm_buffer[++tfm_byte]; \
ci._italic_index=c>>2; \
- ci._tag=c%4; \
+ ci._tag=(unsigned char)(c%4); \
d=tfm_buffer[++tfm_byte]; \
ci._remainder=d; \
} }
#define read_four_quarters(q) \
- { if (font_level!=-1) { \
- fget; read_sixteen_unsigned(a); q.b0=a; \
- fget; read_sixteen_unsigned(b); q.b1=b; \
- fget; read_sixteen_unsigned(c); q.b2=c; \
- fget; read_sixteen_unsigned(d); q.b3=d; \
- } else { \
- a=tfm_buffer[++tfm_byte]; q.b0=a; \
- b=tfm_buffer[++tfm_byte]; q.b1=b; \
- c=tfm_buffer[++tfm_byte]; q.b2=c; \
- d=tfm_buffer[++tfm_byte]; q.b3=d; \
+ { if (font_level!=-1) { \
+ fget; read_sixteen_unsigned(a); q.b0=(quarterword)a; \
+ fget; read_sixteen_unsigned(b); q.b1=(quarterword)b; \
+ fget; read_sixteen_unsigned(c); q.b2=(quarterword)c; \
+ fget; read_sixteen_unsigned(d); q.b3=(quarterword)d; \
+ } else { \
+ a=tfm_buffer[++tfm_byte]; q.b0=(quarterword)a; \
+ b=tfm_buffer[++tfm_byte]; q.b1=(quarterword)b; \
+ c=tfm_buffer[++tfm_byte]; q.b2=(quarterword)c; \
+ d=tfm_buffer[++tfm_byte]; q.b3=(quarterword)d; \
} }
#define check_byte_range(z) { if ((z<bc)||(z>ec)) tfm_abort ; }
-/* A |fix_word| whose four bytes are $(a,b,c,d)$ from left to right represents
+@ A |fix_word| whose four bytes are $(a,b,c,d)$ from left to right represents
the number
$$x=\left\{\vcenter{\halign{$#$,\hfil\qquad&if $#$\hfil\cr
b\cdot2^{-4}+c\cdot2^{-12}+d\cdot2^{-20}&a=0;\cr
@@ -505,8 +497,8 @@ static int open_tfm_file(const char *nom, unsigned char **tfm_buf, integer * tfm
if $a=0$, or the same quantity minus $\alpha=2^{4+e}z^\prime$ if $a=255$.
This calculation must be done exactly, in order to guarantee portability
of \TeX\ between computers.
-*/
+@c
#define store_scaled(zz) \
{ fget; a=fbyte; fget; b=fbyte; \
fget; c=fbyte; fget; d=fbyte; \
@@ -518,9 +510,9 @@ scaled store_scaled_f(scaled sq, scaled z_in)
{
eight_bits a, b, c, d;
scaled sw;
- static integer alpha, beta; /* beta:1..16 */
+ static int alpha, beta; /* beta:1..16 */
static scaled z, z_prev = 0;
- /* @<Replace |z| by $|z|^\prime$ and compute $\alpha,\beta$@>; */
+ /* Replace |z| by $|z|^\prime$ and compute $\alpha,\beta$ */
if (z_in != z_prev || z_prev == 0) {
z = z_prev = z_in;
alpha = 16;
@@ -532,22 +524,22 @@ scaled store_scaled_f(scaled sq, scaled z_in)
alpha *= z;
};
if (sq >= 0) {
- d = sq % 256; /* any "mod 256" not really needed, would typecast alone be safe? */
+ d = (eight_bits) (sq % 256);
sq = sq / 256;
- c = sq % 256;
+ c = (eight_bits) (sq % 256);
sq = sq / 256;
- b = sq % 256;
+ b = (eight_bits) (sq % 256);
sq = sq / 256;
- a = sq % 256;
+ a = (eight_bits) (sq % 256);
} else {
sq = (sq + 1073741824) + 1073741824; /* braces for optimizing compiler */
- d = sq % 256;
+ d = (eight_bits) (sq % 256);
sq = sq / 256;
- c = sq % 256;
+ c = (eight_bits) (sq % 256);
sq = sq / 256;
- b = sq % 256;
+ b = (eight_bits) (sq % 256);
sq = sq / 256;
- a = (sq + 128) % 256;
+ a = (eight_bits) ((sq + 128) % 256);
}
sw = (((((d * z) >> 8) + (c * z)) >> 8) + (b * z)) / beta;
if (a == 0)
@@ -555,56 +547,59 @@ scaled store_scaled_f(scaled sq, scaled z_in)
else if (a == 255)
return (sw - alpha);
else
- pdf_error(maketexstring("vf"), maketexstring("vf scaling"));
+ pdf_error("vf", "vf scaling");
return sw; /* not reached, just to make the compiler happy */
}
+@ @c
#define check_existence(z) \
{ check_byte_range(z); \
if (!char_exists(f,z)) tfm_abort; \
}
typedef struct tfmcharacterinfo {
- integer _kern_index;
- integer _lig_index;
- integer _width_index;
- integer _height_index;
- integer _depth_index;
- integer _italic_index;
- integer _remainder;
+ int _kern_index;
+ int _lig_index;
+ int _width_index;
+ int _height_index;
+ int _depth_index;
+ int _italic_index;
+ int _remainder;
unsigned char _tag;
} tfmcharacterinfo;
-int read_tfm_info(internalfontnumber f, const char *cnom, scaled s)
+@ @c
+int read_tfm_info(internal_font_number f, const char *cnom, scaled s)
{
- integer k; /* index into |font_info| */
+ int k; /* index into |font_info| */
halfword lf, lh, bc, ec, nw, nh, nd, ni, nl, nk, ne, np, slh; /* sizes of subfiles */
scaled *widths, *heights, *depths, *italics, *kerns;
halfword font_dir;
- integer a, b, c, d; /* byte variables */
- integer i; /* counter */
- integer font_level, header_length;
- integer nco, ncw, npc, nlw, neew;
+ int a, b, c, d; /* byte variables */
+ int i; /* counter */
+ int font_level, header_length;
+ int nco, ncw, npc, nlw, neew;
tfmcharacterinfo ci;
charinfo *co;
four_quarters qw;
four_quarters *lig_kerns, *extens;
scaled sw; /* accumulators */
- integer bch_label; /* left boundary start location, or infinity */
- int bchar; /* :0..too_big_char; *//* right boundary character, or |too_big_char| */
- integer first_two;
+ int bch_label; /* left boundary start location, or infinity */
+ int bchar; /* |:0..too_big_char;| *//* right boundary character, or |too_big_char| */
+ int first_two;
scaled z; /* the design size or the ``at'' size */
- integer alpha;
+ int alpha;
char beta; /* :1..16 */
- integer *xligs, *xkerns; /* aux. for ligkern processing */
+ int *xligs, *xkerns; /* aux. for ligkern processing */
liginfo *cligs;
kerninfo *ckerns;
int fligs, fkerns;
char *tmpnam;
- integer tfm_byte = 0; /* index into |tfm_buffer| */
- integer saved_tfm_byte = 0; /* saved index into |tfm_buffer| */
+ int tfm_byte = 0; /* index into |tfm_buffer| */
+ int saved_tfm_byte = 0; /* saved index into |tfm_buffer| */
unsigned char *tfm_buffer = NULL; /* byte buffer for tfm files */
- integer tfm_size = 0; /* total size of the tfm file */
+ int tfm_size = 0; /* total size of the tfm file */
+ int tmp;
widths = NULL;
heights = NULL;
@@ -634,7 +629,7 @@ int read_tfm_info(internalfontnumber f, const char *cnom, scaled s)
set_font_name(f, tmpnam);
set_font_area(f, NULL);
- /* @<Read the {\.{TFM}} size fields@>; */
+ /* Read the {\.{TFM}} size fields */
nco = 0;
ncw = 0;
npc = 0;
@@ -716,28 +711,29 @@ int read_tfm_info(internalfontnumber f, const char *cnom, scaled s)
if (lf * 4 > tfm_size)
tfm_abort;
- /* @<Use size fields to allocate font information@>; */
+ /* Use size fields to allocate font information */
set_font_natural_dir(f, font_dir);
set_font_bc(f, bc);
set_font_ec(f, ec);
/* read the arrays first */
- widths = xmalloc(nw * sizeof(scaled));
- heights = xmalloc(nh * sizeof(scaled));
- depths = xmalloc(nd * sizeof(scaled));
- italics = xmalloc(ni * sizeof(scaled));
- extens = xmalloc(ne * sizeof(four_quarters));
- lig_kerns = xmalloc(nl * sizeof(four_quarters));
- kerns = xmalloc(nk * sizeof(scaled));
+ widths = xmalloc((unsigned) ((unsigned) nw * sizeof(scaled)));
+ heights = xmalloc((unsigned) ((unsigned) nh * sizeof(scaled)));
+ depths = xmalloc((unsigned) ((unsigned) nd * sizeof(scaled)));
+ italics = xmalloc((unsigned) ((unsigned) ni * sizeof(scaled)));
+ extens = xmalloc((unsigned) ((unsigned) ne * sizeof(four_quarters)));
+ lig_kerns = xmalloc((unsigned) ((unsigned) nl * sizeof(four_quarters)));
+ kerns = xmalloc((unsigned) ((unsigned) nk * sizeof(scaled)));
- /* @<Read the {\.{TFM}} header@>; */
+ /* Read the {\.{TFM}} header */
/* Only the first two words of the header are needed by \TeX82. */
slh = lh;
if (lh < 2)
tfm_abort;
- store_four_bytes(font_checksum(f));
+ store_four_bytes(tmp);
+ font_checksum(f) = (unsigned) tmp;
fget;
read_sixteen(z); /* this rejects a negative design size */
fget;
@@ -768,17 +764,17 @@ int read_tfm_info(internalfontnumber f, const char *cnom, scaled s)
saved_tfm_byte = tfm_byte;
tfm_byte = (header_length + slh + ncw) * 4 - 1;
- /* @<Replace |z| by $|z|^\prime$ and compute $\alpha,\beta$@>; */
+ /* Replace |z| by $|z|^\prime$ and compute $\alpha,\beta$ */
alpha = 16;
while (z >= 040000000) {
z = z >> 1;
alpha = alpha + alpha;
};
- beta = 256 / alpha;
+ beta = (char) (256 / alpha);
alpha = alpha * z;
- /* @<Read box dimensions@>; */
+ /* Read box dimensions */
for (k = 0; k < nw; k++) {
store_scaled(sw);
@@ -806,7 +802,7 @@ int read_tfm_info(internalfontnumber f, const char *cnom, scaled s)
tfm_abort; /* \\{italic}[0] must be zero */
- /* @<Read ligature/kern program@>; */
+ /* Read ligature/kern program */
bch_label = nl; /* infinity */
bchar = 65536;
@@ -820,9 +816,13 @@ int read_tfm_info(internalfontnumber f, const char *cnom, scaled s)
if (a == 255 && k == 0)
bchar = b;
} else {
- /* if (b!=bchar) check_existence(b); */
+#if 0
+ if (b!=bchar) check_existence(b);
+#endif
if (c < 128) {
- /* check_existence(d); *//* check ligature */
+#if 0
+ check_existence(d); /* check ligature */
+#endif
} else if (256 * (c - 128) + d >= nk) {
tfm_abort; /* check kern */
}
@@ -840,13 +840,13 @@ int read_tfm_info(internalfontnumber f, const char *cnom, scaled s)
kerns[k] = sw;
}
- /* @<Read extensible character recipes@>; */
+ /* Read extensible character recipes */
for (k = 0; k < ne; k++) {
read_four_quarters(qw);
extens[k] = qw;
}
- /* @<Read font parameters@>; */
+ /* Read font parameters */
if (np > 7) {
set_font_params(f, np);
@@ -876,10 +876,10 @@ int read_tfm_info(internalfontnumber f, const char *cnom, scaled s)
fkerns = 0;
if (bch_label != nl) {
k = bch_label;
- /*
+#if 0
if (skip_byte(k) > stop_flag)
k = lig_kern_restart(k);
- */
+#endif
while (1) {
if (skip_byte(k) <= stop_flag) {
if (op_byte(k) >= kern_flag) { /* kern */
@@ -899,16 +899,16 @@ int read_tfm_info(internalfontnumber f, const char *cnom, scaled s)
}
if (fkerns > 0 || fligs > 0) {
if (fligs > 0)
- cligs = xcalloc((fligs + 1), sizeof(liginfo));
+ cligs = xcalloc((unsigned) (fligs + 1), sizeof(liginfo));
if (fkerns > 0)
- ckerns = xcalloc((fkerns + 1), sizeof(kerninfo));
+ ckerns = xcalloc((unsigned) (fkerns + 1), sizeof(kerninfo));
fligs = 0;
fkerns = 0;
k = bch_label;
- /*
- if (skip_byte(k) > stop_flag)
+#if 0
+ if (skip_byte(k) > stop_flag)
k = lig_kern_restart(k);
- */
+#endif
while (1) {
if (skip_byte(k) <= stop_flag) {
if (op_byte(k) >= kern_flag) { /* kern */
@@ -917,7 +917,7 @@ int read_tfm_info(internalfontnumber f, const char *cnom, scaled s)
rem_byte(k)]);
fkerns++;
} else { /* lig */
- set_ligature_item(cligs[fligs], (op_byte(k) * 2 + 1),
+ set_ligature_item(cligs[fligs], (char) (op_byte(k) * 2 + 1),
next_char(k), rem_byte(k));
fligs++;
}
@@ -946,7 +946,7 @@ int read_tfm_info(internalfontnumber f, const char *cnom, scaled s)
}
}
- /* @<Read character data@>; */
+ /* Read character data */
for (k = bc; k <= ec; k++) {
store_char_info(k);
if (ci._width_index == 0)
@@ -971,7 +971,7 @@ int read_tfm_info(internalfontnumber f, const char *cnom, scaled s)
the largest character code in the cycle.
*/
check_byte_range(d);
- while (d < k) { /* current_character == k */
+ while (d < k) { /* |current_character == k| */
if (char_tag(f, d) != list_tag)
goto NOT_FOUND; /* not a cycle */
d = char_remainder(f, d); /* next character on the list */
@@ -1002,8 +1002,8 @@ int read_tfm_info(internalfontnumber f, const char *cnom, scaled s)
/* first pass: count ligs and kerns */
- xligs = xcalloc((ec + 1), sizeof(integer));
- xkerns = xcalloc((ec + 1), sizeof(integer));
+ xligs = xcalloc((unsigned) (ec + 1), sizeof(int));
+ xkerns = xcalloc((unsigned) (ec + 1), sizeof(int));
for (i = bc; i <= ec; i++) {
if (char_tag(f, i) == lig_tag) {
@@ -1046,9 +1046,9 @@ int read_tfm_info(internalfontnumber f, const char *cnom, scaled s)
k = lig_kern_restart(k);
/* now k is the start index */
if (xligs[i] > 0)
- cligs = xcalloc((xligs[i] + 1), sizeof(liginfo));
+ cligs = xcalloc((unsigned) (xligs[i] + 1), sizeof(liginfo));
if (xkerns[i] > 0)
- ckerns = xcalloc((xkerns[i] + 1), sizeof(kerninfo));
+ ckerns = xcalloc((unsigned) (xkerns[i] + 1), sizeof(kerninfo));
while (1) {
if (skip_byte(k) <= stop_flag) {
if (op_byte(k) >= kern_flag) { /* kern */
@@ -1065,11 +1065,12 @@ int read_tfm_info(internalfontnumber f, const char *cnom, scaled s)
} else { /* lig */
if (next_char(k) == bchar) {
set_ligature_item(cligs[fligs],
- (op_byte(k) * 2 + 1),
+ (char) (op_byte(k) * 2 + 1),
right_boundarychar, rem_byte(k));
fligs++;
}
- set_ligature_item(cligs[fligs], (op_byte(k) * 2 + 1),
+ set_ligature_item(cligs[fligs],
+ (char) (op_byte(k) * 2 + 1),
next_char(k), rem_byte(k));
fligs++;
}
@@ -1100,7 +1101,7 @@ int read_tfm_info(internalfontnumber f, const char *cnom, scaled s)
}
- /* @<Make final adjustments and |goto done|@> */
+ /* Make final adjustments and |goto done| */
/* Now to wrap it up, we have checked all the necessary things about the \.{TFM}
file, and all we need to do is put the finishing touches on the data for
diff --git a/Build/source/texk/web2c/luatexdir/font/tounicode.c b/Build/source/texk/web2c/luatexdir/font/tounicode.w
index a4029f5220d..9ca84210606 100644
--- a/Build/source/texk/web2c/luatexdir/font/tounicode.c
+++ b/Build/source/texk/web2c/luatexdir/font/tounicode.w
@@ -1,31 +1,35 @@
-/* tounicode.c
- Copyright 2006 Han The Thanh, <thanh@pdftex.org>
- Copyright 2006-2008 Taco Hoekwater <taco@luatex.org>
+% tounicode.w
- This file is part of LuaTeX.
+% Copyright 2006 Han The Thanh, <thanh@@pdftex.org>
+% Copyright 2006-2010 Taco Hoekwater <taco@@luatex.org>
- LuaTeX 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 2 of the License, or (at your
- option) any later version.
+% This file is part of LuaTeX.
- LuaTeX 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 Lesser General Public
- License for more details.
+% LuaTeX 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 2 of the License, or (at your
+% option) any later version.
- You should have received a copy of the GNU General Public License along
- with LuaTeX; if not, see <http://www.gnu.org/licenses/>. */
+% LuaTeX 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 Lesser General Public
+% License for more details.
+% You should have received a copy of the GNU General Public License along
+% with LuaTeX; if not, see <http://www.gnu.org/licenses/>.
+
+@ @c
#include "ptexlib.h"
static const char _svn_version[] =
- "$Id: tounicode.c 2448 2009-06-08 07:43:50Z taco $ $URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.40.6/source/texk/web2c/luatexdir/font/tounicode.c $";
+ "$Id: tounicode.w 3584 2010-04-02 17:45:55Z hhenkel $ "
+"$URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.60.0/source/texk/web2c/luatexdir/font/tounicode.w $";
+@ @c
#define isXdigit(c) (isdigit(c) || ('A' <= (c) && (c) <= 'F'))
#define UNI_UNDEF -1
-#define UNI_STRING -2 /* string allocated by def_tounicode() */
-#define UNI_EXTRA_STRING -3 /* string allocated by set_glyph_unicode() */
+#define UNI_STRING -2 /* string allocated by |def_tounicode()| */
+#define UNI_EXTRA_STRING -3 /* string allocated by |set_glyph_unicode()| */
static struct avl_table *glyph_unicode_tree = NULL;
@@ -63,9 +67,10 @@ void glyph_unicode_free(void)
avl_destroy(glyph_unicode_tree, destroy_glyph_unicode_entry);
}
+@ @c
void def_tounicode(str_number glyph, str_number unistr)
{
- char buf[SMALL_BUF_SIZE], *p;
+ char buf[SMALL_BUF_SIZE], *p, *ph;
char buf2[SMALL_BUF_SIZE], *q;
int valid_unistr; /* 0: invalid; 1: unicode value; 2: string */
int i, l;
@@ -74,11 +79,13 @@ void def_tounicode(str_number glyph, str_number unistr)
p = makecstring(glyph);
assert(strlen(p) < SMALL_BUF_SIZE);
- strcpy(buf, p); /* copy the result to buf before next call of makecstring() */
+ strcpy(buf, p);
+ free(p);
p = makecstring(unistr);
+ ph = p;
while (*p == ' ')
p++; /* ignore leading spaces */
- l = strlen(p);
+ l = (int) strlen(p);
while (l > 0 && p[l - 1] == ' ')
l--; /* ignore traling spaces */
valid_unistr = 1; /* a unicode value is the most common case */
@@ -125,12 +132,14 @@ void def_tounicode(str_number glyph, str_number unistr)
}
aa = avl_probe(glyph_unicode_tree, gu);
assert(aa != NULL);
+ free(ph);
}
+@ @c
static long check_unicode_value(char *s, boolean multiple_value)
{
- int l = strlen(s);
+ int l = (int) strlen(s);
int i;
long code;
@@ -165,6 +174,7 @@ static long check_unicode_value(char *s, boolean multiple_value)
return code;
}
+@ @c
static char *utf16be_str(long code)
{
static char buf[SMALL_BUF_SIZE];
@@ -177,17 +187,18 @@ static char *utf16be_str(long code)
sprintf(buf, "%04lX", code);
else {
v = code - 0x10000;
- vh = v / 0x400 + 0xD800;
- vl = v % 0x400 + 0xDC00;
+ vh = (unsigned) (v / 0x400 + 0xD800);
+ vl = (unsigned) (v % 0x400 + 0xDC00);
sprintf(buf, "%04X%04X", vh, vl);
}
return buf;
}
-/* this function set proper values to *gp based on s; in case it returns
- * gp->code == UNI_EXTRA_STRING then the caller is responsible for freeing
- * gp->unicode_seq too */
+@ This function set proper values to |*gp| based on |s|; in case it returns
+ |gp->code == UNI_EXTRA_STRING| then the caller is responsible for freeing
+ |gp->unicode_seq| too.
+@c
static void set_glyph_unicode(char *s, glyph_unicode_entry * gp)
{
char buf[SMALL_BUF_SIZE], buf2[SMALL_BUF_SIZE], *p;
@@ -203,14 +214,14 @@ static void set_glyph_unicode(char *s, glyph_unicode_entry * gp)
p = strchr(s, '.');
if (p != NULL) {
*buf = 0;
- strncat(buf, s, p - s);
+ strncat(buf, s, (size_t) (p - s));
s = buf;
}
if (strlen(s) == 0)
return;
- /* check for case of multiple components separated by '_' */
+ /* check for case of multiple components separated by |'_'| */
p = strchr(s, '_');
if (p != NULL) {
assert(strlen(s) < sizeof(buf));
@@ -293,12 +304,13 @@ static void set_glyph_unicode(char *s, glyph_unicode_entry * gp)
}
}
+@ @c
static void set_cid_glyph_unicode(long index, glyph_unicode_entry * gp,
internal_font_number f)
{
char *s;
if (font_tounicode(f) &&
- (s = get_charinfo_tounicode(char_info(f, index))) != NULL) {
+ (s = get_charinfo_tounicode(char_info(f, (int) index))) != NULL) {
gp->code = UNI_EXTRA_STRING;
gp->unicode_seq = xstrdup(s);
} else {
@@ -307,19 +319,22 @@ static void set_cid_glyph_unicode(long index, glyph_unicode_entry * gp,
}
-integer write_tounicode(char **glyph_names, char *name)
+@ @c
+int write_tounicode(PDF pdf, char **glyph_names, char *name)
{
char buf[SMALL_BUF_SIZE], *p;
static char builtin_suffix[] = "-builtin";
short range_size[257];
glyph_unicode_entry gtab[257];
- integer objnum;
+ int objnum;
int i, j;
int bfchar_count, bfrange_count, subrange_count;
assert(strlen(name) + strlen(builtin_suffix) < SMALL_BUF_SIZE);
if (glyph_unicode_tree == NULL) {
- /*pdftex_warn("no GlyphToUnicode entry has been inserted yet!"); */
- fixed_gen_tounicode = 0;
+#ifdef DEBUG
+ pdftex_warn("no GlyphToUnicode entry has been inserted yet!");
+#endif
+ pdf->gen_tounicode = 0;
return 0;
}
strcpy(buf, name);
@@ -328,27 +343,27 @@ integer write_tounicode(char **glyph_names, char *name)
else
strcat(buf, builtin_suffix); /* ".enc" not present, this is a builtin
encoding so the name is eg "cmr10-builtin" */
- objnum = pdf_new_objnum();
- pdf_begin_dict(objnum, 0);
- pdf_begin_stream();
- pdf_printf("%%!PS-Adobe-3.0 Resource-CMap\n"
- "%%%%DocumentNeededResources: ProcSet (CIDInit)\n"
- "%%%%IncludeResource: ProcSet (CIDInit)\n"
- "%%%%BeginResource: CMap (TeX-%s-0)\n"
- "%%%%Title: (TeX-%s-0 TeX %s 0)\n"
- "%%%%Version: 1.000\n"
- "%%%%EndComments\n"
- "/CIDInit /ProcSet findresource begin\n"
- "12 dict begin\n"
- "begincmap\n"
- "/CIDSystemInfo\n"
- "<< /Registry (TeX)\n"
- "/Ordering (%s)\n"
- "/Supplement 0\n"
- ">> def\n"
- "/CMapName /TeX-%s-0 def\n"
- "/CMapType 2 def\n"
- "1 begincodespacerange\n"
+ objnum = pdf_new_objnum(pdf);
+ pdf_begin_dict(pdf, objnum, 0);
+ pdf_begin_stream(pdf);
+ pdf_printf(pdf, "%%!PS-Adobe-3.0 Resource-CMap\n"@/
+ "%%%%DocumentNeededResources: ProcSet (CIDInit)\n"@/
+ "%%%%IncludeResource: ProcSet (CIDInit)\n"@/
+ "%%%%BeginResource: CMap (TeX-%s-0)\n"@/
+ "%%%%Title: (TeX-%s-0 TeX %s 0)\n"@/
+ "%%%%Version: 1.000\n"@/
+ "%%%%EndComments\n"@/
+ "/CIDInit /ProcSet findresource begin\n"@/
+ "12 dict begin\n"@/
+ "begincmap\n"@/
+ "/CIDSystemInfo\n"@/
+ "<< /Registry (TeX)\n"@/
+ "/Ordering (%s)\n"@/
+ "/Supplement 0\n"@/
+ ">> def\n"@/
+ "/CMapName /TeX-%s-0 def\n"@/
+ "/CMapType 2 def\n"@/
+ "1 begincodespacerange\n"@/
"<00> <FF>\n" "endcodespacerange\n", buf, buf, buf, buf, buf);
/* set gtab */
@@ -358,7 +373,7 @@ integer write_tounicode(char **glyph_names, char *name)
}
gtab[256].code = UNI_UNDEF;
- /* set range_size */
+ /* set |range_size| */
for (i = 0; i < 256;) {
if (gtab[i].code == UNI_STRING || gtab[i].code == UNI_EXTRA_STRING) {
range_size[i] = 1; /* single entry */
@@ -373,11 +388,11 @@ integer write_tounicode(char **glyph_names, char *name)
i++;
/* at this point i is the last entry of the subrange */
i++; /* move i to the next entry */
- range_size[j] = i - j;
+ range_size[j] = (short) (i - j);
}
}
- /* calculate bfrange_count and bfchar_count */
+ /* calculate |bfrange_count| and |bfchar_count| */
bfrange_count = 0;
bfchar_count = 0;
for (i = 0; i < 256;) {
@@ -399,16 +414,16 @@ integer write_tounicode(char **glyph_names, char *name)
else
subrange_count = bfrange_count;
bfrange_count -= subrange_count;
- pdf_printf("%i beginbfrange\n", subrange_count);
+ pdf_printf(pdf, "%i beginbfrange\n", subrange_count);
for (j = 0; j < subrange_count; j++) {
while (range_size[i] <= 1 && i < 256)
i++;
assert(i < 256);
- pdf_printf("<%02X> <%02X> <%s>\n", i, i + range_size[i] - 1,
+ pdf_printf(pdf, "<%02X> <%02X> <%s>\n", i, i + range_size[i] - 1,
utf16be_str(gtab[i].code));
i += range_size[i];
}
- pdf_printf("endbfrange\n");
+ pdf_printf(pdf, "endbfrange\n");
if (bfrange_count > 0)
goto write_bfrange;
@@ -420,79 +435,80 @@ integer write_tounicode(char **glyph_names, char *name)
else
subrange_count = bfchar_count;
bfchar_count -= subrange_count;
- pdf_printf("%i beginbfchar\n", subrange_count);
+ pdf_printf(pdf, "%i beginbfchar\n", subrange_count);
for (j = 0; j < subrange_count; j++) {
while (i < 256) {
if (range_size[i] > 1)
i += range_size[i];
else if (range_size[i] == 0)
i++;
- else /* range_size[i] == 1 */
+ else /* |range_size[i] == 1| */
break;
}
assert(i < 256 && gtab[i].code != UNI_UNDEF);
if (gtab[i].code == UNI_STRING || gtab[i].code == UNI_EXTRA_STRING) {
assert(gtab[i].unicode_seq != NULL);
- pdf_printf("<%02X> <%s>\n", i, gtab[i].unicode_seq);
+ pdf_printf(pdf, "<%02X> <%s>\n", i, gtab[i].unicode_seq);
} else
- pdf_printf("<%02X> <%s>\n", i, utf16be_str(gtab[i].code));
+ pdf_printf(pdf, "<%02X> <%s>\n", i, utf16be_str(gtab[i].code));
i++;
}
- pdf_printf("endbfchar\n");
+ pdf_printf(pdf, "endbfchar\n");
if (bfchar_count > 0)
goto write_bfchar;
- /* free strings allocated by set_glyph_unicode() */
+ /* free strings allocated by |set_glyph_unicode()| */
for (i = 0; i < 256; ++i) {
if (gtab[i].code == UNI_EXTRA_STRING)
xfree(gtab[i].unicode_seq);
}
- pdf_printf("endcmap\n"
+ pdf_printf(pdf, "endcmap\n"
"CMapName currentdict /CMap defineresource pop\n"
"end\n" "end\n" "%%%%EndResource\n" "%%%%EOF\n");
- pdf_end_stream();
+ pdf_end_stream(pdf);
return objnum;
}
-integer write_cid_tounicode(fo_entry * fo, internalfontnumber f)
+@ @c
+int write_cid_tounicode(PDF pdf, fo_entry * fo, internal_font_number f)
{
int range_size[65537];
glyph_unicode_entry gtab[65537];
- integer objnum;
+ int objnum;
int i, j, k;
int bfchar_count, bfrange_count, subrange_count;
char *buf;
assert(fo->fd->fontname);
- buf = xmalloc(strlen(fo->fd->fontname) + 8);
+ buf = xmalloc((unsigned) (strlen(fo->fd->fontname) + 8));
sprintf(buf, "%s-%s",
(fo->fd->subset_tag != NULL ? fo->fd->subset_tag : "UCS"),
fo->fd->fontname);
- objnum = pdf_new_objnum();
- pdf_begin_dict(objnum, 0);
- pdf_begin_stream();
- pdf_printf("%%!PS-Adobe-3.0 Resource-CMap\n"
- "%%%%DocumentNeededResources: ProcSet (CIDInit)\n"
- "%%%%IncludeResource: ProcSet (CIDInit)\n"
- "%%%%BeginResource: CMap (TeX-%s-0)\n"
- "%%%%Title: (TeX-%s-0 TeX %s 0)\n"
- "%%%%Version: 1.000\n"
- "%%%%EndComments\n"
- "/CIDInit /ProcSet findresource begin\n"
- "12 dict begin\n"
- "begincmap\n"
- "/CIDSystemInfo\n"
- "<< /Registry (TeX)\n"
- "/Ordering (%s)\n"
- "/Supplement 0\n"
- ">> def\n"
- "/CMapName /TeX-Identity-%s def\n"
- "/CMapType 2 def\n"
- "1 begincodespacerange\n"
- "<0000> <FFFF>\n"
+ objnum = pdf_new_objnum(pdf);
+ pdf_begin_dict(pdf, objnum, 0);
+ pdf_begin_stream(pdf);
+ pdf_printf(pdf, "%%!PS-Adobe-3.0 Resource-CMap\n"@/
+ "%%%%DocumentNeededResources: ProcSet (CIDInit)\n"@/
+ "%%%%IncludeResource: ProcSet (CIDInit)\n"@/
+ "%%%%BeginResource: CMap (TeX-%s-0)\n"@/
+ "%%%%Title: (TeX-%s-0 TeX %s 0)\n"@/
+ "%%%%Version: 1.000\n"@/
+ "%%%%EndComments\n"@/
+ "/CIDInit /ProcSet findresource begin\n"@/
+ "12 dict begin\n"@/
+ "begincmap\n"@/
+ "/CIDSystemInfo\n"@/
+ "<< /Registry (TeX)\n"@/
+ "/Ordering (%s)\n"@/
+ "/Supplement 0\n"@/
+ ">> def\n"@/
+ "/CMapName /TeX-Identity-%s def\n"@/
+ "/CMapType 2 def\n"@/
+ "1 begincodespacerange\n"@/
+ "<0000> <FFFF>\n"@/
"endcodespacerange\n", buf, buf, buf, buf, buf);
xfree(buf);
/* set up gtab */
@@ -502,7 +518,7 @@ integer write_cid_tounicode(fo_entry * fo, internalfontnumber f)
for (k = 1; k <= max_font_id(); k++) {
if (k == f || -f == pdf_font_num(k)) {
for (i = font_bc(k); i <= font_ec(k); i++) {
- if (char_exists(k, i) && char_used(k, i)) {
+ if (quick_char_exists(k, i) && char_used(k, i)) {
j = char_index(k, i);
if (gtab[j].code == UNI_UNDEF) {
set_cid_glyph_unicode(i, &gtab[j], f);
@@ -512,7 +528,7 @@ integer write_cid_tounicode(fo_entry * fo, internalfontnumber f)
}
}
- /* set range_size */
+ /* set |range_size| */
for (i = 0; i < 65536;) {
if (gtab[i].code == UNI_STRING || gtab[i].code == UNI_EXTRA_STRING) {
range_size[i] = 1; /* single entry */
@@ -520,7 +536,7 @@ integer write_cid_tounicode(fo_entry * fo, internalfontnumber f)
} else if (gtab[i].code == UNI_UNDEF) {
range_size[i] = 0; /* no entry */
i++;
- } else { /* gtab[i].code >= 0 */
+ } else { /* |gtab[i].code >= 0| */
j = i;
while (i < 65536 && gtab[i + 1].code >= 0 &&
gtab[i].code + 1 == gtab[i + 1].code)
@@ -531,7 +547,7 @@ integer write_cid_tounicode(fo_entry * fo, internalfontnumber f)
}
}
- /* calculate bfrange_count and bfchar_count */
+ /* calculate |bfrange_count| and |bfchar_count| */
bfrange_count = 0;
bfchar_count = 0;
for (i = 0; i < 65536;) {
@@ -553,16 +569,16 @@ integer write_cid_tounicode(fo_entry * fo, internalfontnumber f)
else
subrange_count = bfrange_count;
bfrange_count -= subrange_count;
- pdf_printf("%i beginbfrange\n", subrange_count);
+ pdf_printf(pdf, "%i beginbfrange\n", subrange_count);
for (j = 0; j < subrange_count; j++) {
while (range_size[i] <= 1 && i < 65536)
i++;
assert(i < 65536);
- pdf_printf("<%04X> <%04X> <%s>\n", i, i + range_size[i] - 1,
+ pdf_printf(pdf, "<%04X> <%04X> <%s>\n", i, i + range_size[i] - 1,
utf16be_str(gtab[i].code));
i += range_size[i];
}
- pdf_printf("endbfrange\n");
+ pdf_printf(pdf, "endbfrange\n");
if (bfrange_count > 0)
goto write_bfrange;
@@ -574,37 +590,37 @@ integer write_cid_tounicode(fo_entry * fo, internalfontnumber f)
else
subrange_count = bfchar_count;
bfchar_count -= subrange_count;
- pdf_printf("%i beginbfchar\n", subrange_count);
+ pdf_printf(pdf, "%i beginbfchar\n", subrange_count);
for (j = 0; j < subrange_count; j++) {
while (i < 65536) {
if (range_size[i] > 1)
i += range_size[i];
else if (range_size[i] == 0)
i++;
- else /* range_size[i] == 1 */
+ else /* |range_size[i] == 1| */
break;
}
assert(i < 65536 && gtab[i].code != UNI_UNDEF);
if (gtab[i].code == UNI_STRING || gtab[i].code == UNI_EXTRA_STRING) {
assert(gtab[i].unicode_seq != NULL);
- pdf_printf("<%04X> <%s>\n", i, gtab[i].unicode_seq);
+ pdf_printf(pdf, "<%04X> <%s>\n", i, gtab[i].unicode_seq);
} else
- pdf_printf("<%04X> <%s>\n", i, utf16be_str(gtab[i].code));
+ pdf_printf(pdf, "<%04X> <%s>\n", i, utf16be_str(gtab[i].code));
i++;
}
- pdf_printf("endbfchar\n");
+ pdf_printf(pdf, "endbfchar\n");
if (bfchar_count > 0)
goto write_bfchar;
- /* free strings allocated by set_glyph_unicode() */
+ /* free strings allocated by |set_glyph_unicode()| */
for (i = 0; i < 65536; ++i) {
if (gtab[i].code == UNI_EXTRA_STRING)
xfree(gtab[i].unicode_seq);
}
- pdf_printf("endcmap\n"
+ pdf_printf(pdf, "endcmap\n"
"CMapName currentdict /CMap defineresource pop\n"
"end\n" "end\n" "%%%%EndResource\n" "%%%%EOF\n");
- pdf_end_stream();
+ pdf_end_stream(pdf);
return objnum;
}
diff --git a/Build/source/texk/web2c/luatexdir/font/tt_glyf.c b/Build/source/texk/web2c/luatexdir/font/tt_glyf.w
index 1ca35e8800f..b22d5748284 100644
--- a/Build/source/texk/web2c/luatexdir/font/tt_glyf.c
+++ b/Build/source/texk/web2c/luatexdir/font/tt_glyf.w
@@ -1,39 +1,39 @@
-/* tt_glyf.c
-
- Copyright 2002 by Jin-Hwan Cho and Shunsaku Hirata,
- the dvipdfmx project team <dvipdfmx@project.ktug.or.kr>
- Copyright 2006-2008 Taco Hoekwater <taco@luatex.org>
+% tt_glyf.w
+%
+% Copyright 2002 by Jin-Hwan Cho and Shunsaku Hirata,
+% the dvipdfmx project team <dvipdfmx@@project.ktug.or.kr>
+% Copyright 2006-2010 Taco Hoekwater <taco@@luatex.org>
- This file is part of LuaTeX.
+% This file is part of LuaTeX.
- LuaTeX 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 2 of the License, or (at your
- option) any later version.
+% LuaTeX 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 2 of the License, or (at your
+% option) any later version.
- LuaTeX 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 Lesser General Public
- License for more details.
+% LuaTeX 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 Lesser General Public
+% License for more details.
- You should have received a copy of the GNU General Public License along
- with LuaTeX; if not, see <http://www.gnu.org/licenses/>. */
+% You should have received a copy of the GNU General Public License along
+% with LuaTeX; if not, see <http://www.gnu.org/licenses/>.
-/*
- * Subsetting glyf, updating loca, hmtx, ...
- *
- */
+@* Subsetting glyf, updating loca, hmtx, etc.
+@ @c
#include "ptexlib.h"
-#include "sfnt.h"
-#include "tt_table.h"
-#include "tt_glyf.h"
-#include "writettf.h"
+#include "font/sfnt.h"
+#include "font/tt_table.h"
+#include "font/tt_glyf.h"
+#include "font/writettf.h"
static const char _svn_version[] =
- "$Id: tt_glyf.c 2271 2009-04-12 23:42:21Z oneiros $ $URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.40.6/source/texk/web2c/luatexdir/font/tt_glyf.c $";
+ "$Id: tt_glyf.w 3584 2010-04-02 17:45:55Z hhenkel $ "
+"$URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.60.0/source/texk/web2c/luatexdir/font/tt_glyf.w $";
+@ @c
#define NUM_GLYPH_LIMIT 65534
#define TABLE_DATA_ALLOC_SIZE 40960
#define GLYPH_ARRAY_ALLOC_SIZE 256
@@ -97,15 +97,17 @@ USHORT tt_add_glyph(struct tt_glyphs * g, USHORT gid, USHORT new_gid)
TT_ERROR("Too many glyphs.");
if (g->num_glyphs >= g->max_glyphs) {
- g->max_glyphs += GLYPH_ARRAY_ALLOC_SIZE;
+ g->max_glyphs = (USHORT) (g->max_glyphs + GLYPH_ARRAY_ALLOC_SIZE);
g->gd = RENEW(g->gd, g->max_glyphs, struct tt_glyph_desc);
}
g->gd[g->num_glyphs].gid = new_gid;
g->gd[g->num_glyphs].ogid = gid;
g->gd[g->num_glyphs].length = 0;
g->gd[g->num_glyphs].data = NULL;
- g->used_slot[new_gid / 8] |= (1 << (7 - (new_gid % 8)));
- g->num_glyphs += 1;
+ g->used_slot[new_gid / 8] =
+ (unsigned char) (g->used_slot[new_gid /
+ 8] | (1 << (7 - (new_gid % 8))));
+ g->num_glyphs++;
}
if (new_gid > g->last_gid) {
@@ -115,9 +117,9 @@ USHORT tt_add_glyph(struct tt_glyphs * g, USHORT gid, USHORT new_gid)
return new_gid;
}
-/*
- * Initialization
- */
+
+@ Initialization
+@c
struct tt_glyphs *tt_build_init(void)
{
struct tt_glyphs *g;
@@ -173,6 +175,7 @@ static int glyf_cmp(const void *v1, const void *v2)
return cmp;
}
+@ @c
int tt_build_tables(sfnt * sfont, struct tt_glyphs *g)
{
char *hmtx_table_data = NULL, *loca_table_data = NULL;
@@ -198,12 +201,15 @@ int tt_build_tables(sfnt * sfont, struct tt_glyphs *g)
TT_ERROR("Too many glyphs.");
/*
- * Read head, hhea, maxp, loca:
- *
- * unitsPerEm --> head
- * numHMetrics --> hhea
- * indexToLocFormat --> head
- * numGlyphs --> maxp
+ Read head, hhea, maxp, loca:
+
+ unitsPerEm --> head
+
+ numHMetrics --> hhea
+
+ indexToLocFormat --> head
+
+ numGlyphs --> maxp
*/
head = tt_read_head_table(sfont);
hhea = tt_read_hhea_table(sfont);
@@ -219,8 +225,8 @@ int tt_build_tables(sfnt * sfont, struct tt_glyphs *g)
os2 = tt_read_os2__table(sfont);
if (os2) {
- g->default_advh = os2->sTypoAscender - os2->sTypoDescender;
- g->default_tsb = g->default_advh - os2->sTypoAscender;
+ g->default_advh = (USHORT) (os2->sTypoAscender - os2->sTypoDescender);
+ g->default_tsb = (SHORT) (g->default_advh - os2->sTypoAscender);
/* dvipdfmx does this elsewhere! */
fd_cur->font_dim[STEMV_CODE].val =
@@ -252,17 +258,18 @@ int tt_build_tables(sfnt * sfont, struct tt_glyphs *g)
}
w_stat = NEW(g->emsize + 2, USHORT);
- memset(w_stat, 0, sizeof(USHORT) * (g->emsize + 2));
+ memset(w_stat, 0,
+ (size_t) (sizeof(USHORT) * ((long unsigned) g->emsize + 2)));
/*
* Read glyf table.
*/
offset = sfnt_locate_table(sfont, "glyf");
/*
- * The num_glyphs may grow when composite glyph is found.
- * A component of glyph refered by a composite glyph is appended
- * to used_glyphs if it is not already registered in used_glyphs.
- * Glyph programs of composite glyphs are modified so that it
- * correctly refer to new gid of their components.
+ The |num_glyphs| may grow when composite glyph is found.
+ A component of glyph refered by a composite glyph is appended
+ to |used_glyphs| if it is not already registered in |used_glyphs|.
+ Glyph programs of composite glyphs are modified so that it
+ correctly refer to new gid of their components.
*/
for (i = 0; i < NUM_GLYPH_LIMIT; i++) {
USHORT gid; /* old gid */
@@ -291,9 +298,9 @@ int tt_build_tables(sfnt * sfont, struct tt_glyphs *g)
g->gd[i].length = len;
g->gd[i].data = NULL;
if (g->gd[i].advw <= g->emsize) {
- w_stat[g->gd[i].advw] += 1;
+ w_stat[g->gd[i].advw]++;
} else {
- w_stat[g->emsize + 1] += 1; /* larger than em */
+ w_stat[g->emsize + 1]++; /* larger than em */
}
if (len == 0) { /* Does not contains any data. */
@@ -305,7 +312,7 @@ int tt_build_tables(sfnt * sfont, struct tt_glyphs *g)
g->gd[i].data = p = NEW(len, BYTE);
endptr = p + len;
- sfnt_seek_set(sfont, offset + loc);
+ sfnt_seek_set(sfont, (long) (offset + loc));
number_of_contours = sfnt_get_short(sfont);
p += sfnt_put_short(p, number_of_contours);
@@ -314,10 +321,11 @@ int tt_build_tables(sfnt * sfont, struct tt_glyphs *g)
g->gd[i].lly = sfnt_get_short(sfont);
g->gd[i].urx = sfnt_get_short(sfont);
g->gd[i].ury = sfnt_get_short(sfont);
- /* _FIXME_ */
+ /* |_FIXME_| */
#if 1
- if (!vmtx) /* vertOriginY == sTypeAscender */
- g->gd[i].tsb = g->default_advh - g->default_tsb - g->gd[i].ury;
+ if (!vmtx) /* |vertOriginY == sTypeAscender| */
+ g->gd[i].tsb =
+ (SHORT) (g->default_advh - g->default_tsb - g->gd[i].ury);
#endif
p += sfnt_put_short(p, g->gd[i].llx);
p += sfnt_put_short(p, g->gd[i].lly);
@@ -325,9 +333,9 @@ int tt_build_tables(sfnt * sfont, struct tt_glyphs *g)
p += sfnt_put_short(p, g->gd[i].ury);
/* Read evrything else. */
- sfnt_read(p, len - 10, sfont);
+ sfnt_read(p, (int) len - 10, sfont);
/*
- * Fix GIDs of composite glyphs.
+ Fix GIDs of composite glyphs.
*/
if (number_of_contours < 0) {
USHORT flags, cgid, new_gid; /* flag, gid of a component */
@@ -338,9 +346,9 @@ int tt_build_tables(sfnt * sfont, struct tt_glyphs *g)
/*
* Flags and gid of component glyph are both USHORT.
*/
- flags = ((*p) << 8) | *(p + 1);
+ flags = (USHORT) (((*p) << 8) | *(p + 1));
p += 2;
- cgid = ((*p) << 8) | *(p + 1);
+ cgid = (USHORT) (((*p) << 8) | *(p + 1));
if (cgid >= maxp->numGlyphs) {
TT_ERROR("Invalid gid (%u > %u) in composite glyph %u.",
cgid, maxp->numGlyphs, gid);
@@ -362,9 +370,11 @@ int tt_build_tables(sfnt * sfont, struct tt_glyphs *g)
p += 8;
} while (flags & MORE_COMPONENTS);
/*
- * TrueType instructions comes here:
- * length_of_instruction (ushort)
- * instruction (byte * length_of_instruction)
+ TrueType instructions comes here:
+
+ |length_of_instruction| (|ushort|)
+
+ instruction (|byte * length_of_instruction|)
*/
}
}
@@ -380,7 +390,7 @@ int tt_build_tables(sfnt * sfont, struct tt_glyphs *g)
for (i = 0; i < g->emsize + 1; i++) {
if (w_stat[i] > max_count) {
max_count = w_stat[i];
- g->dw = i;
+ g->dw = (USHORT) i;
}
}
}
@@ -396,10 +406,11 @@ int tt_build_tables(sfnt * sfont, struct tt_glyphs *g)
num_hm_known = 0;
last_advw = g->gd[g->num_glyphs - 1].advw;
for (i = g->num_glyphs - 1; i >= 0; i--) {
- padlen = (g->gd[i].length % 4) ? (4 - (g->gd[i].length % 4)) : 0;
- glyf_table_size += g->gd[i].length + padlen;
+ padlen =
+ (int) ((g->gd[i].length % 4) ? (4 - (g->gd[i].length % 4)) : 0);
+ glyf_table_size += (ULONG) (g->gd[i].length + (ULONG) padlen);
if (!num_hm_known && last_advw != g->gd[i].advw) {
- hhea->numberOfHMetrics = g->gd[i].gid + 2;
+ hhea->numberOfHMetrics = (USHORT) (g->gd[i].gid + 2);
num_hm_known = 1;
}
}
@@ -407,18 +418,19 @@ int tt_build_tables(sfnt * sfont, struct tt_glyphs *g)
if (!num_hm_known) {
hhea->numberOfHMetrics = 1;
}
- hmtx_table_size = hhea->numberOfHMetrics * 2 + (g->last_gid + 1) * 2;
+ hmtx_table_size =
+ (ULONG) (hhea->numberOfHMetrics * 2 + (g->last_gid + 1) * 2);
/*
- * Choosing short format does not always give good result
- * when compressed. Sometimes increases size.
+ Choosing short format does not always give good result
+ when compressed. Sometimes increases size.
*/
if (glyf_table_size < 0x20000UL) {
head->indexToLocFormat = 0;
- loca_table_size = (g->last_gid + 2) * 2;
+ loca_table_size = (ULONG) ((g->last_gid + 2) * 2);
} else {
head->indexToLocFormat = 1;
- loca_table_size = (g->last_gid + 2) * 4;
+ loca_table_size = (ULONG) ((g->last_gid + 2) * 4);
}
hmtx_table_data = p = NEW(hmtx_table_size, char);
@@ -440,10 +452,11 @@ int tt_build_tables(sfnt * sfont, struct tt_glyphs *g)
if (head->indexToLocFormat == 0) {
q += sfnt_put_ushort(q, (USHORT) (offset / 2));
} else {
- q += sfnt_put_ulong(q, offset);
+ q += sfnt_put_ulong(q, (LONG) offset);
}
}
- padlen = (g->gd[i].length % 4) ? (4 - (g->gd[i].length % 4)) : 0;
+ padlen =
+ (int) ((g->gd[i].length % 4) ? (4 - (g->gd[i].length % 4)) : 0);
if (g->gd[i].gid < hhea->numberOfHMetrics) {
p += sfnt_put_ushort(p, g->gd[i].advw);
}
@@ -451,11 +464,12 @@ int tt_build_tables(sfnt * sfont, struct tt_glyphs *g)
if (head->indexToLocFormat == 0) {
q += sfnt_put_ushort(q, (USHORT) (offset / 2));
} else {
- q += sfnt_put_ulong(q, offset);
+ q += sfnt_put_ulong(q, (LONG) offset);
}
- memset(glyf_table_data + offset, 0, g->gd[i].length + padlen);
+ memset(glyf_table_data + offset, 0,
+ (size_t) (g->gd[i].length + (ULONG) padlen));
memcpy(glyf_table_data + offset, g->gd[i].data, g->gd[i].length);
- offset += g->gd[i].length + padlen;
+ offset += (g->gd[i].length + (ULONG) padlen);
prev = g->gd[i].gid;
/* free data here since it consume much memory */
RELEASE(g->gd[i].data);
@@ -465,7 +479,7 @@ int tt_build_tables(sfnt * sfont, struct tt_glyphs *g)
if (head->indexToLocFormat == 0) {
q += sfnt_put_ushort(q, (USHORT) (offset / 2));
} else {
- q += sfnt_put_ulong(q, offset);
+ q += sfnt_put_ulong(q, (LONG) offset);
}
sfnt_set_table(sfont, "hmtx", (char *) hmtx_table_data,
@@ -477,7 +491,7 @@ int tt_build_tables(sfnt * sfont, struct tt_glyphs *g)
}
head->checkSumAdjustment = 0;
- maxp->numGlyphs = g->last_gid + 1;
+ maxp->numGlyphs = (USHORT) (g->last_gid + 1);
/* TODO */
sfnt_set_table(sfont, "maxp", tt_pack_maxp_table(maxp), TT_MAXP_TABLE_SIZE);
@@ -521,12 +535,15 @@ int tt_get_metrics(sfnt * sfont, struct tt_glyphs *g)
TT_ERROR("Invalid font type");
/*
- * Read head, hhea, maxp, loca:
- *
- * unitsPerEm --> head
- * numHMetrics --> hhea
- * indexToLocFormat --> head
- * numGlyphs --> maxp
+ Read head, hhea, maxp, loca:
+
+ unitsPerEm --> head
+
+ numHMetrics --> hhea
+
+ indexToLocFormat --> head
+
+ numGlyphs --> maxp
*/
head = tt_read_head_table(sfont);
hhea = tt_read_hhea_table(sfont);
@@ -541,8 +558,8 @@ int tt_get_metrics(sfnt * sfont, struct tt_glyphs *g)
hmtx = tt_read_longMetrics(sfont, maxp->numGlyphs, hhea->numberOfHMetrics);
os2 = tt_read_os2__table(sfont);
- g->default_advh = os2->sTypoAscender - os2->sTypoDescender;
- g->default_tsb = g->default_advh - os2->sTypoAscender;
+ g->default_advh = (USHORT) (os2->sTypoAscender - os2->sTypoDescender);
+ g->default_tsb = (SHORT) (g->default_advh - os2->sTypoAscender);
if (sfnt_find_table_pos(sfont, "vmtx") > 0) {
struct tt_vhea_table *vhea;
@@ -569,9 +586,9 @@ int tt_get_metrics(sfnt * sfont, struct tt_glyphs *g)
}
w_stat = NEW(g->emsize + 2, USHORT);
- memset(w_stat, 0, sizeof(USHORT) * (g->emsize + 2));
+ memset(w_stat, 0, (size_t) ((int) sizeof(USHORT) * (g->emsize + 2)));
/*
- * Read glyf table.
+ Read glyf table.
*/
offset = sfnt_locate_table(sfont, "glyf");
for (i = 0; i < g->num_glyphs; i++) {
@@ -598,9 +615,9 @@ int tt_get_metrics(sfnt * sfont, struct tt_glyphs *g)
g->gd[i].data = NULL;
if (g->gd[i].advw <= g->emsize) {
- w_stat[g->gd[i].advw] += 1;
+ w_stat[g->gd[i].advw]++;
} else {
- w_stat[g->emsize + 1] += 1; /* larger than em */
+ w_stat[g->emsize + 1]++; /* larger than em */
}
if (len == 0) { /* Does not contains any data. */
@@ -609,7 +626,7 @@ int tt_get_metrics(sfnt * sfont, struct tt_glyphs *g)
TT_ERROR("Invalid TrueType glyph data (gid %u).", gid);
}
- sfnt_seek_set(sfont, offset + loc);
+ sfnt_seek_set(sfont, (long) (offset + loc));
number_of_contours = sfnt_get_short(sfont);
/* BoundingBox: FWord x 4 */
@@ -617,10 +634,11 @@ int tt_get_metrics(sfnt * sfont, struct tt_glyphs *g)
g->gd[i].lly = sfnt_get_short(sfont);
g->gd[i].urx = sfnt_get_short(sfont);
g->gd[i].ury = sfnt_get_short(sfont);
- /* _FIXME_ */
+ /* |_FIXME_| */
#if 1
- if (!vmtx) /* vertOriginY == sTypeAscender */
- g->gd[i].tsb = g->default_advh - g->default_tsb - g->gd[i].ury;
+ if (!vmtx) /* |vertOriginY == sTypeAscender| */
+ g->gd[i].tsb =
+ (SHORT) (g->default_advh - g->default_tsb - g->gd[i].ury);
#endif
}
RELEASE(location);
@@ -640,7 +658,7 @@ int tt_get_metrics(sfnt * sfont, struct tt_glyphs *g)
for (i = 0; i < g->emsize + 1; i++) {
if (w_stat[i] > max_count) {
max_count = w_stat[i];
- g->dw = i;
+ g->dw = (USHORT) i;
}
}
}
diff --git a/Build/source/texk/web2c/luatexdir/font/tt_table.c b/Build/source/texk/web2c/luatexdir/font/tt_table.w
index d979542b476..35da4284ee8 100644
--- a/Build/source/texk/web2c/luatexdir/font/tt_table.c
+++ b/Build/source/texk/web2c/luatexdir/font/tt_table.w
@@ -1,49 +1,46 @@
-/* tt_table.c
-
- Copyright 2002 by Jin-Hwan Cho and Shunsaku Hirata,
- the dvipdfmx project team <dvipdfmx@project.ktug.or.kr>
- Copyright 2006-2008 Taco Hoekwater <taco@luatex.org>
+% tt_table.w
+%
+% Copyright 2002 by Jin-Hwan Cho and Shunsaku Hirata,
+% the dvipdfmx project team <dvipdfmx@@project.ktug.or.kr>
+% Copyright 2006-2010 Taco Hoekwater <taco@@luatex.org>
- This file is part of LuaTeX.
+% This file is part of LuaTeX.
- LuaTeX 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 2 of the License, or (at your
- option) any later version.
+% LuaTeX 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 2 of the License, or (at your
+% option) any later version.
- LuaTeX 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 Lesser General Public
- License for more details.
+% LuaTeX 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 Lesser General Public
+% License for more details.
- You should have received a copy of the GNU General Public License along
- with LuaTeX; if not, see <http://www.gnu.org/licenses/>. */
+% You should have received a copy of the GNU General Public License along
+% with LuaTeX; if not, see <http://www.gnu.org/licenses/>.
+@ @c
#include <stdio.h>
-#ifndef pdfTeX
-# include "system.h"
-# include "error.h"
-# include "mem.h"
-# include "mfileio.h"
-#else
-# include "ptexlib.h"
-#endif
-
-#include "sfnt.h"
-#include "tt_table.h"
+#include "ptexlib.h"
+#include "font/sfnt.h"
+#include "font/tt_table.h"
static const char _svn_version[] =
- "$Id: tt_table.c 2271 2009-04-12 23:42:21Z oneiros $ $URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.40.6/source/texk/web2c/luatexdir/font/tt_table.c $";
+ "$Id: tt_table.w 3584 2010-04-02 17:45:55Z hhenkel $ "
+"$URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.60.0/source/texk/web2c/luatexdir/font/tt_table.w $";
+
+@ tables contains information refered by other tables
+
+ |maxp->numGlyphs, etc --> loca, etc|
-/*
- tables contains information refered by other tables
- maxp->numGlyphs, etc --> loca, etc
- hhea->numberOfHMetrics --> hmtx
- head->indexToLocFormat --> loca
- head->glyphDataFormat --> glyf
-*/
+ |hhea->numberOfHMetrics --> hmtx|
+ |head->indexToLocFormat --> loca|
+
+ |head->glyphDataFormat --> glyf|
+
+@c
char *tt_pack_head_table(struct tt_head_table *table)
{
int i;
@@ -53,17 +50,17 @@ char *tt_pack_head_table(struct tt_head_table *table)
TT_ERROR("passed NULL pointer\n");
p = data = NEW(TT_HEAD_TABLE_SIZE, char);
- p += sfnt_put_ulong(p, table->version);
- p += sfnt_put_ulong(p, table->fontRevision);
- p += sfnt_put_ulong(p, table->checkSumAdjustment);
- p += sfnt_put_ulong(p, table->magicNumber);
+ p += sfnt_put_ulong(p, (LONG) table->version);
+ p += sfnt_put_ulong(p, (LONG) table->fontRevision);
+ p += sfnt_put_ulong(p, (LONG) table->checkSumAdjustment);
+ p += sfnt_put_ulong(p, (LONG) table->magicNumber);
p += sfnt_put_ushort(p, table->flags);
p += sfnt_put_ushort(p, table->unitsPerEm);
for (i = 0; i < 8; i++) {
- *(p++) = (table->created)[i];
+ *(p++) = (char) (table->created)[i];
}
for (i = 0; i < 8; i++) {
- *(p++) = (table->modified)[i];
+ *(p++) = (char) (table->modified)[i];
}
p += sfnt_put_short(p, table->xMin);
p += sfnt_put_short(p, table->yMin);
@@ -103,8 +100,8 @@ struct tt_head_table *tt_read_head_table(sfnt * sfont)
table->yMin = sfnt_get_short(sfont);
table->xMax = sfnt_get_short(sfont);
table->yMax = sfnt_get_short(sfont);
- table->macStyle = sfnt_get_short(sfont);
- table->lowestRecPPEM = sfnt_get_short(sfont);
+ table->macStyle = (USHORT) sfnt_get_short(sfont);
+ table->lowestRecPPEM = (USHORT) sfnt_get_short(sfont);
table->fontDirectionHint = sfnt_get_short(sfont);
table->indexToLocFormat = sfnt_get_short(sfont);
table->glyphDataFormat = sfnt_get_short(sfont);
@@ -117,7 +114,7 @@ char *tt_pack_maxp_table(struct tt_maxp_table *table)
char *p, *data;
p = data = NEW(TT_MAXP_TABLE_SIZE, char);
- p += sfnt_put_ulong(p, table->version);
+ p += sfnt_put_ulong(p, (LONG) table->version);
p += sfnt_put_ushort(p, table->numGlyphs);
p += sfnt_put_ushort(p, table->maxPoints);
p += sfnt_put_ushort(p, table->maxContours);
@@ -168,7 +165,7 @@ char *tt_pack_hhea_table(struct tt_hhea_table *table)
char *p, *data;
p = data = NEW(TT_HHEA_TABLE_SIZE, char);
- p += sfnt_put_ulong(p, table->version);
+ p += sfnt_put_ulong(p, (LONG) table->version);
p += sfnt_put_short(p, table->Ascender);
p += sfnt_put_short(p, table->Descender);
p += sfnt_put_short(p, table->LineGap);
@@ -216,14 +213,15 @@ struct tt_hhea_table *tt_read_hhea_table(sfnt * sfont)
return table;
}
-/* vhea */
+@ vhea
+@c
char *tt_pack_vhea_table(struct tt_vhea_table *table)
{
int i;
char *p, *data;
p = data = NEW(TT_VHEA_TABLE_SIZE, char);
- p += sfnt_put_ulong(p, table->version);
+ p += sfnt_put_ulong(p, (LONG) table->version);
p += sfnt_put_short(p, table->vertTypoAscender);
p += sfnt_put_short(p, table->vertTypoDescender);
p += sfnt_put_short(p, table->vertTypoLineGap);
@@ -304,12 +302,12 @@ struct tt_VORG_table *tt_read_VORG_table(sfnt * sfont)
return vorg;
}
-/*
- * hmtx and vmtx
- *
- * Reading/writing hmtx and vmtx depend on other tables, maxp and hhea/vhea.
- */
+@ hmtx and vmtx
+
+Reading/writing hmtx and vmtx depend on other tables, maxp and hhea/vhea.
+
+@c
struct tt_longMetrics *tt_read_longMetrics(sfnt * sfont, USHORT numGlyphs,
USHORT numLongMetrics)
{
@@ -327,8 +325,10 @@ struct tt_longMetrics *tt_read_longMetrics(sfnt * sfont, USHORT numGlyphs,
return m;
}
-/* OS/2 table */
-/* this table may not exist */
+@ OS/2 table
+
+this table may not exist
+@c
struct tt_os2__table *tt_read_os2__table(sfnt * sfont)
{
struct tt_os2__table *table = NULL;
@@ -420,9 +420,9 @@ tt_get_name(sfnt * sfont, char *dest, USHORT destlen,
if (length > destlen - 1) {
fprintf(stderr,
"\n** Notice: Name string too long. Truncating **\n");
- length = destlen - 1;
+ length = (USHORT) (destlen - 1);
}
- sfnt_seek_set(sfont, name_offset + string_offset + offset);
+ sfnt_seek_set(sfont, (long) (name_offset + string_offset + offset));
sfnt_read((unsigned char *) dest, length, sfont);
dest[length] = '\0';
break;
@@ -439,18 +439,6 @@ USHORT tt_get_ps_fontname(sfnt * sfont, char *dest, USHORT destlen)
{
USHORT namelen = 0;
-#ifdef XETEX
-
- const char *name = FT_Get_Postscript_Name(sfont->ft_face);
- namelen = strlen(name);
- if (namelen > destlen - 1) {
- strncpy(dest, name, destlen - 1);
- dest[destlen] = 0;
- } else
- strcpy(dest, name);
-
-#else
-
/* First try Mac-Roman PS name and then Win-Unicode PS name */
if ((namelen = tt_get_name(sfont, dest, destlen, 1, 0, 0, 6)) != 0 ||
(namelen = tt_get_name(sfont, dest, destlen, 3, 1, 0x409u, 6)) != 0 ||
@@ -470,7 +458,6 @@ USHORT tt_get_ps_fontname(sfnt * sfont, char *dest, USHORT destlen)
*/
namelen = tt_get_name(sfont, dest, destlen, 1, 0, 0, 1);
}
-#endif
return namelen;
}
diff --git a/Build/source/texk/web2c/luatexdir/font/vfovf.c b/Build/source/texk/web2c/luatexdir/font/vfovf.w
index 407076c215e..cc3c93ad8b5 100644
--- a/Build/source/texk/web2c/luatexdir/font/vfovf.c
+++ b/Build/source/texk/web2c/luatexdir/font/vfovf.w
@@ -1,32 +1,31 @@
-/* vfovf.c
+% vfovf.w
- Copyright 1996-2006 Han The Thanh <thanh@pdftex.org>
- Copyright 2006-2009 Taco Hoekwater <taco@luatex.org>
+% Copyright 1996-2006 Han The Thanh <thanh@@pdftex.org>
+% Copyright 2006-2009 Taco Hoekwater <taco@@luatex.org>
- This file is part of LuaTeX.
+% This file is part of LuaTeX.
- LuaTeX 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 2 of the License, or (at your
- option) any later version.
+% LuaTeX 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 2 of the License, or (at your
+% option) any later version.
- LuaTeX 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 Lesser General Public
- License for more details.
+% LuaTeX 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 Lesser General Public
+% License for more details.
- You should have received a copy of the GNU General Public License along
- with LuaTeX; if not, see <http://www.gnu.org/licenses/>. */
+% You should have received a copy of the GNU General Public License along
+% with LuaTeX; if not, see <http://www.gnu.org/licenses/>.
+@ @c
#include "ptexlib.h"
-#include "luatex-api.h"
-#include "luatexfont.h"
-#include "inc-vfovf.h"
static const char _svn_version[] =
- "$Id: vfovf.c 2448 2009-06-08 07:43:50Z taco $ "
- "$URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.40.6/source/texk/web2c/luatexdir/font/vfovf.c $";
+ "$Id: vfovf.w 3584 2010-04-02 17:45:55Z hhenkel $ "
+ "$URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.60.0/source/texk/web2c/luatexdir/font/vfovf.w $";
+@ @c
/* this is a hack! */
#define font_max 5000
@@ -97,13 +96,14 @@ static const char _svn_version[] =
#define long_char 242 /* \.{VF} command for general character packet */
#define vf_id 202 /* identifies \.{VF} files */
-/* go out \.{VF} processing with an error message */
+@ go out \.{VF} processing with an error message
+@c
#define bad_vf(a) { xfree(vf_buffer); print_nlp(); \
- print_string("Error in processing VF font ("); \
- print_string(font_name(f)); \
- print_string(".vf): "); \
- print_string(a); \
- print_string(", virtual font will be ignored"); \
+ tprint("Error in processing VF font ("); \
+ tprint(font_name(f)); \
+ tprint(".vf): "); \
+ tprint(a); \
+ tprint(", virtual font will be ignored"); \
print_ln(); return; }
#define lua_bad_vf(a) { xfree(vf_buffer); \
@@ -120,6 +120,7 @@ static const char _svn_version[] =
#define vf_stack_size 100 /* \.{DVI} files shouldn't |push| beyond this depth */
+@ @c
typedef unsigned char vf_stack_index; /* an index into the stack */
typedef struct vf_stack_record {
@@ -128,11 +129,11 @@ typedef struct vf_stack_record {
boolean auto_expand_vf(internal_font_number f); /* forward */
-/* get a byte from\.{VF} file */
-
+@ get a byte from\.{VF} file
+@c
#define vf_byte(a) \
{ \
- real_eight_bits vf_tmp_b; \
+ eight_bits vf_tmp_b; \
if (vf_cur >= vf_size) { \
pdftex_fail("unexpected eof on virtual font"); \
} \
@@ -140,6 +141,7 @@ boolean auto_expand_vf(internal_font_number f); /* forward */
a = vf_tmp_b; \
}
+@ @c
#define vf_replace_z() \
{ \
vf_alpha = 16; \
@@ -147,19 +149,20 @@ boolean auto_expand_vf(internal_font_number f); /* forward */
vf_z = vf_z / 2; \
vf_alpha += vf_alpha; \
} \
- vf_beta = 256 / vf_alpha; \
- vf_alpha = vf_alpha * vf_z; \
+ vf_beta = (char)(256 / vf_alpha); \
+ vf_alpha = (vf_alpha * vf_z); \
}
-/* read |k| bytes as an integer from \.{VF} file */
-/* beware: the vf_read() macro differs from vf_read() in vftovp.web for 1...3 byte words */
+@ read |k| bytes as an integer from \.{VF} file
+beware: the |vf_read()| macro differs from |vf_read()| in vftovp.web for 1...3 byte words.
+@c
#define vf_read(k, l) \
{ \
- integer itmp = 0, dtmp = k, jtmp = 0; \
+ int itmp = 0, dtmp = (int)(k), jtmp = 0; \
while (dtmp > 0) { \
vf_byte(jtmp); \
- if ((dtmp == (integer) k) && jtmp > 127) \
+ if ((dtmp == (int) k) && jtmp > 127) \
jtmp = jtmp - 256; \
itmp = itmp * 256 + jtmp; \
decr(dtmp); \
@@ -169,7 +172,8 @@ boolean auto_expand_vf(internal_font_number f); /* forward */
#define vf_read_u(k, l) \
{ \
- unsigned int dtmp = k, itmp = 0, jtmp = 0; \
+ int dtmp = (int)(k); \
+ unsigned int itmp = 0, jtmp = 0; \
while (dtmp-- > 0) { \
vf_byte(jtmp); \
itmp = itmp * 256 + jtmp; \
@@ -177,52 +181,51 @@ boolean auto_expand_vf(internal_font_number f); /* forward */
l = itmp; \
}
-void pdf_check_vf_cur_val(void)
+@ @c
+void pdf_check_vf(internal_font_number f)
{
- internal_font_number f;
- f = cur_val;
if (font_type(f) == virtual_font_type)
- pdf_error(maketexstring("font"),
- maketexstring("command cannot be used with virtual font"));
+ pdf_error("font", "command cannot be used with virtual font");
}
static void
-vf_local_font_warning(internal_font_number f, internal_font_number k, const char *s,
- integer a, integer b)
+vf_local_font_warning(internal_font_number f, internal_font_number k,
+ const char *s, int a, int b)
{
print_nlp();
- print_string(s);
- print_string(" in local font ");
- print_string(font_name(k));
- print_string(" (");
+ tprint(s);
+ tprint(" in local font ");
+ tprint(font_name(k));
+ tprint(" (");
print_int(b);
- print_string(" != ");
+ tprint(" != ");
print_int(a);
- print_string(") in virtual font ");
- print_string(font_name(f));
- print_string(".vf ignored.");
+ tprint(") in virtual font ");
+ tprint(font_name(f));
+ tprint(".vf ignored.");
}
-/* process a local font in \.{VF} file */
-
-static internal_font_number
-vf_def_font(internal_font_number f, unsigned char *vf_buffer, integer * vf_cr)
+@ process a local font in \.{VF} file
+@c
+internal_font_number
+vf_def_font(internal_font_number f, unsigned char *vf_buffer, int *vf_cr)
{
internal_font_number k;
str_number s;
+ char *st;
scaled ds, fs;
four_quarters cs;
memory_word tmp_w; /* accumulator */
- integer junk;
+ int junk;
unsigned long checksum;
cs.b0 = vf_buffer[(*vf_cr)];
cs.b1 = vf_buffer[(*vf_cr) + 1];
cs.b2 = vf_buffer[(*vf_cr) + 2];
cs.b3 = vf_buffer[(*vf_cr) + 3];
(*vf_cr) += 4;
- checksum =
- cs.b0 * 256 * 256 * 256 + cs.b1 * 256 * 256 + cs.b2 * 256 + cs.b3;
+ checksum = (unsigned)
+ (cs.b0 * 256 * 256 * 256 + cs.b1 * 256 * 256 + cs.b2 * 256 + cs.b3);
k = vf_buffer[(*vf_cr)];
(*vf_cr)++;
if (k > 127)
@@ -258,67 +261,50 @@ vf_def_font(internal_font_number f, unsigned char *vf_buffer, integer * vf_cr)
tmp_b0--;
(*vf_cr)++; /* skip the font path */
}
- string_room(tmp_b1);
+ str_room((unsigned) tmp_b1);
while (tmp_b1 > 0) {
tmp_b1--;
junk = vf_buffer[(*vf_cr)];
(*vf_cr)++;
- append_pool_char(junk);
+ append_char(junk);
}
s = make_string();
- k = tfm_lookup(s, fs);
+ st = makecstring(s);
+ k = tfm_lookup(st, fs, font_expand_ratio(f));
if (k == null_font)
- k = read_font_info(get_nullcs(), s, fs, -1);
+ k = read_font_info(null_cs, st, fs, -1);
+ free(st);
if (k != null_font) {
if (checksum != 0 && font_checksum(k) != 0
&& checksum != font_checksum(k))
- vf_local_font_warning(f, k, "checksum mismatch", checksum,
- font_checksum(k));
+ vf_local_font_warning(f, k, "checksum mismatch", (int) checksum,
+ (int) font_checksum(k));
if (ds != font_dsize(k))
vf_local_font_warning(f, k, "design size mismatch", ds,
font_dsize(k));
}
- if (pdf_font_expand_ratio(f) != 0)
- set_expand_params(k, pdf_font_auto_expand(f),
- pdf_font_expand_ratio(pdf_font_stretch(f)),
- -pdf_font_expand_ratio(pdf_font_shrink(f)),
- pdf_font_step(f), pdf_font_expand_ratio(f));
+ if (font_expand_ratio(f) != 0)
+ set_expand_params(k, font_auto_expand(f),
+ font_expand_ratio(font_stretch(f)),
+ -font_expand_ratio(font_shrink(f)),
+ font_step(f), font_expand_ratio(f));
return k;
}
-
-static int open_vf_file(const char *fn, unsigned char **vbuffer, integer * vsize)
+@ @c
+static int open_vf_file(const char *fn, unsigned char **vbuffer, int *vsize)
{
boolean res; /* was the callback successful? */
- integer callback_id;
- boolean file_read; /* was |vf_file| successfully read? */
+ int callback_id;
+ boolean file_read = false; /* was |vf_file| successfully read? */
FILE *vf_file;
- char *fnam = NULL;
-
-
+ const char *fname = luatex_find_file(fn, find_vf_file_callback);
+ if (!fname)
+ fname = fn;
-
- namelength = strlen(fn);
- nameoffile = xmalloc(namelength + 2);
- strcpy((char *) (nameoffile + 1), fn);
-
- callback_id = callback_defined(find_vf_file_callback);
- if (callback_id > 0) {
- res = run_callback(callback_id, "S->S", fn, &fnam);
- if (res && (fnam != NULL) && (strlen(fnam) > 0)) {
- /* @<Fixup |nameoffile| after callback@>; */
- free(nameoffile);
- namelength = strlen(fnam);
- nameoffile = xmalloc(namelength + 2);
- strcpy((char *) (nameoffile + 1), fnam);
- } else {
- return 0;
- }
- }
callback_id = callback_defined(read_vf_file_callback);
if (callback_id > 0) {
- file_read = false;
- res = run_callback(callback_id, "S->bSd", stringcast(nameoffile + 1),
+ res = run_callback(callback_id, "S->bSd", fname,
&file_read, vbuffer, vsize);
if (res && file_read && (*vsize > 0)) {
return 1;
@@ -326,9 +312,12 @@ static int open_vf_file(const char *fn, unsigned char **vbuffer, integer * vsize
if (!file_read)
return 0; /* -1 */
} else {
- if (ovf_b_open_in(vf_file) || vf_b_open_in(vf_file)) {
+ if (luatex_open_input
+ (&(vf_file), fname, kpse_ovf_format, FOPEN_RBIN_MODE, false)
+ || luatex_open_input(&(vf_file), fname, kpse_vf_format,
+ FOPEN_RBIN_MODE, false)) {
res = read_vf_file(vf_file, vbuffer, vsize);
- b_close(vf_file);
+ close_file(vf_file);
if (res) {
return 1;
}
@@ -340,19 +329,20 @@ static int open_vf_file(const char *fn, unsigned char **vbuffer, integer * vsize
}
-/*
- @ The |do_vf| procedure attempts to read the \.{VF} file for a font, and sets
+
+@ The |do_vf| procedure attempts to read the \.{VF} file for a font, and sets
|font_type()| to |real_font_type| if the \.{VF} file could not be found
or loaded, otherwise sets |font_type()| to |virtual_font_type|. At this
time, |tmp_f| is the internal font number of the current \.{TFM} font. To
process font definitions in virtual font we call |vf_def_font|.
-*/
-#define append_packet(k) vpackets[vf_np++] = k
+@c
+#define append_packet(k) vpackets[vf_np++] = (eight_bits)(k)
-/* life is easier if all internal font commands are fnt4 and
- all character commands are set4 or put4 */
+@ life is easier if all internal font commands are fnt4 and
+ all character commands are set4 or put4
+@c
#define append_fnt_set(k) \
{ \
assert(k > 0); \
@@ -368,8 +358,9 @@ static int open_vf_file(const char *fn, unsigned char **vbuffer, integer * vsize
append_packet((k & 0x000000FF)); \
}
-/* some of these things happen twice, adding a define is simplest */
+@ some of these things happen twice, adding a define is simplest
+@c
#define test_checksum() { vf_byte(tmp_b0); vf_byte(tmp_b1); \
vf_byte(tmp_b2); vf_byte(tmp_b3); \
if (((tmp_b0 != 0) || (tmp_b1 != 0) || (tmp_b2 != 0) || (tmp_b3 != 0)) && \
@@ -378,9 +369,9 @@ static int open_vf_file(const char *fn, unsigned char **vbuffer, integer * vsize
((tmp_b0 != font_check_0(f)) || (tmp_b1 != font_check_1(f)) || \
(tmp_b2 != font_check_2(f)) || (tmp_b3 != font_check_3(f)))) { \
print_nlp(); \
- print_string("checksum mismatch in font "); \
- print_string(font_name(f)); \
- print_string(".vf ignored "); } }
+ tprint("checksum mismatch in font "); \
+ tprint(font_name(f)); \
+ tprint(".vf ignored "); } }
#define test_dsize() \
{ \
@@ -388,21 +379,22 @@ static int open_vf_file(const char *fn, unsigned char **vbuffer, integer * vsize
vf_read(4, read_tmp); \
if ((read_tmp / 16) != font_dsize(f)) { \
print_nlp(); \
- print_string("design size mismatch in font "); \
- print_string(font_name(f)); \
- print_string(".vf ignored"); \
+ tprint("design size mismatch in font "); \
+ tprint(font_name(f)); \
+ tprint(".vf ignored"); \
} \
}
-static int count_packet_bytes(real_eight_bits * vf_buf, int cur_bute, int count)
+@ @c
+int count_packet_bytes(eight_bits * vf_buf, int cur_bute, int count)
{
- int k = 0;
+ unsigned k = 0;
int ff = 0;
int acc = 0;
unsigned int cmd = 0;
unsigned int d = 0;
- while (k < count) {
- cmd = vf_buf[cur_bute + k];
+ while (k < (unsigned) count) {
+ cmd = vf_buf[cur_bute + (int) k];
k++;
if (cmd < set1) {
if (ff == 0) {
@@ -604,40 +596,40 @@ static int count_packet_bytes(real_eight_bits * vf_buf, int cur_bute, int count)
k += 4;
break;
case xxx1:
- d = vf_buf[cur_bute + k];
+ d = vf_buf[cur_bute + (int) k];
k++;
k += d;
- acc += 5 + d;
+ acc += 5 + (int) d;
break;
case xxx2:
- d = vf_buf[cur_bute + k];
+ d = vf_buf[cur_bute + (int) k];
k++;
- d = d * 256 + vf_buf[cur_bute + k];
+ d = d * 256 + vf_buf[cur_bute + (int) k];
k++;
k += d;
- acc += 5 + d;
+ acc += 5 + (int) d;
break;
case xxx3:
- d = vf_buf[cur_bute + k];
+ d = vf_buf[cur_bute + (int) k];
k++;
- d = d * 256 + vf_buf[cur_bute + k];
+ d = d * 256 + vf_buf[cur_bute + (int) k];
k++;
- d = d * 256 + vf_buf[cur_bute + k];
+ d = d * 256 + vf_buf[cur_bute + (int) k];
k++;
k += d;
- acc += 5 + d;
+ acc += 5 + (int) d;
break;
case xxx4:
- d = vf_buf[cur_bute + k];
+ d = vf_buf[cur_bute + (int) k];
k++;
- d = d * 256 + vf_buf[cur_bute + k];
+ d = d * 256 + vf_buf[cur_bute + (int) k];
k++;
- d = d * 256 + vf_buf[cur_bute + k];
+ d = d * 256 + vf_buf[cur_bute + (int) k];
k++;
- d = d * 256 + vf_buf[cur_bute + k];
+ d = d * 256 + vf_buf[cur_bute + (int) k];
k++;
k += d;
- acc += 5 + d;
+ acc += 5 + (int) d;
break;
case w0:
acc += 5;
@@ -665,29 +657,32 @@ static int count_packet_bytes(real_eight_bits * vf_buf, int cur_bute, int count)
return (acc + 1);
}
+@ @c
void do_vf(internal_font_number f)
{
- integer k, i;
+ int k, i;
unsigned cmd, n;
scaled x, y, w, z, h, v;
- integer cc, cmd_length, packet_length;
+ int cc, cmd_length;
+ unsigned packet_length;
charinfo *co;
scaled tfm_width;
- integer save_cur_byte;
+ int save_cur_byte;
vf_stack_index stack_level;
- integer vf_z; /* multiplier */
- integer vf_alpha; /* correction for negative values */
+ int vf_z; /* multiplier */
+ int vf_alpha; /* correction for negative values */
char vf_beta; /* divisor */
- integer vf_np;
- real_eight_bits *vpackets;
+ int vf_np;
+ eight_bits *vpackets;
memory_word tmp_w; /* accumulator */
vf_stack_record vf_stack[256];
- integer junk;
+ int junk;
+ unsigned utmp;
unsigned char *vf_buffer;
- integer vf_size;
- integer vf_cur;
- integer *vf_local_fnts = NULL; /* external font ids */
- integer *vf_real_fnts = NULL; /* internal font ids */
+ int vf_size;
+ int vf_cur;
+ unsigned *vf_local_fnts = NULL; /* external font ids */
+ unsigned *vf_real_fnts = NULL; /* internal font ids */
unsigned vf_nf = 0; /* local font counter */
if (font_type(f) != unknown_font_type)
@@ -696,13 +691,13 @@ void do_vf(internal_font_number f)
if (auto_expand_vf(f))
return; /* auto-expanded virtual font */
stack_level = 0;
- /* @<Open |vf_file|, return if not found@>; */
+ /* Open |vf_file|, return if not found */
vf_cur = 0;
vf_buffer = NULL;
vf_size = 0;
if (!open_vf_file(font_name(f), &vf_buffer, &vf_size))
return;
- /* @<Process the preamble@>;@/ */
+ /* Process the preamble */
set_font_type(f, virtual_font_type);
vf_byte(k);
if (k != pre)
@@ -715,16 +710,15 @@ void do_vf(internal_font_number f)
vf_byte(junk);
test_checksum();
test_dsize();
- /* update_terminal; */
vf_z = font_size(f);
vf_replace_z();
- /* @<Process the font definitions@>;@/ */
+ /* Process the font definitions */
/* scan forward to find the number of internal fonts */
vf_nf = 0;
save_cur_byte = vf_cur;
vf_byte(cmd);
while ((cmd >= fnt_def1) && (cmd <= (fnt_def1 + 3))) {
- vf_read_u((cmd - fnt_def1 + 1), junk);
+ vf_read_u((cmd - fnt_def1 + 1), utmp);
vf_read(4, junk);
vf_read(4, junk);
vf_read(4, junk);
@@ -741,15 +735,15 @@ void do_vf(internal_font_number f)
vf_byte(cmd);
/* malloc and fill the local font arrays */
if (vf_nf > 0) {
- i = vf_nf * sizeof(integer);
- vf_local_fnts = xmalloc(i);
- memset(vf_local_fnts, 0, i);
- vf_real_fnts = xmalloc(i);
- memset(vf_real_fnts, 0, i);
+ unsigned ii = (unsigned) ((unsigned) vf_nf * sizeof(int));
+ vf_local_fnts = xmalloc(ii);
+ memset(vf_local_fnts, 0, ii);
+ vf_real_fnts = xmalloc(ii);
+ memset(vf_real_fnts, 0, ii);
vf_nf = 0;
while ((cmd >= fnt_def1) && (cmd <= (fnt_def1 + 3))) {
vf_read_u((cmd - fnt_def1 + 1), vf_local_fnts[vf_nf]);
- vf_real_fnts[vf_nf] = vf_def_font(f, vf_buffer, &vf_cur);
+ vf_real_fnts[vf_nf] = (unsigned) vf_def_font(f, vf_buffer, &vf_cur);
incr(vf_nf);
vf_byte(cmd);
}
@@ -757,11 +751,12 @@ void do_vf(internal_font_number f)
while (cmd <= long_char) {
- /* @<Build a character packet@>;@/ */
+ /* Build a character packet */
vf_np = 0;
if (cmd == long_char) {
vf_read_u(4, packet_length);
- vf_read_u(4, cc);
+ vf_read_u(4, utmp);
+ cc = (int) utmp;
if (!char_exists(f, cc)) {
bad_vf("invalid character code");
}
@@ -773,21 +768,22 @@ void do_vf(internal_font_number f)
if (!char_exists(f, cc)) {
bad_vf("invalid character code");
}
- vf_read_u(3, k); /* cf. vftovp.web, line 1028 */
+ vf_read_u(3, utmp);
+ k = (int) utmp; /* cf. vftovp.web, line 1028 */
tfm_width = store_scaled_f(k, font_size(f));
}
- if (packet_length < 0)
- bad_vf("negative packet length");
+
+
if (tfm_width != char_width(f, cc)) {
if (tfm_width != char_width(f, cc)) {
print_nlp();
- print_string("character width mismatch in font ");
- print_string(font_name(f));
- print_string(".vf ignored");
+ tprint("character width mismatch in font ");
+ tprint(font_name(f));
+ tprint(".vf ignored");
}
}
- k = count_packet_bytes(vf_buffer, vf_cur, packet_length);
- vpackets = xmalloc(k + 1); /* need one extra extra for packet_end */
+ k = count_packet_bytes(vf_buffer, vf_cur, (int) packet_length);
+ vpackets = xmalloc((unsigned) (k + 1)); /* need one extra extra for |packet_end| */
co = get_charinfo(f, cc);
k = 0;
w = 0;
@@ -800,7 +796,7 @@ void do_vf(internal_font_number f)
if (cmd < set1) {
if (k == 0) {
- k = vf_real_fnts[0];
+ k = (int) vf_real_fnts[0];
append_fnt_set(k);
}
append_packet(packet_char_code);
@@ -811,20 +807,21 @@ void do_vf(internal_font_number f)
} else if (((fnt_num_0 <= cmd) && (cmd <= fnt_num_0 + 63)) ||
((fnt1 <= cmd) && (cmd <= fnt1 + 3))) {
if (cmd >= fnt1) {
- vf_read_u((cmd - fnt1 + 1), k);
+ vf_read_u((cmd - fnt1 + 1), utmp);
+ k = (int) utmp;
packet_length -= (cmd - fnt1 + 1);
} else {
- k = cmd - fnt_num_0;
+ k = (int) cmd - fnt_num_0;
}
/* change from local to external font id */
n = 0;
- while ((n < vf_nf) && (vf_local_fnts[n] != k))
+ while ((n < vf_nf) && (vf_local_fnts[n] != (unsigned) k))
n++;
if (n == vf_nf)
bad_vf("undefined local font");
- k = vf_real_fnts[n];
+ k = (int) vf_real_fnts[n];
append_fnt_set(k);
cmd_length = 0;
cmd = nop;
@@ -853,10 +850,11 @@ void do_vf(internal_font_number f)
case set3:
case set4:
if (k == 0) {
- k = vf_real_fnts[0];
+ k = (int) vf_real_fnts[0];
append_fnt_set(k);
}
- vf_read_u((cmd - set1 + 1), i);
+ vf_read_u((cmd - set1 + 1), utmp);
+ i = (int) utmp;
append_packet(packet_char_code);
append_four(i);
packet_length -= (cmd - set1 + 1);
@@ -866,10 +864,11 @@ void do_vf(internal_font_number f)
case put3:
case put4:
if (k == 0) {
- k = vf_real_fnts[0];
+ k = (int) vf_real_fnts[0];
append_fnt_set(k);
}
- vf_read_u((cmd - put1 + 1), i);
+ vf_read_u((cmd - put1 + 1), utmp);
+ i = (int) utmp;
append_packet(packet_push_code);
append_packet(packet_char_code);
append_four(i);
@@ -934,11 +933,12 @@ void do_vf(internal_font_number f)
case xxx2:
case xxx3:
case xxx4:
- vf_read_u((cmd - xxx1 + 1), cmd_length);
+ vf_read_u((cmd - xxx1 + 1), utmp);
+ cmd_length = (int) utmp;
packet_length -= (cmd - xxx1 + 1);
if (cmd_length <= 0)
bad_vf("special of negative length");
- packet_length -= cmd_length;
+ packet_length -= (unsigned) cmd_length;
append_packet(packet_special_code);
append_four(cmd_length);
@@ -968,8 +968,7 @@ void do_vf(internal_font_number f)
break;
case push:
if (stack_level == vf_stack_size) {
- overflow_string("virtual font stack size",
- vf_stack_size);
+ overflow("virtual font stack size", vf_stack_size);
} else {
vf_stack[stack_level].stack_w = w;
vf_stack[stack_level].stack_x = x;
@@ -1003,7 +1002,7 @@ void do_vf(internal_font_number f)
bad_vf("more PUSHs than POPs in character packet");
if (packet_length != 0)
bad_vf("invalid packet length or DVI command in packet");
- /* @<Store the packet being built@>; */
+ /* \.{Store the packet being built} */
set_charinfo_packets(co, vpackets);
vf_byte(cmd);
}
@@ -1013,6 +1012,7 @@ void do_vf(internal_font_number f)
xfree(vf_buffer);
}
+@ @c
#define make_command0(N,K) { \
lua_newtable(L); \
lua_pushstring(L, N); \
@@ -1052,29 +1052,31 @@ void do_vf(internal_font_number f)
int make_vf_table(lua_State * L, const char *cnom, scaled atsize)
{
- integer cmd, k, i;
- integer cc, cmd_length, packet_length;
+ int cmd, k, i;
+ int cc;
+ unsigned cmd_length, packet_length;
scaled tfm_width;
vf_stack_index stack_level;
- integer vf_z; /* multiplier */
- integer vf_alpha; /* correction for negative values */
+ int vf_z; /* multiplier */
+ int vf_alpha; /* correction for negative values */
char vf_beta; /* divisor */
- char *s;
+ eight_bits *s;
scaled h, v;
scaled w, x, y, z;
- integer s_top; /* lua stack */
- integer vf_nf; /* local font counter */
+ int s_top; /* lua stack */
+ int vf_nf; /* local font counter */
scaled ds, fs;
four_quarters cs;
memory_word tmp_w; /* accumulator */
vf_stack_record vf_stack[256];
unsigned char *vf_buffer;
- integer vf_size;
- integer vf_cur;
+ int vf_size;
+ int vf_cur;
+ unsigned utmp;
stack_level = 0;
- /* @<Open |vf_file|, return if not found@>; */
+ /* Open |vf_file|, return if not found */
vf_cur = 0;
vf_buffer = NULL;
vf_size = 0;
@@ -1087,7 +1089,7 @@ int make_vf_table(lua_State * L, const char *cnom, scaled atsize)
s_top = lua_gettop(L);
lua_newtable(L);
- /* @<Process the preamble@>;@/ */
+ /* Process the preamble */
vf_byte(k);
if (k != pre)
lua_bad_vf("PRE command expected");
@@ -1097,10 +1099,10 @@ int make_vf_table(lua_State * L, const char *cnom, scaled atsize)
vf_byte(cmd_length);
s = xmalloc(cmd_length);
- for (k = 1; k <= cmd_length; k++)
+ for (k = 1; k <= (int) cmd_length; k++)
vf_byte(s[(k - 1)]);
- lua_pushlstring(L, s, cmd_length);
+ lua_pushlstring(L, (char *) s, (size_t) cmd_length);
free(s);
lua_setfield(L, -2, "header");
@@ -1109,8 +1111,8 @@ int make_vf_table(lua_State * L, const char *cnom, scaled atsize)
vf_byte(cs.b2);
vf_byte(cs.b3);
lua_pushnumber(L,
- (unsigned long) (cs.b0 << 24) + (cs.b1 << 16) +
- (cs.b2 << 8) + cs.b3);
+ (lua_Number) ((cs.b0 << 24) + (cs.b1 << 16) +
+ (cs.b2 << 8) + cs.b3));
lua_setfield(L, -2, "checksum");
vf_read(4, k);
@@ -1125,11 +1127,9 @@ int make_vf_table(lua_State * L, const char *cnom, scaled atsize)
lua_pushinteger(L, atsize);
lua_setfield(L, -2, "size");
-
- /* update_terminal; */
vf_z = atsize;
vf_replace_z();
- /* @<Process the font definitions@>;@/ */
+ /* Process the font definitions */
vf_byte(cmd);
lua_newtable(L);
@@ -1137,7 +1137,8 @@ int make_vf_table(lua_State * L, const char *cnom, scaled atsize)
while ((cmd >= fnt_def1) && (cmd <= fnt_def1 + 3)) {
lua_newtable(L);
- vf_read_u((cmd - fnt_def1 + 1), vf_nf);
+ vf_read_u((cmd - fnt_def1 + 1), utmp);
+ vf_nf = (int) utmp;
vf_nf++;
/* checksum */
vf_byte(cs.b0);
@@ -1161,13 +1162,13 @@ int make_vf_table(lua_State * L, const char *cnom, scaled atsize)
vf_byte(k);
} /* skip the font path */
- s = xmalloc(tmp_b1 + 1);
+ s = xmalloc((unsigned) (tmp_b1 + 1));
k = 0;
while (tmp_b1-- > 0)
vf_byte(s[k++]);
s[k] = 0;
lua_pushstring(L, "name");
- lua_pushstring(L, xstrdup(s));
+ lua_pushstring(L, xstrdup((char *) s));
free(s);
lua_rawset(L, -3);
@@ -1184,18 +1185,20 @@ int make_vf_table(lua_State * L, const char *cnom, scaled atsize)
lua_newtable(L); /* 'characters' */
while (cmd <= long_char) {
- /* @<Build a character packet@>;@/ */
+ /* Build a character packet */
if (cmd == long_char) {
vf_read_u(4, packet_length);
- vf_read_u(4, cc);
+ vf_read_u(4, utmp);
+ cc = (int) utmp;
vf_read(4, tfm_width);
} else {
- packet_length = cmd;
+ packet_length = (unsigned) cmd;
vf_byte(cc);
- vf_read_u(3, tfm_width);
+ vf_read_u(3, utmp);
+ tfm_width = (int) utmp;
}
- if (packet_length < 0)
- lua_bad_vf("negative packet length");
+
+
lua_newtable(L); /* for this character */
@@ -1224,9 +1227,10 @@ int make_vf_table(lua_State * L, const char *cnom, scaled atsize)
} else if (((fnt_num_0 <= cmd) && (cmd <= fnt_num_0 + 63)) ||
((fnt1 <= cmd) && (cmd <= fnt1 + 3))) {
if (cmd >= fnt1) {
- vf_read_u((cmd - fnt1 + 1), vf_nf);
+ vf_read_u((cmd - fnt1 + 1), utmp);
+ vf_nf = (int) utmp;
vf_nf++;
- packet_length -= (cmd - fnt1 + 1);
+ packet_length -= (unsigned) (cmd - fnt1 + 1);
} else {
vf_nf = cmd - fnt_num_0 + 1;
}
@@ -1257,9 +1261,10 @@ int make_vf_table(lua_State * L, const char *cnom, scaled atsize)
vf_nf = 1;
make_command1("font", vf_nf, k);
}
- vf_read_u((cmd - set1 + 1), i);
+ vf_read_u((cmd - set1 + 1), utmp);
+ i = (int) utmp;
make_command1("char", i, k);
- packet_length -= (cmd - set1 + 1);
+ packet_length -= (unsigned) (cmd - set1 + 1);
break;
case put1:
case put2:
@@ -1269,11 +1274,12 @@ int make_vf_table(lua_State * L, const char *cnom, scaled atsize)
vf_nf = 1;
make_command1("font", vf_nf, k);
}
- vf_read_u((cmd - put1 + 1), i);
+ vf_read_u((cmd - put1 + 1), utmp);
+ i = (int) utmp;
make_command0("push", k);
make_command1("char", i, k);
make_command0("pop", k);
- packet_length -= (cmd - put1 + 1);
+ packet_length -= (unsigned) (cmd - put1 + 1);
break;
case right1:
case right2:
@@ -1281,7 +1287,7 @@ int make_vf_table(lua_State * L, const char *cnom, scaled atsize)
case right4:
vf_read((cmd - right1 + 1), i);
make_command1("right", store_scaled_f(i, atsize), k);
- packet_length -= (cmd - right1 + 1);
+ packet_length -= (unsigned) (cmd - right1 + 1);
break;
case w1:
case w2:
@@ -1289,7 +1295,7 @@ int make_vf_table(lua_State * L, const char *cnom, scaled atsize)
case w4:
vf_read((cmd - w1 + 1), w);
make_command1("right", store_scaled_f(w, atsize), k);
- packet_length -= (cmd - w1 + 1);
+ packet_length -= (unsigned) (cmd - w1 + 1);
break;
case x1:
case x2:
@@ -1297,7 +1303,7 @@ int make_vf_table(lua_State * L, const char *cnom, scaled atsize)
case x4:
vf_read((cmd - x1 + 1), x);
make_command1("right", store_scaled_f(x, atsize), k);
- packet_length -= (cmd - x1 + 1);
+ packet_length -= (unsigned) (cmd - x1 + 1);
break;
case down1:
case down2:
@@ -1305,7 +1311,7 @@ int make_vf_table(lua_State * L, const char *cnom, scaled atsize)
case down4:
vf_read((cmd - down1 + 1), i);
make_command1("down", store_scaled_f(i, atsize), k);
- packet_length -= (cmd - down1 + 1);
+ packet_length -= (unsigned) (cmd - down1 + 1);
break;
case y1:
case y2:
@@ -1313,7 +1319,7 @@ int make_vf_table(lua_State * L, const char *cnom, scaled atsize)
case y4:
vf_read((cmd - y1 + 1), y);
make_command1("down", store_scaled_f(y, atsize), k);
- packet_length -= (cmd - y1 + 1);
+ packet_length -= (unsigned) (cmd - y1 + 1);
break;
case z1:
case z2:
@@ -1321,19 +1327,19 @@ int make_vf_table(lua_State * L, const char *cnom, scaled atsize)
case z4:
vf_read((cmd - z1 + 1), z);
make_command1("down", store_scaled_f(z, atsize), k);
- packet_length -= (cmd - z1 + 1);
+ packet_length -= (unsigned) (cmd - z1 + 1);
break;
case xxx1:
case xxx2:
case xxx3:
case xxx4:
vf_read_u((cmd - xxx1 + 1), cmd_length);
- packet_length -= (cmd - xxx1 + 1);
+ packet_length -= (unsigned) (cmd - xxx1 + 1);
if (cmd_length <= 0)
lua_bad_vf("special of negative length");
packet_length -= cmd_length;
- s = xmalloc(cmd_length + 1);
+ s = xmalloc((cmd_length + 1));
i = 0;
while (cmd_length > 0) {
cmd_length--;
@@ -1341,7 +1347,8 @@ int make_vf_table(lua_State * L, const char *cnom, scaled atsize)
i++;
}
s[i] = 0;
- make_commands("special", strdup(s), i, k);
+ make_commands("special", xstrdup((char *) s), (size_t) i,
+ k);
free(s);
break;
case w0:
@@ -1360,8 +1367,7 @@ int make_vf_table(lua_State * L, const char *cnom, scaled atsize)
break;
case push:
if (stack_level == vf_stack_size) {
- overflow_string("virtual font stack size",
- vf_stack_size);
+ overflow("virtual font stack size", vf_stack_size);
} else {
vf_stack[stack_level].stack_w = w;
vf_stack[stack_level].stack_x = x;
@@ -1409,29 +1415,30 @@ int make_vf_table(lua_State * L, const char *cnom, scaled atsize)
}
-/* This function is called from |do_vf|, and fixes up the virtual data
- inside an auto-expanded virtual font */
+@ This function is called from |do_vf|, and fixes up the virtual data
+inside an auto-expanded virtual font
+@c
boolean auto_expand_vf(internal_font_number f)
{
internal_font_number bf;
- integer e, k;
- integer *vf_old_fonts, *vf_new_fonts;
- integer num = 0;
+ int e, k;
+ int *vf_old_fonts, *vf_new_fonts;
+ int num = 0;
- if ((!pdf_font_auto_expand(f)) || (pdf_font_blink(f) == null_font))
+ if ((!font_auto_expand(f)) || (pdf_font_blink(f) == null_font))
return false; /* not an auto-expanded font */
bf = pdf_font_blink(f);
if (font_type(bf) != virtual_font_type)
return false; /* not a virtual font */
- e = pdf_font_expand_ratio(f);
+ e = font_expand_ratio(f);
vf_old_fonts = packet_local_fonts(bf, &num);
if (num > 0) {
- vf_new_fonts = xmalloc(num * sizeof(integer));
+ vf_new_fonts = xmalloc((unsigned) ((unsigned) num * sizeof(int)));
for (k = 0; k < num; k++) {
vf_new_fonts[k] = auto_expand_font(vf_old_fonts[k], e);
copy_expand_params(vf_new_fonts[k], vf_old_fonts[k], e);
@@ -1444,37 +1451,19 @@ boolean auto_expand_vf(internal_font_number f)
return true;
}
-/* this function is not always safe, because it needs makecstring() */
-str_number expand_font_name(internal_font_number f, integer e)
-{
- int old_setting;
- old_setting = selector;
- selector = new_string;
- print_string(font_name(f));
- if (e > 0) {
- print_char('+');
- }
- print_int(e);
- selector = old_setting;
- return make_string();
-}
-
-
-internal_font_number auto_expand_font(internal_font_number f, integer e)
+@ @c
+internal_font_number auto_expand_font(internal_font_number f, int e)
{
internal_font_number k;
kerninfo *krn;
charinfo *co;
- char *fn;
- integer i;
+ int i;
scaled w;
k = copy_font(f);
- i = strlen(font_name(f)) + 12;
- fn = xmalloc(i);
- snprintf(fn, i, "%s%s%d", font_name(f), (e > 0 ? "+" : ""), (int) e);
- set_font_name(k, fn);
+ set_font_name(k, font_name(f));
+ set_font_expand_ratio(k, e);
for (i = font_bc(k); i <= font_ec(k); i++) {
- if (char_exists(k, i)) {
+ if (quick_char_exists(k, i)) {
co = get_charinfo(k, i);
w = round_xn_over_d(char_width(f, i), 1000 + e, 1000);
set_charinfo_width(co, w);
@@ -1493,21 +1482,22 @@ internal_font_number auto_expand_font(internal_font_number f, integer e)
return k;
}
+@ @c
void vf_expand_local_fonts(internal_font_number f)
{
internal_font_number lf;
- integer k, num;
- integer *vf_old_fonts;
+ int k, num;
+ int *vf_old_fonts;
pdfassert(font_type(f) == virtual_font_type);
num = 0;
vf_old_fonts = packet_local_fonts(f, &num);
if (num > 0) {
for (k = 0; k < num; k++) {
lf = vf_old_fonts[k];
- set_expand_params(lf, pdf_font_auto_expand(f),
- pdf_font_expand_ratio(pdf_font_stretch(f)),
- -pdf_font_expand_ratio(pdf_font_shrink(f)),
- pdf_font_step(f), pdf_font_expand_ratio(f));
+ set_expand_params(lf, font_auto_expand(f),
+ font_expand_ratio(font_stretch(f)),
+ -font_expand_ratio(font_shrink(f)),
+ font_step(f), font_expand_ratio(f));
if (font_type(lf) == virtual_font_type)
vf_expand_local_fonts(lf);
}
@@ -1515,33 +1505,34 @@ void vf_expand_local_fonts(internal_font_number f)
}
}
+@ @c
internal_font_number
-letter_space_font(halfword u, internal_font_number f, integer e)
+letter_space_font(halfword u, internal_font_number f, int e)
{
internal_font_number k;
scaled w, r;
char *new_font_name;
- integer vf_z;
- integer vf_alpha;
- integer vf_beta;
+ int vf_z;
+ int vf_alpha;
+ int vf_beta;
memory_word tmp_w; /* accumulator */
/* read a new font and expand the character widths */
- k = read_font_info(u, tex_font_name(f), font_size(f), font_natural_dir(f));
+ k = read_font_info(u, font_name(f), font_size(f), font_natural_dir(f));
set_no_ligatures(k); /* disable ligatures for letter-spaced fonts */
-/*
+#if 0
for (i = 0;i <= font_widths(k);i++) {
set_font_width(k,i,font_width(f,i)+round_xn_over_d(quad(k), e, 1000));
}
-*/
+#endif
/* append eg '+100ls' to font name */
- new_font_name = xmalloc(strlen(font_name(k)) + 8); /* |abs(e) <= 1000| */
+ new_font_name = xmalloc((unsigned) (strlen(font_name(k)) + 8)); /* |abs(e) <= 1000| */
if (e > 0) {
sprintf(new_font_name, "%s+%ils", font_name(k), (int) e);
} else {
- /* minus from %i */
+ /* minus from \%i */
sprintf(new_font_name, "%s%ils", font_name(k), (int) e);
}
set_font_name(k, new_font_name);
@@ -1559,22 +1550,22 @@ letter_space_font(halfword u, internal_font_number f, integer e)
w = vf_alpha + w;
}
r = w * vf_beta;
- tmp_b1 = r / vf_z;
+ tmp_b1 = (quarterword) (r / vf_z);
r = r % vf_z;
if (r == 0) {
tmp_b2 = 0;
} else {
r = r * 256;
- tmp_b2 = r / vf_z;
+ tmp_b2 = (quarterword) (r / vf_z);
r = r % vf_z;
}
if (r == 0) {
tmp_b3 = 0;
} else {
r = r * 256;
- tmp_b3 = r / vf_z;
+ tmp_b3 = (quarterword) (r / vf_z);
}
- /*
+#if 0
vf_packet_base[k] = new_vf_packet(k);
for (c=font_bc(k);c<=font_ec(k);c++) {
@@ -1598,14 +1589,13 @@ letter_space_font(halfword u, internal_font_number f, integer e)
store_packet(k, c, s);
flush_str(s);
}
- */
+#endif
return k;
}
-/* the fontname has [+-]\d+ls at the end */
-
-#if 0 /* unused */
-static boolean is_letterspaced_font(internal_font_number f)
+@ the fontname has [+-]\d+ls at the end
+@c
+boolean is_letterspaced_font(internal_font_number f)
{
char *i, *j;
if (font_type(f) != virtual_font_type)
@@ -1626,10 +1616,8 @@ static boolean is_letterspaced_font(internal_font_number f)
return false;
return true;
}
-#endif
-
-/* TODO */
+@ @c
internal_font_number copy_font_info(internal_font_number f)
{
return copy_font(f);
diff --git a/Build/source/texk/web2c/luatexdir/font/vfpacket.c b/Build/source/texk/web2c/luatexdir/font/vfpacket.w
index 161330469e3..eb28fcdcc4c 100644
--- a/Build/source/texk/web2c/luatexdir/font/vfpacket.c
+++ b/Build/source/texk/web2c/luatexdir/font/vfpacket.w
@@ -1,38 +1,40 @@
-/* vfpacket.c
-
- Copyright 1996-2006 Han The Thanh <thanh@pdftex.org>
- Copyright 2006-2008 Taco Hoekwater <taco@luatex.org>
+% vfpacket.w
- This file is part of LuaTeX.
+% Copyright 1996-2006 Han The Thanh <thanh@@pdftex.org>
+% Copyright 2006-2009 Taco Hoekwater <taco@@luatex.org>
- LuaTeX 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 2 of the License, or (at your
- option) any later version.
+% This file is part of LuaTeX.
- LuaTeX 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 Lesser General Public
- License for more details.
+% LuaTeX 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 2 of the License, or (at your
+% option) any later version.
- You should have received a copy of the GNU General Public License along
- with LuaTeX; if not, see <http://www.gnu.org/licenses/>. */
+% LuaTeX 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 Lesser General Public
+% License for more details.
+% You should have received a copy of the GNU General Public License along
+% with LuaTeX; if not, see <http://www.gnu.org/licenses/>.
+
+@ @c
#include "ptexlib.h"
static const char _svn_version[] =
- "$Id: vfpacket.c 2414 2009-06-03 12:57:01Z taco $ $URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.40.6/source/texk/web2c/luatexdir/font/vfpacket.c $";
+ "$Id: vfpacket.w 3584 2010-04-02 17:45:55Z hhenkel $ "
+ "$URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.60.0/source/texk/web2c/luatexdir/font/vfpacket.w $";
+
-/*
- The |do_vf_packet| procedure is called in order to interpret the
+@ The |do_vf_packet| procedure is called in order to interpret the
character packet for a virtual character. Such a packet may contain
the instruction to typeset a character from the same or an other
virtual font; in such cases |do_vf_packet| calls itself
recursively. The recursion level, i.e., the number of times this has
happened, is kept in the global variable |packet_cur_s| and should
not exceed |packet_max_recursion|.
-*/
+@c
#define packet_max_recursion 100
typedef unsigned char packet_stack_index; /* an index into the stack */
@@ -48,8 +50,8 @@ static packet_stack_record packet_stack[packet_max_recursion];
static packet_stack_index packet_stack_ptr = 0; /* pointer into |packet_stack| */
-/* Some macros for processing character packets. */
-
+@ Some macros for processing character packets.
+@c
#define do_packet_byte() vf_packets[cur_packet_byte++]
#define packet_number(fw) { \
@@ -58,7 +60,7 @@ static packet_stack_index packet_stack_ptr = 0; /* pointer into |packet_stack| *
fw = fw*256 + do_packet_byte(); \
fw = fw*256 + do_packet_byte(); }
-#define packet_scaled(a,fs) { integer fw; \
+#define packet_scaled(a,fs) { int fw; \
fw = do_packet_byte(); \
if (fw>127) fw = fw - 256; \
fw = fw*256 + do_packet_byte(); \
@@ -67,11 +69,12 @@ static packet_stack_index packet_stack_ptr = 0; /* pointer into |packet_stack| *
a = store_scaled_f(fw, fs); }
-/* count the number of bytes in a command packet */
+@ count the number of bytes in a command packet
+@c
int vf_packet_bytes(charinfo * co)
{
- real_eight_bits *vf_packets;
- integer cur_packet_byte;
+ eight_bits *vf_packets;
+ int cur_packet_byte;
unsigned k;
int cmd;
@@ -98,7 +101,7 @@ int vf_packet_bytes(charinfo * co)
break;
case packet_special_code:
packet_number(k); /* +4 */
- cur_packet_byte += k;
+ cur_packet_byte = (cur_packet_byte + (int) k);
break;
case packet_image_code:
cur_packet_byte += 4;
@@ -106,61 +109,64 @@ int vf_packet_bytes(charinfo * co)
case packet_nop_code:
break;
default:
- pdf_error(maketexstring("vf"),
- maketexstring("invalid DVI command (1)"));
+ pdf_error("vf", "invalid DVI command (1)");
}
};
return (cur_packet_byte + 1);
}
-/* typeset the \.{DVI} commands in the
- character packet for character |c| in current font |f| */
-
-#if 0 /* unused */
-static char *packet_command_names[] = {
+@ typeset the \.{DVI} commands in the
+ character packet for character |c| in current font |f|
+@c
+const char *packet_command_names[] = {
"char", "font", "pop", "push", "special", "image",
"right", "down", "rule", "node", "nop", "end", NULL
};
-#endif
-void do_vf_packet(internal_font_number vf_f, integer c)
+void do_vf_packet(PDF pdf, internal_font_number vf_f, int c)
{
internal_font_number lf;
charinfo *co;
- scaledpos save_cur;
- real_eight_bits *vf_packets;
- integer cur_packet_byte;
- integer cmd, fs_f;
+ scaledpos cur = { 0, 0 }, size;
+ eight_bits *vf_packets;
+ int cur_packet_byte;
+ int cmd, fs_f;
scaled i;
unsigned k;
str_number s;
- packet_cur_s++;
- if (packet_cur_s >= packet_max_recursion)
- overflow_string("max level recursion of virtual fonts",
- packet_max_recursion);
- save_cur = cur;
+ posstructure localpos; /* the position structure local within this function */
+ posstructure *refpos; /* the list origin pos. on the page, provided by the caller */
lf = 0; /* for -Wall */
+ packet_cur_s++;
+ if (packet_cur_s >= packet_max_recursion)
+ overflow("max level recursion of virtual fonts", packet_max_recursion);
co = get_charinfo(vf_f, c);
vf_packets = get_charinfo_packets(co);
if (vf_packets == NULL) {
packet_cur_s--;
return;
}
+
+ refpos = pdf->posstruct;
+ pdf->posstruct = &localpos; /* use local structure for recursion */
+ localpos.pos = refpos->pos;
+ localpos.dir = dir_TLT; /* invariably for vf */
+
cur_packet_byte = 0;
fs_f = font_size(vf_f);
while ((cmd = vf_packets[cur_packet_byte]) != packet_end_code) {
cur_packet_byte++;
- /*
+#ifdef DEBUG
if (cmd>packet_end_code) {
fprintf(stdout, "do_vf_packet(%i,%i) command code = illegal \n", vf_f,c);
} else {
fprintf(stdout, "do_vf_packet(%i,%i) command code = %s\n",vf_f, c, packet_command_names[cmd]);
}
- */
+#endif
switch (cmd) {
case packet_font_code:
packet_number(lf);
@@ -177,26 +183,22 @@ void do_vf_packet(internal_font_number vf_f, integer c)
break;
case packet_char_code:
packet_number(k);
- if (!char_exists(lf, k)) {
- char_warning(lf, k);
+ if (!char_exists(lf, (int) k)) {
+ char_warning(lf, (int) k);
} else {
- if (has_packet(lf, k))
- do_vf_packet(lf, k);
- else {
- pos = synch_p_with_c(cur);
- pdf_place_glyph(lf, k);
- }
+ if (has_packet(lf, (int) k))
+ do_vf_packet(pdf, lf, (int) k);
+ else
+ pdf_place_glyph(pdf, lf, (int) k);
}
- cur.h = cur.h + char_width(lf, k);
+ cur.h = cur.h + char_width(lf, (int) k);
break;
case packet_rule_code:
- packet_scaled(rule_ht, fs_f);
- packet_scaled(rule_wd, fs_f);
- if ((rule_wd > 0) && (rule_ht > 0)) {
- pos = synch_p_with_c(cur);
- pdf_place_rule(pos.h, pos.v, rule_wd, rule_ht);
- }
- cur.h = cur.h + rule_wd;
+ packet_scaled(size.v, fs_f); /* height (where is depth?) */
+ packet_scaled(size.h, fs_f);
+ if (size.h > 0 && size.v > 0)
+ pdf_place_rule(pdf, 0, size); /* the 0 is unused */
+ cur.h = cur.h + size.h;
break;
case packet_right_code:
packet_scaled(i, fs_f);
@@ -208,48 +210,46 @@ void do_vf_packet(internal_font_number vf_f, integer c)
break;
case packet_special_code:
packet_number(k);
- string_room(k);
+ str_room((unsigned) k);
while (k > 0) {
k--;
- append_pool_char(do_packet_byte());
+ append_char(do_packet_byte());
}
s = make_string();
- literal(s, scan_special, false);
+ pdf_literal(pdf, s, scan_special, false);
flush_str(s);
break;
case packet_image_code:
packet_number(k);
- pos = synch_p_with_c(cur);
- vf_out_image(k);
+ vf_out_image(pdf, k);
break;
case packet_node_code:
packet_number(k);
- temp_ptr = k;
- pdf_hlist_out();
+ hlist_out(pdf, (halfword) k);
break;
case packet_nop_code:
break;
default:
- pdf_error(maketexstring("vf"),
- maketexstring("invalid DVI command (2)"));
+ pdf_error("vf", "invalid DVI command (2)");
}
- };
- cur = save_cur;
+ synch_pos_with_cur(&localpos, refpos, cur); /* trivial case, always TLT */
+ }
packet_cur_s--;
+ pdf->posstruct = refpos;
}
-
-integer *packet_local_fonts(internal_font_number f, integer * num)
+@ @c
+int *packet_local_fonts(internal_font_number f, int *num)
{
int c, cmd, cur_packet_byte, lf, k, l, i;
- integer localfonts[256] = { 0 };
- integer *lfs;
+ int localfonts[256] = { 0 };
+ int *lfs;
charinfo *co;
- real_eight_bits *vf_packets;
+ eight_bits *vf_packets;
k = 0;
for (c = font_bc(f); c <= font_ec(f); c++) {
- if (char_exists(f, c)) {
+ if (quick_char_exists(f, c)) {
co = get_charinfo(f, c);
vf_packets = get_charinfo_packets(co);
if (vf_packets == NULL)
@@ -291,33 +291,33 @@ integer *packet_local_fonts(internal_font_number f, integer * num)
cur_packet_byte += 4;
break;
default:
- pdf_error(maketexstring("vf"),
- maketexstring("invalid DVI command (3)"));
+ pdf_error("vf", "invalid DVI command (3)");
}
}
}
}
*num = k;
if (k > 0) {
- lfs = xmalloc(k * sizeof(integer));
- memcpy(lfs, localfonts, k * sizeof(integer));
+ lfs = xmalloc((unsigned) ((unsigned) k * sizeof(int)));
+ memcpy(lfs, localfonts, (size_t) ((unsigned) k * sizeof(int)));
return lfs;
}
return NULL;
}
+@ @c
void
-replace_packet_fonts(internal_font_number f, integer * old_fontid,
- integer * new_fontid, int count)
+replace_packet_fonts(internal_font_number f, int *old_fontid,
+ int *new_fontid, int count)
{
int c, cmd, cur_packet_byte, lf, k, l;
charinfo *co;
- real_eight_bits *vf_packets;
+ eight_bits *vf_packets;
k = 0;
for (c = font_bc(f); c <= font_ec(f); c++) {
- if (char_exists(f, c)) {
+ if (quick_char_exists(f, c)) {
co = get_charinfo(f, c);
vf_packets = get_charinfo_packets(co);
if (vf_packets == NULL)
@@ -335,13 +335,14 @@ replace_packet_fonts(internal_font_number f, integer * old_fontid,
}
if (l < count) {
k = new_fontid[l];
- vf_packets[(cur_packet_byte - 4)] =
- (k & 0xFF000000) >> 24;
- vf_packets[(cur_packet_byte - 3)] =
- (k & 0x00FF0000) >> 16;
- vf_packets[(cur_packet_byte - 2)] =
- (k & 0x0000FF00) >> 8;
- vf_packets[(cur_packet_byte - 1)] = (k & 0x000000FF);
+ vf_packets[(cur_packet_byte - 4)] = (eight_bits)
+ ((k & 0xFF000000) >> 24);
+ vf_packets[(cur_packet_byte - 3)] = (eight_bits)
+ ((k & 0x00FF0000) >> 16);
+ vf_packets[(cur_packet_byte - 2)] = (eight_bits)
+ ((k & 0x0000FF00) >> 8);
+ vf_packets[(cur_packet_byte - 1)] =
+ (eight_bits) (k & 0x000000FF);
}
break;
case packet_push_code:
@@ -366,8 +367,7 @@ replace_packet_fonts(internal_font_number f, integer * old_fontid,
cur_packet_byte += 4;
break;
default:
- pdf_error(maketexstring("vf"),
- maketexstring("invalid DVI command (4)"));
+ pdf_error("vf", "invalid DVI command (4)");
}
}
}
diff --git a/Build/source/texk/web2c/luatexdir/font/writecff.h b/Build/source/texk/web2c/luatexdir/font/writecff.h
index bec0add205b..266cc9d1f6d 100644
--- a/Build/source/texk/web2c/luatexdir/font/writecff.h
+++ b/Build/source/texk/web2c/luatexdir/font/writecff.h
@@ -19,7 +19,7 @@
You should have received a copy of the GNU General Public License along
with LuaTeX; if not, see <http://www.gnu.org/licenses/>. */
-/* $Id: writecff.h 2271 2009-04-12 23:42:21Z oneiros $ */
+/* $Id: writecff.h 3400 2010-01-27 16:10:42Z taco $ */
#ifndef _CFF_LIMITS_H_
# define _CFF_LIMITS_H_
@@ -340,5 +340,5 @@ extern long cs_copy_charstring(card8 * dest, long destlen,
extern cff_font *read_cff(unsigned char *buf, long buflength, int subf);
-extern void write_cff(cff_font * cff, fd_entry * fd);
-extern void write_cid_cff(cff_font * cffont, fd_entry * fd);
+extern void write_cff(PDF pdf, cff_font * cff, fd_entry * fd);
+extern void write_cid_cff(PDF pdf, cff_font * cffont, fd_entry * fd);
diff --git a/Build/source/texk/web2c/luatexdir/font/writecff.c b/Build/source/texk/web2c/luatexdir/font/writecff.w
index 82b52d96d7c..91d1f3c9af2 100644
--- a/Build/source/texk/web2c/luatexdir/font/writecff.c
+++ b/Build/source/texk/web2c/luatexdir/font/writecff.w
@@ -1,33 +1,36 @@
-/* writecff.c
-
- Copyright 2006-2008 Taco Hoekwater <taco@luatex.org>
+% writecff.w
- This file is part of LuaTeX.
+% Copyright 2006-2010 Taco Hoekwater <taco@@luatex.org>
- LuaTeX 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 2 of the License, or (at your
- option) any later version.
+% This file is part of LuaTeX.
- LuaTeX 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 Lesser General Public
- License for more details.
+% LuaTeX 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 2 of the License, or (at your
+% option) any later version.
- You should have received a copy of the GNU General Public License along
- with LuaTeX; if not, see <http://www.gnu.org/licenses/>. */
+% LuaTeX 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 Lesser General Public
+% License for more details.
+% You should have received a copy of the GNU General Public License along
+% with LuaTeX; if not, see <http://www.gnu.org/licenses/>. */
+
+@ @c
#include "ptexlib.h"
+#include "lua/luatex-api.h"
-#include "writecff.h"
+#include "font/writecff.h"
static const char _svn_version[] =
- "$Id: writecff.c 2448 2009-06-08 07:43:50Z taco $ "
- "$URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.40.6/source/texk/web2c/luatexdir/font/writecff.c $";
+ "$Id: writecff.w 3584 2010-04-02 17:45:55Z hhenkel $ "
+"$URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.60.0/source/texk/web2c/luatexdir/font/writecff.w $";
+@ @c
#define get_offset(s,n) get_unsigned(s, (n))
-#define get_card8(a) a->stream[a->offset++]
-#define get_card16(a) get_unsigned(a,2)
+#define get_card8(a) (card8)(a->stream[a->offset++])
+#define get_card16(a) (card16)(get_unsigned(a,2))
#undef b0
#undef b1
@@ -46,6 +49,7 @@ static unsigned long get_unsigned(cff_font * cff, int n)
return v;
}
+@ @c
#define CFF_ERROR pdftex_fail
#undef WARN
#define WARN pdftex_warn
@@ -147,7 +151,8 @@ const char *const cff_stdstr[CFF_STDSTR_MAX] = {
};
-/* Only read header part but not body */
+@ Only read header part but not body
+@c
cff_index *cff_get_index_header(cff_font * cff)
{
cff_index *idx;
@@ -161,7 +166,8 @@ cff_index *cff_get_index_header(cff_font * cff)
if (idx->offsize < 1 || idx->offsize > 4)
CFF_ERROR("invalid offsize data");
- idx->offset = xcalloc(count + 1, sizeof(l_offset));
+ idx->offset =
+ xmalloc((unsigned) (((unsigned) count + 1) * sizeof(l_offset)));
for (i = 0; i < count + 1; i++) {
(idx->offset)[i] = get_offset(cff, idx->offsize);
}
@@ -181,11 +187,12 @@ cff_index *cff_get_index_header(cff_font * cff)
+@ @c
cff_index *cff_get_index(cff_font * cff)
{
cff_index *idx;
card16 i, count;
- long length;
+ size_t length;
idx = xcalloc(1, sizeof(cff_index));
@@ -195,7 +202,8 @@ cff_index *cff_get_index(cff_font * cff)
if (idx->offsize < 1 || idx->offsize > 4)
CFF_ERROR("invalid offsize data");
- idx->offset = xcalloc((count + 1), sizeof(l_offset));
+ idx->offset =
+ xmalloc((unsigned) (((unsigned) count + 1) * sizeof(l_offset)));
for (i = 0; i < count + 1; i++) {
idx->offset[i] = get_offset(cff, idx->offsize);
}
@@ -203,9 +211,9 @@ cff_index *cff_get_index(cff_font * cff)
if (idx->offset[0] != 1)
CFF_ERROR("Invalid CFF Index offset data");
- length = idx->offset[count] - idx->offset[0];
+ length = (size_t) (idx->offset[count] - idx->offset[0]);
- idx->data = xcalloc(length, sizeof(card8));
+ idx->data = xmalloc((unsigned) length * sizeof(card8));
memcpy(idx->data, &cff->stream[cff->offset], length);
cff->offset += length;
@@ -218,6 +226,7 @@ cff_index *cff_get_index(cff_font * cff)
}
+@ @c
long cff_pack_index(cff_index * idx, card8 * dest, long destlen)
{
long len = 0;
@@ -237,8 +246,8 @@ long cff_pack_index(cff_index * idx, card8 * dest, long destlen)
if (destlen < len)
CFF_ERROR("Not enough space available...");
- *(dest++) = (idx->count >> 8) & 0xff;
- *(dest++) = idx->count & 0xff;
+ *(dest++) = (card8) ((idx->count >> 8) & 0xff);
+ *(dest++) = (card8) (idx->count & 0xff);
if (datalen < 0xffUL) {
idx->offsize = 1;
@@ -277,6 +286,7 @@ long cff_pack_index(cff_index * idx, card8 * dest, long destlen)
return len;
}
+@ @c
long cff_index_size(cff_index * idx)
{
if (idx->count > 0) {
@@ -292,12 +302,13 @@ long cff_index_size(cff_index * idx)
} else {
idx->offsize = 4;
}
- return (3 + (idx->offsize) * (idx->count + 1) + datalen);
+ return (3 + (idx->offsize) * (idx->count + 1) + (long) datalen);
} else {
return 2;
}
}
+@ @c
cff_index *cff_new_index(card16 count)
{
cff_index *idx;
@@ -307,7 +318,7 @@ cff_index *cff_new_index(card16 count)
idx->offsize = 0;
if (count > 0) {
- idx->offset = xcalloc(count + 1, sizeof(l_offset));
+ idx->offset = xcalloc((unsigned) (count + 1), sizeof(l_offset));
(idx->offset)[0] = 1;
} else {
idx->offset = NULL;
@@ -318,6 +329,7 @@ cff_index *cff_new_index(card16 count)
}
+@ @c
void cff_release_index(cff_index * idx)
{
if (idx) {
@@ -327,6 +339,7 @@ void cff_release_index(cff_index * idx)
}
}
+@ @c
void cff_release_dict(cff_dict * dict)
{
if (dict) {
@@ -342,6 +355,7 @@ void cff_release_dict(cff_dict * dict)
}
+@ @c
void cff_release_encoding(cff_encoding * encoding)
{
if (encoding) {
@@ -361,6 +375,7 @@ void cff_release_encoding(cff_encoding * encoding)
}
}
+@ @c
void cff_release_charsets(cff_charsets * charset)
{
if (charset) {
@@ -381,6 +396,7 @@ void cff_release_charsets(cff_charsets * charset)
}
}
+@ @c
void cff_release_fdselect(cff_fdselect * fdselect)
{
if (fdselect) {
@@ -394,13 +410,13 @@ void cff_release_fdselect(cff_fdselect * fdselect)
}
+@ @c
void cff_close(cff_font * cff)
{
card16 i;
if (cff) {
- if (cff->fontname)
- xfree(cff->fontname);
+ xfree(cff->fontname);
if (cff->name)
cff_release_index(cff->name);
if (cff->topdict)
@@ -446,6 +462,7 @@ void cff_close(cff_font * cff)
return;
}
+@ @c
char *cff_get_name(cff_font * cff)
{
char *fontname;
@@ -454,7 +471,7 @@ char *cff_get_name(cff_font * cff)
idx = cff->name;
len = idx->offset[cff->index + 1] - idx->offset[cff->index];
- fontname = xmalloc((len + 1) * sizeof(char));
+ fontname = xmalloc((unsigned) (len + 1) * sizeof(char));
memcpy(fontname, idx->data + idx->offset[cff->index] - 1, len);
fontname[len] = '\0';
@@ -462,6 +479,7 @@ char *cff_get_name(cff_font * cff)
}
+@ @c
long cff_set_name(cff_font * cff, char *name)
{
cff_index *idx;
@@ -478,10 +496,10 @@ long cff_set_name(cff_font * cff, char *name)
idx->offset = xmalloc(2 * sizeof(l_offset));
(idx->offset)[0] = 1;
(idx->offset)[1] = strlen(name) + 1;
- idx->data = xcalloc(strlen(name), sizeof(card8));
- memmove(idx->data, name, strlen(name)); /* no trailing '\0' */
+ idx->data = xmalloc((unsigned) strlen(name) * sizeof(card8));
+ memmove(idx->data, name, strlen(name)); /* no trailing |'\0'| */
- return 5 + strlen(name);
+ return (long) (5 + strlen(name));
}
long cff_put_header(cff_font * cff, card8 * dest, long destlen)
@@ -501,6 +519,7 @@ long cff_put_header(cff_font * cff, card8 * dest, long destlen)
return 4;
}
+@ @c
#define CFF_PARSE_OK 0
#define CFF_CFF_ERROR_PARSE_CFF_ERROR -1
#define CFF_CFF_ERROR_STACK_OVERFLOW -2
@@ -516,32 +535,33 @@ cff_dict *cff_new_dict(void)
dict = xcalloc(1, sizeof(cff_dict));
dict->max = DICT_ENTRY_MAX;
dict->count = 0;
- dict->entries = xcalloc(dict->max, sizeof(cff_dict_entry));
+ dict->entries = xcalloc((unsigned) dict->max, sizeof(cff_dict_entry));
return dict;
}
-/*
- * Operand stack:
- * only numbers are stored (as double)
- *
- * Operand types:
- *
- * number : double (integer or real)
- * boolean: stored as a number
- * SID : stored as a number
- * array : array of numbers
- * delta : array of numbers
- */
+@
+
+Operand stack:
+ only numbers are stored (as double)
+
+Operand types:
+number : double (integer or real)
+boolean: stored as a number
+SID : stored as a number
+array : array of numbers
+delta : array of numbers
+
+@c
#define CFF_DICT_STACK_LIMIT 64
static int stack_top = 0;
static double arg_stack[CFF_DICT_STACK_LIMIT];
-/*
- * CFF DICT encoding:
- * TODO: default values
- */
-
+@
+CFF DICT encoding:
+TODO: default values
+
+@c
#define CFF_LAST_DICT_OP1 22
#define CFF_LAST_DICT_OP2 39
#define CFF_LAST_DICT_OP (CFF_LAST_DICT_OP1 + CFF_LAST_DICT_OP2)
@@ -623,7 +643,8 @@ static struct {
"FDSelect", CFF_TYPE_OFFSET}, {
"FontName", CFF_TYPE_SID},};
-/* Parse DICT data */
+@ Parse DICT data
+@c
static double get_integer(card8 ** data, card8 * endptr, int *status)
{
long result = 0;
@@ -660,7 +681,8 @@ static double get_integer(card8 ** data, card8 * endptr, int *status)
return (double) result;
}
-/* Simply uses strtod */
+@ Simply uses strtod
+@c
static double get_real(card8 ** data, card8 * endptr, int *status)
{
double result = 0.0;
@@ -684,7 +706,7 @@ static double get_real(card8 ** data, card8 * endptr, int *status)
nibble = (**data >> 4) & 0x0f;
}
if (nibble >= 0x00 && nibble <= 0x09) {
- work_buffer[len++] = nibble + '0';
+ work_buffer[len++] = (char) (nibble + '0');
} else if (nibble == 0x0a) { /* . */
work_buffer[len++] = '.';
} else if (nibble == 0x0b || nibble == 0x0c) { /* E, E- */
@@ -721,11 +743,12 @@ static double get_real(card8 ** data, card8 * endptr, int *status)
return result;
}
-/* operators */
+@ operators
+@c
static void add_dict(cff_dict * dict,
card8 ** data, card8 * endptr, int *status)
{
- int id, argtype;
+ int id, argtype, t;
id = **data;
if (id == 0x0c) {
@@ -750,7 +773,9 @@ static void add_dict(cff_dict * dict,
dict->max += DICT_ENTRY_MAX;
/* not zeroed! */
dict->entries =
- xrealloc(dict->entries, dict->max * sizeof(cff_dict_entry));
+ xrealloc(dict->entries,
+ (unsigned) ((unsigned) dict->max *
+ sizeof(cff_dict_entry)));
}
(dict->entries)[dict->count].id = id;
@@ -771,15 +796,21 @@ static void add_dict(cff_dict * dict,
} else {
/* just ignore operator if there were no operands provided;
don't treat this as underflow (e.g. StemSnapV in TemporaLGCUni-Italic.otf) */
- if (stack_top > 0) {
+ if ((t = stack_top) > 0) {
(dict->entries)[dict->count].count = stack_top;
(dict->entries)[dict->count].values =
- xcalloc(stack_top, sizeof(double));
+ xmalloc((unsigned) ((unsigned) stack_top * sizeof(double)));
while (stack_top > 0) {
stack_top--;
(dict->entries)[dict->count].values[stack_top] =
arg_stack[stack_top];
}
+ if (t > 3 && strcmp(dict_operator[id].opname, "FontMatrix") == 0) {
+ /* reset FontMatrix to [0.001 * * 0.001 * *],
+ fix mantis bug \# 0000200 (acroread "feature") */
+ (dict->entries)[dict->count].values[0] = 0.001;
+ (dict->entries)[dict->count].values[3] = 0.001;
+ }
dict->count += 1;
}
}
@@ -789,11 +820,12 @@ static void add_dict(cff_dict * dict,
return;
}
-/*
- * All operands are treated as number or array of numbers.
- * Private: two numbers, size and offset
- * ROS : three numbers, SID, SID, and a number
- */
+
+@ All operands are treated as number or array of numbers.
+ Private: two numbers, size and offset
+ ROS : three numbers, SID, SID, and a number
+
+@c
cff_dict *cff_dict_unpack(card8 * data, card8 * endptr)
{
cff_dict *dict;
@@ -834,7 +866,7 @@ cff_dict *cff_dict_unpack(card8 * data, card8 * endptr)
return dict;
}
-
+@ @c
int cff_dict_known(cff_dict * dict, const char *key)
{
int i;
@@ -848,6 +880,7 @@ int cff_dict_known(cff_dict * dict, const char *key)
return 0;
}
+@ @c
double cff_dict_get(cff_dict * dict, const char *key, int idx)
{
double value = 0.0;
@@ -871,6 +904,7 @@ double cff_dict_get(cff_dict * dict, const char *key, int idx)
return value;
}
+@ @c
card8 cff_fdselect_lookup(cff_font * cff, card16 gid)
{
card8 fd = 0xff;
@@ -913,6 +947,7 @@ card8 cff_fdselect_lookup(cff_font * cff, card16 gid)
return fd;
}
+@ @c
long cff_read_subrs(cff_font * cff)
{
long len = 0;
@@ -945,7 +980,7 @@ long cff_read_subrs(cff_font * cff)
} else {
offset = (long) cff_dict_get(cff->fdarray[i], "Private", 1);
offset += (long) cff_dict_get(cff->private[i], "Subrs", 0);
- cff->offset = offset;
+ cff->offset = (l_offset) offset;
(cff->subrs)[i] = cff_get_index(cff);
len += cff_index_size((cff->subrs)[i]);
}
@@ -957,7 +992,7 @@ long cff_read_subrs(cff_font * cff)
} else {
offset = (long) cff_dict_get(cff->topdict, "Private", 1);
offset += (long) cff_dict_get(cff->private[0], "Subrs", 0);
- cff->offset = offset;
+ cff->offset = (l_offset) offset;
(cff->subrs)[0] = cff_get_index(cff);
len += cff_index_size((cff->subrs)[0]);
}
@@ -967,6 +1002,7 @@ long cff_read_subrs(cff_font * cff)
}
+@ @c
long cff_read_fdarray(cff_font * cff)
{
long len = 0;
@@ -982,13 +1018,13 @@ long cff_read_fdarray(cff_font * cff)
/* must exist */
offset = (long) cff_dict_get(cff->topdict, "FDArray", 0);
- cff->offset = offset;
+ cff->offset = (l_offset) offset;
idx = cff_get_index(cff);
cff->num_fds = (card8) idx->count;
- cff->fdarray = xcalloc(idx->count, sizeof(cff_dict *));
+ cff->fdarray = xmalloc((unsigned) (idx->count * sizeof(cff_dict *)));
for (i = 0; i < idx->count; i++) {
card8 *data = idx->data + (idx->offset)[i] - 1;
- size = (idx->offset)[i + 1] - (idx->offset)[i];
+ size = (long) ((idx->offset)[i + 1] - (idx->offset)[i]);
if (size > 0) {
(cff->fdarray)[i] = cff_dict_unpack(data, data + size);
} else {
@@ -1002,6 +1038,7 @@ long cff_read_fdarray(cff_font * cff)
}
+@ @c
long cff_read_private(cff_font * cff)
{
long len = 0;
@@ -1014,17 +1051,17 @@ long cff_read_private(cff_font * cff)
if (cff->fdarray == NULL)
cff_read_fdarray(cff);
- cff->private = xcalloc(cff->num_fds, sizeof(cff_dict *));
+ cff->private = xmalloc((unsigned) (cff->num_fds * sizeof(cff_dict *)));
for (i = 0; i < cff->num_fds; i++) {
if (cff->fdarray[i] != NULL &&
cff_dict_known(cff->fdarray[i], "Private") &&
(size = (long) cff_dict_get(cff->fdarray[i], "Private", 0))
> 0) {
offset = (long) cff_dict_get(cff->fdarray[i], "Private", 1);
- cff->offset = offset;
- data = xcalloc(size, sizeof(card8));
- memcpy(data, &cff->stream[cff->offset], size);
- cff->offset = size;
+ cff->offset = (l_offset) offset;
+ data = xmalloc((unsigned) size * sizeof(card8));
+ memcpy(data, &cff->stream[cff->offset], (size_t) size);
+ cff->offset = (l_offset) size;
(cff->private)[i] = cff_dict_unpack(data, data + size);
xfree(data);
len += size;
@@ -1034,14 +1071,14 @@ long cff_read_private(cff_font * cff)
}
} else {
cff->num_fds = 1;
- cff->private = xcalloc(1, sizeof(cff_dict *));
+ cff->private = xmalloc(sizeof(cff_dict *));
if (cff_dict_known(cff->topdict, "Private") &&
(size = (long) cff_dict_get(cff->topdict, "Private", 0)) > 0) {
offset = (long) cff_dict_get(cff->topdict, "Private", 1);
- cff->offset = offset;
- data = xcalloc(size, sizeof(card8));
- memcpy(data, &cff->stream[cff->offset], size);
- cff->offset = size;
+ cff->offset = (l_offset) offset;
+ data = xmalloc((unsigned) size * sizeof(card8));
+ memcpy(data, &cff->stream[cff->offset], (size_t) size);
+ cff->offset = (l_offset) size;
cff->private[0] = cff_dict_unpack(data, data + size);
xfree(data);
len += size;
@@ -1055,6 +1092,7 @@ long cff_read_private(cff_font * cff)
}
+@ @c
cff_font *read_cff(unsigned char *buf, long buflength, int n)
{
cff_font *cff;
@@ -1065,7 +1103,7 @@ cff_font *read_cff(unsigned char *buf, long buflength, int n)
cff = xcalloc(1, sizeof(cff_font));
cff->stream = buf;
- cff->stream_size = buflength;
+ cff->stream_size = (l_offset) buflength;
cff->index = n;
cff->header_major = get_card8(cff);
@@ -1133,7 +1171,7 @@ cff_font *read_cff(unsigned char *buf, long buflength, int n)
/* Number of glyphs */
offset = (long) cff_dict_get(cff->topdict, "CharStrings", 0);
- cff->offset = offset;
+ cff->offset = (l_offset) offset;
cff->num_glyphs = get_card16(cff);
/* Check for font type */
@@ -1160,11 +1198,10 @@ cff_font *read_cff(unsigned char *buf, long buflength, int n)
return cff;
}
-/* write a cff for opentype */
-
-
+@* write a cff for opentype.
-/* Pack DICT data */
+@ Pack DICT data
+@c
static long pack_integer(card8 * dest, long destlen, long value)
{
long len = 0;
@@ -1172,42 +1209,43 @@ static long pack_integer(card8 * dest, long destlen, long value)
if (value >= -107 && value <= 107) {
if (destlen < 1)
CFF_ERROR("Buffer overflow.");
- dest[0] = (value + 139) & 0xff;
+ dest[0] = (card8) ((value + 139) & 0xff);
len = 1;
} else if (value >= 108 && value <= 1131) {
if (destlen < 2)
CFF_ERROR("Buffer overflow.");
- value = 0xf700u + value - 108;
- dest[0] = (value >> 8) & 0xff;
- dest[1] = value & 0xff;
+ value = (long) 0xf700u + value - 108;
+ dest[0] = (card8) ((value >> 8) & 0xff);
+ dest[1] = (card8) (value & 0xff);
len = 2;
} else if (value >= -1131 && value <= -108) {
if (destlen < 2)
CFF_ERROR("Buffer overflow.");
- value = 0xfb00u - value - 108;
- dest[0] = (value >> 8) & 0xff;
- dest[1] = value & 0xff;
+ value = (long) 0xfb00u - value - 108;
+ dest[0] = (card8) ((value >> 8) & 0xff);
+ dest[1] = (card8) (value & 0xff);
len = 2;
} else if (value >= -32768 && value <= 32767) { /* shortint */
if (destlen < 3)
CFF_ERROR("Buffer overflow.");
dest[0] = 28;
- dest[1] = (value >> 8) & 0xff;
- dest[2] = value & 0xff;
+ dest[1] = (card8) ((value >> 8) & 0xff);
+ dest[2] = (card8) (value & 0xff);
len = 3;
} else { /* longint */
if (destlen < 5)
CFF_ERROR("Buffer overflow.");
dest[0] = 29;
- dest[1] = (value >> 24) & 0xff;
- dest[2] = (value >> 16) & 0xff;
- dest[3] = (value >> 8) & 0xff;
- dest[4] = value & 0xff;
+ dest[1] = (card8) ((value >> 24) & 0xff);
+ dest[2] = (card8) ((value >> 16) & 0xff);
+ dest[3] = (card8) ((value >> 8) & 0xff);
+ dest[4] = (card8) (value & 0xff);
len = 5;
}
return len;
}
+@ @c
static long pack_real(card8 * dest, long destlen, double value)
{
long e;
@@ -1251,7 +1289,7 @@ static long pack_real(card8 * dest, long destlen, double value)
} else if (work_buffer[i] == '.') {
ch = 0x0a;
} else if (work_buffer[i] >= '0' && work_buffer[i] <= '9') {
- ch = work_buffer[i] - '0';
+ ch = (unsigned char) (work_buffer[i] - '0');
} else {
CFF_ERROR("Invalid character.");
}
@@ -1260,29 +1298,29 @@ static long pack_real(card8 * dest, long destlen, double value)
CFF_ERROR("Buffer overflow.");
if (pos % 2) {
- dest[pos / 2] += ch;
+ dest[pos / 2] = (card8) (dest[pos / 2] + ch);
} else {
- dest[pos / 2] = (ch << 4);
+ dest[pos / 2] = (card8) (ch << 4);
}
pos++;
}
if (e > 0) {
if (pos % 2) {
- dest[pos / 2] += 0x0b;
+ dest[pos / 2] = (card8) (dest[pos / 2] + 0x0b);
} else {
if (destlen < pos / 2 + 1)
CFF_ERROR("Buffer overflow.");
- dest[pos / 2] = 0xb0;
+ dest[pos / 2] = (card8) (0xb0);
}
pos++;
} else if (e < 0) {
if (pos % 2) {
- dest[pos / 2] += 0x0c;
+ dest[pos / 2] = (card8) (dest[pos / 2] + 0x0c);
} else {
if (destlen < pos / 2 + 1)
CFF_ERROR("Buffer overflow.");
- dest[pos / 2] = 0xc0;
+ dest[pos / 2] = (card8) (0xc0);
}
e *= -1;
pos++;
@@ -1297,7 +1335,7 @@ static long pack_real(card8 * dest, long destlen, double value)
} else if (work_buffer[i] == '.') {
ch = 0x0a;
} else if (work_buffer[i] >= '0' && work_buffer[i] <= '9') {
- ch = work_buffer[i] - '0';
+ ch = (unsigned char) (work_buffer[i] - '0');
} else {
CFF_ERROR("Invalid character.");
}
@@ -1306,27 +1344,28 @@ static long pack_real(card8 * dest, long destlen, double value)
CFF_ERROR("Buffer overflow.");
if (pos % 2) {
- dest[pos / 2] += ch;
+ dest[pos / 2] = (card8) (dest[pos / 2] + ch);
} else {
- dest[pos / 2] = (ch << 4);
+ dest[pos / 2] = (card8) (ch << 4);
}
pos++;
}
}
if (pos % 2) {
- dest[pos / 2] += 0x0f;
+ dest[pos / 2] = (card8) (dest[pos / 2] + 0x0f);
pos++;
} else {
if (destlen < pos / 2 + 1)
CFF_ERROR("Buffer overflow.");
- dest[pos / 2] = 0xff;
+ dest[pos / 2] = (card8) (0xff);
pos += 2;
}
return pos / 2;
}
+@ @c
static long cff_dict_put_number(double value,
card8 * dest, long destlen, int type)
{
@@ -1342,10 +1381,10 @@ static long cff_dict_put_number(double value,
if (destlen < 5)
CFF_ERROR("Buffer overflow.");
dest[0] = 29;
- dest[1] = (lvalue >> 24) & 0xff;
- dest[2] = (lvalue >> 16) & 0xff;
- dest[3] = (lvalue >> 8) & 0xff;
- dest[4] = lvalue & 0xff;
+ dest[1] = (card8) ((lvalue >> 24) & 0xff);
+ dest[2] = (card8) ((lvalue >> 16) & 0xff);
+ dest[3] = (card8) ((lvalue >> 8) & 0xff);
+ dest[4] = (card8) (lvalue & 0xff);
len = 5;
} else if (value > CFF_INT_MAX || value < CFF_INT_MIN || (fabs(value - nearint) > 1.0e-5)) { /* real */
len = pack_real(dest, destlen, value);
@@ -1356,6 +1395,7 @@ static long cff_dict_put_number(double value,
return len;
}
+@ @c
static long put_dict_entry(cff_dict_entry * de, card8 * dest, long destlen)
{
long len = 0;
@@ -1376,12 +1416,12 @@ static long put_dict_entry(cff_dict_entry * de, card8 * dest, long destlen)
if (id >= 0 && id < CFF_LAST_DICT_OP1) {
if (len + 1 > destlen)
CFF_ERROR("Buffer overflow.");
- dest[len++] = id;
+ dest[len++] = (card8) id;
} else if (id >= 0 && id < CFF_LAST_DICT_OP) {
if (len + 2 > destlen)
CFF_ERROR("in cff_dict_pack(): Buffer overflow");
dest[len++] = 12;
- dest[len++] = id - CFF_LAST_DICT_OP1;
+ dest[len++] = (card8) (id - CFF_LAST_DICT_OP1);
} else {
CFF_ERROR("Invalid CFF DICT operator ID.");
}
@@ -1390,6 +1430,7 @@ static long put_dict_entry(cff_dict_entry * de, card8 * dest, long destlen)
return len;
}
+@ @c
long cff_dict_pack(cff_dict * dict, card8 * dest, long destlen)
{
long len = 0;
@@ -1411,6 +1452,7 @@ long cff_dict_pack(cff_dict * dict, card8 * dest, long destlen)
}
+@ @c
void cff_dict_add(cff_dict * dict, const char *key, int count)
{
int id, i;
@@ -1435,15 +1477,17 @@ void cff_dict_add(cff_dict * dict, const char *key, int count)
if (dict->count + 1 >= dict->max) {
dict->max += 8;
dict->entries =
- xrealloc(dict->entries, (dict->max) * sizeof(cff_dict_entry));
+ xrealloc(dict->entries,
+ (unsigned) ((unsigned) dict->max *
+ sizeof(cff_dict_entry)));
}
(dict->entries)[dict->count].id = id;
(dict->entries)[dict->count].key = dict_operator[id].opname;
(dict->entries)[dict->count].count = count;
if (count > 0) {
- (dict->entries)[dict->count].values = xcalloc(count, sizeof(double));
- memset((dict->entries)[dict->count].values, 0, sizeof(double) * count);
+ (dict->entries)[dict->count].values =
+ xcalloc((unsigned) count, sizeof(double));
} else {
(dict->entries)[dict->count].values = NULL;
}
@@ -1453,19 +1497,19 @@ void cff_dict_add(cff_dict * dict, const char *key, int count)
}
+@ @c
void cff_dict_remove(cff_dict * dict, const char *key)
{
int i;
for (i = 0; i < dict->count; i++) {
if (key && strcmp(key, (dict->entries)[i].key) == 0) {
(dict->entries)[i].count = 0;
- if ((dict->entries)[i].values)
- xfree((dict->entries)[i].values);
- (dict->entries)[i].values = NULL;
+ xfree((dict->entries)[i].values);
}
}
}
+@ @c
void cff_dict_set(cff_dict * dict, const char *key, int idx, double value)
{
int i;
@@ -1487,23 +1531,24 @@ void cff_dict_set(cff_dict * dict, const char *key, int idx, double value)
}
-/* Strings */
+@ Strings
+@c
char *cff_get_string(cff_font * cff, s_SID id)
{
char *result = NULL;
- long len;
+ size_t len;
if (id < CFF_STDSTR_MAX) {
len = strlen(cff_stdstr[id]);
- result = xcalloc(len + 1, sizeof(char));
+ result = xmalloc((unsigned) (len + 1) * sizeof(char));
memcpy(result, cff_stdstr[id], len);
result[len] = '\0';
} else if (cff && cff->string) {
cff_index *strings = cff->string;
- id -= CFF_STDSTR_MAX;
+ id = (s_SID) (id - CFF_STDSTR_MAX);
if (id < strings->count) {
len = (strings->offset)[id + 1] - (strings->offset)[id];
- result = xcalloc(len + 1, sizeof(char));
+ result = xmalloc((unsigned) (len + 1) * sizeof(char));
memmove(result, strings->data + (strings->offset)[id] - 1, len);
result[len] = '\0';
}
@@ -1512,6 +1557,7 @@ char *cff_get_string(cff_font * cff, s_SID id)
return result;
}
+@ @c
long cff_get_sid(cff_font * cff, const char *str)
{
card16 i;
@@ -1538,6 +1584,7 @@ long cff_get_sid(cff_font * cff, const char *str)
}
+@ @c
void cff_update_string(cff_font * cff)
{
if (cff == NULL)
@@ -1550,6 +1597,7 @@ void cff_update_string(cff_font * cff)
}
+@ @c
s_SID cff_add_string(cff_font * cff, const char *str)
{
card16 idx;
@@ -1568,7 +1616,7 @@ s_SID cff_add_string(cff_font * cff, const char *str)
offset = strings->offset[idx];
if (size == strlen(str) &&
!memcmp(strings->data + offset - 1, str, strlen(str)))
- return (idx + CFF_STDSTR_MAX);
+ return (s_SID) (idx + CFF_STDSTR_MAX);
}
for (idx = 0; idx < CFF_STDSTR_MAX; idx++) {
@@ -1577,20 +1625,24 @@ s_SID cff_add_string(cff_font * cff, const char *str)
}
offset = (strings->count > 0) ? strings->offset[strings->count] : 1;
strings->offset =
- xrealloc(strings->offset, (strings->count + 2) * sizeof(l_offset));
+ xrealloc(strings->offset,
+ (unsigned) (((unsigned) strings->count +
+ 2) * sizeof(l_offset)));
if (strings->count == 0)
strings->offset[0] = 1;
idx = strings->count;
- strings->count += 1;
+ strings->count = (card16) (strings->count + 1);
strings->offset[strings->count] = offset + strlen(str);
strings->data =
- xrealloc(strings->data, (offset + strlen(str) - 1) * sizeof(card8));
+ xrealloc(strings->data,
+ (unsigned) ((offset + strlen(str) - 1) * sizeof(card8)));
memcpy(strings->data + offset - 1, str, strlen(str));
- return (idx + CFF_STDSTR_MAX);
+ return (s_SID) (idx + CFF_STDSTR_MAX);
}
+@ @c
void cff_dict_update(cff_dict * dict, cff_font * cff)
{
int i;
@@ -1603,14 +1655,14 @@ void cff_dict_update(cff_dict * dict, cff_font * cff)
id = (dict->entries)[i].id;
if (dict_operator[id].argtype == CFF_TYPE_SID) {
- str = cff_get_string(cff, (dict->entries)[i].values[0]);
+ str = cff_get_string(cff, (s_SID) (dict->entries)[i].values[0]);
(dict->entries)[i].values[0] = cff_add_string(cff, str);
xfree(str);
} else if (dict_operator[id].argtype == CFF_TYPE_ROS) {
- str = cff_get_string(cff, (dict->entries)[i].values[0]);
+ str = cff_get_string(cff, (s_SID) (dict->entries)[i].values[0]);
(dict->entries)[i].values[0] = cff_add_string(cff, str);
xfree(str);
- str = cff_get_string(cff, (dict->entries)[i].values[1]);
+ str = cff_get_string(cff, (s_SID) (dict->entries)[i].values[1]);
(dict->entries)[i].values[1] = cff_add_string(cff, str);
xfree(str);
}
@@ -1619,8 +1671,8 @@ void cff_dict_update(cff_dict * dict, cff_font * cff)
}
}
-/* charsets */
-
+@ charsets
+@c
long cff_read_charsets(cff_font * cff)
{
cff_charsets *charset;
@@ -1652,19 +1704,20 @@ long cff_read_charsets(cff_font * cff)
return 0;
}
- cff->offset = offset;
+ cff->offset = (l_offset) offset;
cff->charsets = charset = xcalloc(1, sizeof(cff_charsets));
charset->format = get_card8(cff);
charset->num_entries = 0;
- count = cff->num_glyphs - 1;
+ count = (card16) (cff->num_glyphs - 1);
length = 1;
/* Not sure. Not well documented. */
switch (charset->format) {
case 0:
- charset->num_entries = cff->num_glyphs - 1; /* no .notdef */
- charset->data.glyphs = xcalloc(charset->num_entries, sizeof(s_SID));
+ charset->num_entries = (card16) (cff->num_glyphs - 1); /* no .notdef */
+ charset->data.glyphs =
+ xmalloc((unsigned) (charset->num_entries * sizeof(s_SID)));
length += (charset->num_entries) * 2;
for (i = 0; i < (charset->num_entries); i++) {
charset->data.glyphs[i] = get_card16(cff);
@@ -1677,11 +1730,12 @@ long cff_read_charsets(cff_font * cff)
while (count > 0 && charset->num_entries < cff->num_glyphs) {
ranges =
xrealloc(ranges,
- (charset->num_entries + 1) * sizeof(cff_range1));
+ (unsigned) (((unsigned) charset->num_entries +
+ 1) * sizeof(cff_range1)));
ranges[charset->num_entries].first = get_card16(cff);
ranges[charset->num_entries].n_left = get_card8(cff);
- count -= ranges[charset->num_entries].n_left + 1; /* no-overrap */
- charset->num_entries += 1;
+ count = (card16) (count - ranges[charset->num_entries].n_left + 1); /* no-overrap */
+ charset->num_entries++;
charset->data.range1 = ranges;
}
length += (charset->num_entries) * 3;
@@ -1693,11 +1747,12 @@ long cff_read_charsets(cff_font * cff)
while (count > 0 && charset->num_entries < cff->num_glyphs) {
ranges =
xrealloc(ranges,
- (charset->num_entries + 1) * sizeof(cff_range2));
+ (unsigned) (((unsigned) charset->num_entries +
+ 1) * sizeof(cff_range2)));
ranges[charset->num_entries].first = get_card16(cff);
ranges[charset->num_entries].n_left = get_card16(cff);
- count -= ranges[charset->num_entries].n_left + 1; /* non-overrapping */
- charset->num_entries += 1;
+ count = (card16) (count - (ranges[charset->num_entries].n_left + 1)); /* non-overrapping */
+ charset->num_entries++;
}
charset->data.range2 = ranges;
length += (charset->num_entries) * 4;
@@ -1709,12 +1764,15 @@ long cff_read_charsets(cff_font * cff)
break;
}
- if (count > 0)
+ if (count > 0) {
+ fprintf(stdout, "count=%d\n", count);
CFF_ERROR("Charset data possibly broken");
+ }
return length;
}
+@ @c
long cff_pack_charsets(cff_font * cff, card8 * dest, long destlen)
{
long len = 0;
@@ -1736,8 +1794,8 @@ long cff_pack_charsets(cff_font * cff, card8 * dest, long destlen)
CFF_ERROR("in cff_pack_charsets(): Buffer overflow");
for (i = 0; i < (charset->num_entries); i++) {
s_SID sid = (charset->data).glyphs[i]; /* or CID */
- dest[len++] = (sid >> 8) & 0xff;
- dest[len++] = sid & 0xff;
+ dest[len++] = (card8) ((sid >> 8) & 0xff);
+ dest[len++] = (card8) (sid & 0xff);
}
break;
case 1:
@@ -1745,9 +1803,10 @@ long cff_pack_charsets(cff_font * cff, card8 * dest, long destlen)
if (destlen < len + (charset->num_entries) * 3)
CFF_ERROR("in cff_pack_charsets(): Buffer overflow");
for (i = 0; i < (charset->num_entries); i++) {
- dest[len++] = ((charset->data).range1[i].first >> 8) & 0xff;
- dest[len++] = (charset->data).range1[i].first & 0xff;
- dest[len++] = (charset->data).range1[i].n_left;
+ dest[len++] =
+ (card8) (((charset->data).range1[i].first >> 8) & 0xff);
+ dest[len++] = (card8) ((charset->data).range1[i].first & 0xff);
+ dest[len++] = (card8) ((charset->data).range1[i].n_left);
}
}
break;
@@ -1756,10 +1815,12 @@ long cff_pack_charsets(cff_font * cff, card8 * dest, long destlen)
if (destlen < len + (charset->num_entries) * 4)
CFF_ERROR("in cff_pack_charsets(): Buffer overflow");
for (i = 0; i < (charset->num_entries); i++) {
- dest[len++] = ((charset->data).range2[i].first >> 8) & 0xff;
- dest[len++] = (charset->data).range2[i].first & 0xff;
- dest[len++] = ((charset->data).range2[i].n_left >> 8) & 0xff;
- dest[len++] = (charset->data).range2[i].n_left & 0xff;
+ dest[len++] =
+ (card8) (((charset->data).range2[i].first >> 8) & 0xff);
+ dest[len++] = (card8) ((charset->data).range2[i].first & 0xff);
+ dest[len++] =
+ (card8) (((charset->data).range2[i].n_left >> 8) & 0xff);
+ dest[len++] = (card8) ((charset->data).range2[i].n_left & 0xff);
}
}
break;
@@ -1773,33 +1834,33 @@ long cff_pack_charsets(cff_font * cff, card8 * dest, long destlen)
-/*
- * Type 2 Charstring support:
- * Decode and encode Type 2 charstring
- *
- * All local/global subroutine calls in a given charstring is replace by the
- * content of subroutine charstrings. We do this because some PostScript RIP
- * may have problems with sparse subroutine array. Workaround for this is to
- * re-order subroutine array so that no gap appears in the subroutine array,
- * or put dummy charstrings that contains only `return' in the gap. However,
- * re-ordering of subroutine is rather difficult for Type 2 charstrings due
- * to the bias which depends on the total number of subroutines. Replacing
- * callgsubr/callsubr calls with the content of the corresponding subroutine
- * charstring may be more efficient than putting dummy subroutines in the
- * case of subsetted font. Adobe distiller seems doing same thing.
- *
- * And also note that subroutine numbers within subroutines can depend on the
- * content of operand stack as follows:
- *
- * ... l m callsubr << subr #(m+bias): n add callsubr >> ...
- *
- * I've not implemented the `random' operator which generates a pseudo-random
- * number in the range (0, 1] and push them into argument stack.
- * How pseudo-random sequences are generated is not documented in the Type 2
- * charstring spec..
- */
+@* Type 2 Charstring support.
+
+Decode and encode Type 2 charstring
+All local/global subroutine calls in a given charstring is replace by the
+content of subroutine charstrings. We do this because some PostScript RIP
+may have problems with sparse subroutine array. Workaround for this is to
+re-order subroutine array so that no gap appears in the subroutine array,
+or put dummy charstrings that contains only `return' in the gap. However,
+re-ordering of subroutine is rather difficult for Type 2 charstrings due
+to the bias which depends on the total number of subroutines. Replacing
+callgsubr/callsubr calls with the content of the corresponding subroutine
+charstring may be more efficient than putting dummy subroutines in the
+case of subsetted font. Adobe distiller seems doing same thing.
+And also note that subroutine numbers within subroutines can depend on the
+content of operand stack as follows:
+
+\.{ ... l m callsubr << subr \#(m+bias): n add callsubr >> ...}
+
+I've not implemented the `random' operator which generates a pseudo-random
+number in the range (0, 1] and push them into argument stack.
+How pseudo-random sequences are generated is not documented in the Type 2
+charstring spec..
+
+
+@c
#define CS_TYPE2_DEBUG_STR "Type2 Charstring Parser"
#define CS_TYPE2_DEBUG 5
@@ -1829,29 +1890,29 @@ static int cs2_nest = 0;
static int have_width = 0;
static double width = 0.0;
-/*
- * Standard Encoding Accented Characters:
- * Optional four arguments for endchar. See, CFF spec., p.35.
- * This is obsolete feature and is no longer supported.
- */
+@
+ Standard Encoding Accented Characters:
+ Optional four arguments for endchar. See, CFF spec., p.35.
+ This is obsolete feature and is no longer supported.
+@c
#if 0
/* adx ady bchar achar endchar */
static double seac[4] = { 0.0, 0.0, 0.0, 0.0 };
#endif
-/* Operand stack and Transient array */
+@ Operand stack and Transient array
+@c
static int cs2_stack_top = 0;
static double cs2_arg_stack[CS_ARG_STACK_MAX];
static double trn_array[CS_TRANS_ARRAY_MAX];
-/*
- * Type 2 CharString encoding
- */
+@ Type 2 CharString encoding
+@c
/*
- * 1-byte CharString operaotrs:
- * cs_escape is first byte of two-byte operator
- */
+ 1-byte CharString operaotrs:
+ |cs_escape| is first byte of two-byte operator
+*/
/* RESERVED 0 */
#define cs_hstem 1
@@ -1862,11 +1923,11 @@ static double trn_array[CS_TRANS_ARRAY_MAX];
#define cs_hlineto 6
#define cs_vlineto 7
#define cs_rrcurveto 8
-/* cs_closepath 9 : TYPE1 */
+/* |cs_closepath| 9 : TYPE1 */
#define cs_callsubr 10
#define cs_return 11
#define cs_escape 12
-/* cs_hsbw 13 : TYPE1 */
+/* |cs_hsbw| 13 : TYPE1 */
#define cs_endchar 14
/* RESERVED 15 */
/* RESERVED 16 */
@@ -1887,18 +1948,18 @@ static double trn_array[CS_TRANS_ARRAY_MAX];
#define cs_hvcurveto 31
/*
- * 2-byte CharString operaotrs:
- * "dotsection" is obsoleted in Type 2 charstring.
+ 2-byte CharString operaotrs:
+ "dotsection" is obsoleted in Type 2 charstring.
*/
#define cs_dotsection 0
-/* cs_vstem3 1 : TYPE1 */
-/* cs_hstem3 2 : TYPE1 */
+/* |cs_vstem3| 1 : TYPE1 */
+/* |cs_hstem3| 2 : TYPE1 */
#define cs_and 3
#define cs_or 4
#define cs_not 5
-/* cs_seac 6 : TYPE1 */
-/* cs_sbw 7 : TYPE1 */
+/* |cs_seac| 6 : TYPE1 */
+/* |cs_sbw| 7 : TYPE1 */
/* RESERVED 8 */
#define cs_abs 9
#define cs_add 10
@@ -1907,8 +1968,8 @@ static double trn_array[CS_TRANS_ARRAY_MAX];
/* RESERVED 13 */
#define cs_neg 14
#define cs_eq 15
-/* cs_callothersubr 16 : TYPE1 */
-/* cs_pop 17 : TYPE1 */
+/* |cs_callothersubr| 16 : TYPE1 */
+/* |cs_pop| 17 : TYPE1 */
#define cs_drop 18
/* RESERVED 19 */
#define cs_put 20
@@ -1922,7 +1983,7 @@ static double trn_array[CS_TRANS_ARRAY_MAX];
#define cs_exch 28
#define cs_index 29
#define cs_roll 30
-/* cs_setcurrentpoint 31 : TYPE1 */
+/* |cs_setcurrentpoint| 31 : TYPE1 */
/* RESERVED 32 */
/* RESERVED 33 */
#define cs_hflex 34
@@ -1930,9 +1991,9 @@ static double trn_array[CS_TRANS_ARRAY_MAX];
#define cs_hflex1 36
#define cs_flex1 37
-/*
- * clear_stack() put all operands sotred in operand stack to dest.
- */
+@
+|clear_stack()| put all operands sotred in operand stack to dest.
+@c
static void clear_stack(card8 ** dest, card8 * limit)
{
int i;
@@ -1945,39 +2006,39 @@ static void clear_stack(card8 ** dest, card8 * limit)
ivalue = (long) floor(value + 0.5);
if (value >= 0x8000L || value <= (-0x8000L - 1)) {
/*
- * This number cannot be represented as a single operand.
- * We must use `a b mul ...' or `a c div' to represent large values.
+ This number cannot be represented as a single operand.
+ We must use `a b mul ...' or `a c div' to represent large values.
*/
CFF_ERROR("Argument value too large. (This is bug)");
- } else if (fabs(value - ivalue) > 3.0e-5) {
+ } else if (fabs(value - (double) ivalue) > 3.0e-5) {
/* 16.16-bit signed fixed value */
DST_NEED(limit, *dest + 5);
*(*dest)++ = 255;
ivalue = (long) floor(value); /* mantissa */
- *(*dest)++ = (ivalue >> 8) & 0xff;
- *(*dest)++ = ivalue & 0xff;
- ivalue = (long) ((value - ivalue) * 0x10000l); /* fraction */
- *(*dest)++ = (ivalue >> 8) & 0xff;
- *(*dest)++ = ivalue & 0xff;
+ *(*dest)++ = (card8) ((ivalue >> 8) & 0xff);
+ *(*dest)++ = (card8) (ivalue & 0xff);
+ ivalue = (long) ((value - (double) ivalue) * 0x10000l); /* fraction */
+ *(*dest)++ = (card8) ((ivalue >> 8) & 0xff);
+ *(*dest)++ = (card8) (ivalue & 0xff);
/* Everything else are integers. */
} else if (ivalue >= -107 && ivalue <= 107) {
DST_NEED(limit, *dest + 1);
- *(*dest)++ = ivalue + 139;
+ *(*dest)++ = (card8) (ivalue + 139);
} else if (ivalue >= 108 && ivalue <= 1131) {
DST_NEED(limit, *dest + 2);
- ivalue = 0xf700u + ivalue - 108;
- *(*dest)++ = (ivalue >> 8) & 0xff;
- *(*dest)++ = ivalue & 0xff;
+ ivalue = (long) 0xf700u + ivalue - 108;
+ *(*dest)++ = (card8) ((ivalue >> 8) & 0xff);
+ *(*dest)++ = (card8) (ivalue & 0xff);
} else if (ivalue >= -1131 && ivalue <= -108) {
DST_NEED(limit, *dest + 2);
- ivalue = 0xfb00u - ivalue - 108;
- *(*dest)++ = (ivalue >> 8) & 0xff;
- *(*dest)++ = ivalue & 0xff;
+ ivalue = (long) 0xfb00u - ivalue - 108;
+ *(*dest)++ = (card8) ((ivalue >> 8) & 0xff);
+ *(*dest)++ = (card8) (ivalue & 0xff);
} else if (ivalue >= -32768 && ivalue <= 32767) { /* shortint */
DST_NEED(limit, *dest + 3);
*(*dest)++ = 28;
- *(*dest)++ = (ivalue >> 8) & 0xff;
- *(*dest)++ = (ivalue) & 0xff;
+ *(*dest)++ = (card8) ((ivalue >> 8) & 0xff);
+ *(*dest)++ = (card8) ((ivalue) & 0xff);
} else { /* Shouldn't come here */
CFF_ERROR("Unexpected error.");
}
@@ -1988,16 +2049,16 @@ static void clear_stack(card8 ** dest, card8 * limit)
return;
}
-/*
- * Single byte operators:
- * Path construction, Operator for finishing a path, Hint operators.
- *
- * phase:
- * 0: inital state
- * 1: hint declaration, first stack-clearing operator appeared
- * 2: in path construction
- */
+@
+ Single byte operators:
+ Path construction, Operator for finishing a path, Hint operators.
+
+ phase:
+ \item 0: inital state
+ \item 1: hint declaration, first stack-clearing operator appeared
+ \item 2: in path construction
+@c
static void
do_operator1(card8 ** dest, card8 * limit, card8 ** data, card8 * endptr)
{
@@ -2037,7 +2098,7 @@ do_operator1(card8 ** dest, card8 * limit, card8 ** data, card8 * endptr)
int masklen = (num_stems + 7) / 8;
DST_NEED(limit, *dest + masklen);
SRC_NEED(endptr, *data + masklen);
- memmove(*dest, *data, masklen);
+ memmove(*dest, *data, (size_t) masklen);
*data += masklen;
*dest += masklen;
}
@@ -2117,13 +2178,14 @@ do_operator1(card8 ** dest, card8 * limit, card8 ** data, card8 * endptr)
return;
}
-/*
- * Double byte operators:
- * Flex, arithmetic, conditional, and storage operators.
- *
- * Following operators are not supported:
- * random: How random ?
- */
+@
+ Double byte operators:
+ Flex, arithmetic, conditional, and storage operators.
+
+ Following operators are not supported:
+ random: How random ?
+
+@c
static void
do_operator2(card8 ** dest, card8 * limit, card8 ** data, card8 * endptr)
{
@@ -2331,10 +2393,10 @@ do_operator2(card8 ** dest, card8 * limit, card8 ** data, card8 * endptr)
return;
}
-/*
- * integer:
- * exactly the same as the DICT encoding (except 29)
- */
+@
+ integer:
+ exactly the same as the DICT encoding (except 29)
+@c
static void cs2_get_integer(card8 ** data, card8 * endptr)
{
long result = 0;
@@ -2373,9 +2435,9 @@ static void cs2_get_integer(card8 ** data, card8 * endptr)
return;
}
-/*
- * Signed 16.16-bits fixed number for Type 2 charstring encoding
- */
+@
+Signed 16.16-bits fixed number for Type 2 charstring encoding
+@c
static void get_fixed(card8 ** data, card8 * endptr)
{
long ivalue;
@@ -2386,7 +2448,7 @@ static void get_fixed(card8 ** data, card8 * endptr)
SRC_NEED(endptr, *data + 4);
ivalue = *(*data) * 0x100 + *(*data + 1);
- rvalue = (ivalue > 0x7fffL) ? (ivalue - 0x10000L) : ivalue;
+ rvalue = (double) ((ivalue > 0x7fffL) ? (ivalue - 0x10000L) : ivalue);
ivalue = *(*data + 2) * 0x100 + *(*data + 3);
rvalue += ((double) ivalue) / 0x10000L;
@@ -2397,15 +2459,16 @@ static void get_fixed(card8 ** data, card8 * endptr)
return;
}
-/*
- * Subroutines:
- * The bias for subroutine number is introduced in type 2 charstrings.
- *
- * subr: set to a pointer to the subroutine charstring.
- * len: set to the length of subroutine charstring.
- * subr_idx: CFF INDEX data that contains subroutines.
- * id: biased subroutine number.
- */
+@
+ Subroutines:
+ The bias for subroutine number is introduced in type 2 charstrings.
+
+ subr: set to a pointer to the subroutine charstring.
+ len: set to the length of subroutine charstring.
+ |subr_idx|: CFF INDEX data that contains subroutines.
+ id: biased subroutine number.
+
+@c
static void get_subr(card8 ** subr, long *len, cff_index * subr_idx, long id)
{
card16 count;
@@ -2429,19 +2492,19 @@ static void get_subr(card8 ** subr, long *len, cff_index * subr_idx, long id)
CFF_ERROR("%s: Invalid Subr index: %ld (max=%u)", CS_TYPE2_DEBUG_STR,
id, count);
- *len = (subr_idx->offset)[id + 1] - (subr_idx->offset)[id];
+ *len = (long) ((subr_idx->offset)[id + 1] - (subr_idx->offset)[id]);
*subr = subr_idx->data + (subr_idx->offset)[id] - 1;
return;
}
-/*
- * NOTE:
- * The Type 2 interpretation of a number encoded in five-bytes (those with
- * an initial byte value of 255) differs from how it is interpreted in the
- * Type 1 format.
- */
+@ NOTE:
+ The Type 2 interpretation of a number encoded in five-bytes (those with
+ an initial byte value of 255) differs from how it is interpreted in the
+ Type 1 format.
+
+@c
static void
do_charstring(card8 ** dest, card8 * limit,
card8 ** data, card8 * endptr,
@@ -2514,6 +2577,7 @@ do_charstring(card8 ** dest, card8 * limit,
return;
}
+@ @c
static void cs_parse_init(void)
{
status = CS_PARSE_OK;
@@ -2523,9 +2587,9 @@ static void cs_parse_init(void)
cs2_stack_top = 0;
}
-/*
- * Not just copying...
- */
+
+@ Not just copying...
+@c
long
cs_copy_charstring(card8 * dst, long dstlen,
card8 * src, long srclen,
@@ -2554,13 +2618,13 @@ cs_copy_charstring(card8 * dst, long dstlen,
return (long) (dst - save);
}
-/* encodings */
+@* encodings.
-/*
- * Encoding and Charset
- *
- * Encoding and Charset arrays always begin with GID = 1.
- */
+@ Encoding and Charset
+
+Encoding and Charset arrays always begin with GID = 1.
+
+@c
long cff_read_encoding(cff_font * cff)
{
cff_encoding *encoding;
@@ -2588,7 +2652,7 @@ long cff_read_encoding(cff_font * cff)
return 0;
}
- cff->offset = offset;
+ cff->offset = (l_offset) offset;
cff->encoding = encoding = xcalloc(1, sizeof(cff_encoding));
encoding->format = get_card8(cff);
length = 1;
@@ -2596,7 +2660,7 @@ long cff_read_encoding(cff_font * cff)
switch (encoding->format & (~0x80)) {
case 0:
encoding->num_entries = get_card8(cff);
- (encoding->data).codes = xcalloc(encoding->num_entries, sizeof(card8));
+ (encoding->data).codes = xmalloc(encoding->num_entries * sizeof(card8));
for (i = 0; i < (encoding->num_entries); i++) {
(encoding->data).codes[i] = get_card8(cff);
}
@@ -2639,6 +2703,7 @@ long cff_read_encoding(cff_font * cff)
return length;
}
+@ @c
long cff_pack_encoding(cff_font * cff, card8 * dest, long destlen)
{
long len = 0;
@@ -2668,8 +2733,8 @@ long cff_pack_encoding(cff_font * cff, card8 * dest, long destlen)
if (destlen < len + (encoding->num_entries) * 2)
CFF_ERROR("in cff_pack_encoding(): Buffer overflow");
for (i = 0; i < (encoding->num_entries); i++) {
- dest[len++] = (encoding->data).range1[i].first & 0xff;
- dest[len++] = (encoding->data).range1[i].n_left;
+ dest[len++] = (card8) ((encoding->data).range1[i].first & 0xff);
+ dest[len++] = (card8) ((encoding->data).range1[i].n_left);
}
}
break;
@@ -2683,16 +2748,17 @@ long cff_pack_encoding(cff_font * cff, card8 * dest, long destlen)
CFF_ERROR("in cff_pack_encoding(): Buffer overflow");
dest[len++] = encoding->num_supps;
for (i = 0; i < (encoding->num_supps); i++) {
- dest[len++] = (encoding->supp)[i].code;
- dest[len++] = ((encoding->supp)[i].glyph >> 8) & 0xff;
- dest[len++] = (encoding->supp)[i].glyph & 0xff;
+ dest[len++] = (card8) ((encoding->supp)[i].code);
+ dest[len++] = (card8) (((encoding->supp)[i].glyph >> 8) & 0xff);
+ dest[len++] = (card8) ((encoding->supp)[i].glyph & 0xff);
}
}
return len;
}
-/* CID-Keyed font specific */
+@ CID-Keyed font specific
+@c
long cff_read_fdselect(cff_font * cff)
{
cff_fdselect *fdsel;
@@ -2706,7 +2772,7 @@ long cff_read_fdselect(cff_font * cff)
return 0;
offset = (long) cff_dict_get(cff->topdict, "FDSelect", 0);
- cff->offset = offset;
+ cff->offset = (l_offset) offset;
cff->fdselect = fdsel = xcalloc(1, sizeof(cff_fdselect));
fdsel->format = get_card8(cff);
@@ -2715,7 +2781,7 @@ long cff_read_fdselect(cff_font * cff)
switch (fdsel->format) {
case 0:
fdsel->num_entries = cff->num_glyphs;
- (fdsel->data).fds = xcalloc(fdsel->num_entries, sizeof(card8));
+ (fdsel->data).fds = xmalloc(fdsel->num_entries * sizeof(card8));
for (i = 0; i < (fdsel->num_entries); i++) {
(fdsel->data).fds[i] = get_card8(cff);
}
@@ -2748,6 +2814,7 @@ long cff_read_fdselect(cff_font * cff)
}
+@ @c
long cff_pack_fdselect(cff_font * cff, card8 * dest, long destlen)
{
cff_fdselect *fdsel;
@@ -2781,16 +2848,17 @@ long cff_pack_fdselect(cff_font * cff, card8 * dest, long destlen)
for (i = 0; i < (fdsel->num_entries); i++) {
if (destlen < len + 3)
CFF_ERROR("in cff_pack_fdselect(): Buffer overflow");
- dest[len++] = ((fdsel->data).ranges[i].first >> 8) & 0xff;
- dest[len++] = (fdsel->data).ranges[i].first & 0xff;
- dest[len++] = (fdsel->data).ranges[i].fd;
+ dest[len++] =
+ (card8) (((fdsel->data).ranges[i].first >> 8) & 0xff);
+ dest[len++] = (card8) ((fdsel->data).ranges[i].first & 0xff);
+ dest[len++] = (card8) ((fdsel->data).ranges[i].fd);
}
if (destlen < len + 2)
CFF_ERROR("in cff_pack_fdselect(): Buffer overflow");
- dest[len++] = (cff->num_glyphs >> 8) & 0xff;
- dest[len++] = cff->num_glyphs & 0xff;
- dest[1] = ((len / 3 - 1) >> 8) & 0xff;
- dest[2] = (len / 3 - 1) & 0xff;
+ dest[len++] = (card8) ((cff->num_glyphs >> 8) & 0xff);
+ dest[len++] = (card8) (cff->num_glyphs & 0xff);
+ dest[1] = (card8) (((len / 3 - 1) >> 8) & 0xff);
+ dest[2] = (card8) ((len / 3 - 1) & 0xff);
}
break;
default:
@@ -2803,10 +2871,10 @@ long cff_pack_fdselect(cff_font * cff, card8 * dest, long destlen)
-/*
- * Create an instance of embeddable font.
- */
-static void write_fontfile(cff_font * cffont, char *fullname)
+@ Create an instance of embeddable font.
+
+@c
+static void write_fontfile(PDF pdf, cff_font * cffont, char *fullname)
{
cff_index *topdict, *fdarray, *private;
unsigned char *dest;
@@ -2823,9 +2891,9 @@ static void write_fontfile(cff_font * cffont, char *fullname)
cff_dict_remove(cffont->topdict, "Private"); /* some bad font may have */
cff_dict_remove(cffont->topdict, "Encoding"); /* some bad font may have */
- topdict->offset[1] = cff_dict_pack(cffont->topdict,
- (card8 *) work_buffer,
- WORK_BUFFER_SIZE) + 1;
+ topdict->offset[1] = (l_offset) cff_dict_pack(cffont->topdict,
+ (card8 *) work_buffer,
+ WORK_BUFFER_SIZE) + 1;
for (i = 0; i < cffont->num_fds; i++) {
size = 0;
if (cffont->private && cffont->private[i]) {
@@ -2835,10 +2903,13 @@ static void write_fontfile(cff_font * cffont, char *fullname)
cff_dict_remove(cffont->fdarray[i], "Private");
}
}
- (private->offset)[i + 1] = (private->offset)[i] + size;
- (fdarray->offset)[i + 1] = (fdarray->offset)[i] +
- cff_dict_pack(cffont->fdarray[i],
- (card8 *) work_buffer, WORK_BUFFER_SIZE);
+ (private->offset)[i + 1] =
+ (unsigned long) ((private->offset)[i] + (unsigned) size);
+ (fdarray->offset)[i + 1] =
+ (unsigned long) ((fdarray->offset)[i] + (unsigned)
+ cff_dict_pack(cffont->fdarray[i],
+ (card8 *) work_buffer,
+ WORK_BUFFER_SIZE));
}
destlen = 4; /* header size */
@@ -2850,9 +2921,9 @@ static void write_fontfile(cff_font * cffont, char *fullname)
destlen += (cffont->fdselect->num_entries) * 3 + 5; /* fdselect format 3 */
destlen += cff_index_size(cffont->cstrings);
destlen += cff_index_size(fdarray);
- destlen += private->offset[private->count] - 1; /* Private is not INDEX */
+ destlen = (long) (destlen + (long) private->offset[private->count] - 1); /* Private is not INDEX */
- dest = xcalloc(destlen, sizeof(card8));
+ dest = xcalloc((unsigned) destlen, sizeof(card8));
offset = 0;
/* Header */
@@ -2868,36 +2939,38 @@ static void write_fontfile(cff_font * cffont, char *fullname)
offset += cff_pack_index(cffont->gsubr, dest + offset, destlen - offset);
/* charset */
- cff_dict_set(cffont->topdict, "charset", 0, offset);
+ cff_dict_set(cffont->topdict, "charset", 0, (double) offset);
offset += cff_pack_charsets(cffont, dest + offset, destlen - offset);
/* FDSelect */
- cff_dict_set(cffont->topdict, "FDSelect", 0, offset);
+ cff_dict_set(cffont->topdict, "FDSelect", 0, (double) offset);
offset += cff_pack_fdselect(cffont, dest + offset, destlen - offset);
/* CharStrings */
- cff_dict_set(cffont->topdict, "CharStrings", 0, offset);
+ cff_dict_set(cffont->topdict, "CharStrings", 0, (double) offset);
offset += cff_pack_index(cffont->cstrings,
dest + offset, cff_index_size(cffont->cstrings));
cff_release_index(cffont->cstrings);
cffont->cstrings = NULL; /* Charstrings cosumes huge memory */
/* FDArray and Private */
- cff_dict_set(cffont->topdict, "FDArray", 0, offset);
+ cff_dict_set(cffont->topdict, "FDArray", 0, (double) offset);
fdarray_offset = offset;
offset += cff_index_size(fdarray);
- fdarray->data = xcalloc(fdarray->offset[fdarray->count] - 1, sizeof(card8));
+ fdarray->data =
+ xcalloc((unsigned) (fdarray->offset[fdarray->count] - 1),
+ sizeof(card8));
for (i = 0; i < cffont->num_fds; i++) {
- size = private->offset[i + 1] - private->offset[i];
+ size = (long) (private->offset[i + 1] - private->offset[i]);
if (cffont->private[i] && size > 0) {
cff_dict_pack(cffont->private[i], dest + offset, size);
- cff_dict_set(cffont->fdarray[i], "Private", 0, size);
- cff_dict_set(cffont->fdarray[i], "Private", 1, offset);
+ cff_dict_set(cffont->fdarray[i], "Private", 0, (double) size);
+ cff_dict_set(cffont->fdarray[i], "Private", 1, (double) offset);
}
cff_dict_pack(cffont->fdarray[i],
fdarray->data + (fdarray->offset)[i] - 1,
- fdarray->offset[fdarray->count] - 1);
+ (long) (fdarray->offset[fdarray->count] - 1));
offset += size;
}
@@ -2906,45 +2979,47 @@ static void write_fontfile(cff_font * cffont, char *fullname)
cff_release_index(private);
/* Finally Top DICT */
- topdict->data = xcalloc(topdict->offset[topdict->count] - 1, sizeof(card8));
- cff_dict_pack(cffont->topdict,
- topdict->data, topdict->offset[topdict->count] - 1);
+ topdict->data =
+ xcalloc((unsigned) (topdict->offset[topdict->count] - 1),
+ sizeof(card8));
+ cff_dict_pack(cffont->topdict, topdict->data,
+ (long) (topdict->offset[topdict->count] - 1));
cff_pack_index(topdict, dest + topdict_offset, cff_index_size(topdict));
cff_release_index(topdict);
for (i = 0; i < offset; i++)
- fb_putchar(dest[i]);
+ fb_putchar(pdf, dest[i]);
- /*fprintf(stdout," (%i/%i)",offset,cffont->stream_size); */
xfree(dest);
return;
}
-/* this block is used a few times */
-
+@ this block is used a few times
+@c
#define DO_COPY_CHARSTRING() \
if ((avl_find(fd->gl_tree,glyph) != NULL)) { \
- size = cs_idx->offset[code+1] - cs_idx->offset[code]; \
+ size = (long)(cs_idx->offset[code+1] - cs_idx->offset[code]); \
if (size > CS_STR_LEN_MAX) { \
pdftex_fail("Charstring too long: gid=%u, %ld bytes", code, size); \
} \
if (charstring_len + CS_STR_LEN_MAX >= max_len) { \
- max_len = charstring_len + 2 * CS_STR_LEN_MAX; \
- charstrings->data = xrealloc(charstrings->data, max_len*sizeof(card8)); \
+ max_len = (long)(charstring_len + 2 * CS_STR_LEN_MAX); \
+ charstrings->data = xrealloc(charstrings->data, (unsigned)((unsigned)max_len*sizeof(card8))); \
} \
- (charstrings->offset)[gid] = charstring_len + 1; \
- cffont->offset= offset + (cs_idx->offset)[code] - 1; \
- memcpy(data,&cffont->stream[cffont->offset],size); \
+ (charstrings->offset)[gid] = (unsigned)(charstring_len + 1); \
+ cffont->offset= (l_offset)((unsigned)offset + (cs_idx->offset)[code] - 1); \
+ memcpy(data,&cffont->stream[cffont->offset],(size_t)size); \
charstring_len += cs_copy_charstring(charstrings->data + charstring_len, \
- max_len - charstring_len, \
+ max_len - charstring_len, \
data, size, \
cffont->gsubr, (cffont->subrs)[0], \
default_width, nominal_width, NULL); \
gid++; \
}
-void write_cff(cff_font * cffont, fd_entry * fd)
+@ @c
+void write_cff(PDF pdf, cff_font * cffont, fd_entry * fd)
{
cff_index *charstrings, *cs_idx;
@@ -2961,7 +3036,7 @@ void write_cff(cff_font * cffont, fd_entry * fd)
glw_entry *glyph, *found;
struct avl_traverser t;
- fullname = xcalloc(8 + strlen(fd->fontname), 1);
+ fullname = xcalloc((unsigned) (8 + strlen(fd->fontname)), 1);
sprintf(fullname, "%s+%s", fd->subset_tag, fd->fontname);
/* finish parsing the CFF */
@@ -2969,7 +3044,7 @@ void write_cff(cff_font * cffont, fd_entry * fd)
cff_read_subrs(cffont);
/*
- * Widths
+ Widths
*/
if (cffont->private[0] &&
cff_dict_known(cffont->private[0], "defaultWidthX")) {
@@ -3001,7 +3076,7 @@ void write_cff(cff_font * cffont, fd_entry * fd)
for (found = (glw_entry *) avl_t_first(&t, fd->gl_tree);
found != NULL; found = (glw_entry *) avl_t_next(&t)) {
if (found->id > last_cid)
- last_cid = found->id;
+ last_cid = (card16) found->id;
num_glyphs++;
}
@@ -3022,7 +3097,7 @@ void write_cff(cff_font * cffont, fd_entry * fd)
charset = xcalloc(1, sizeof(cff_charsets));
charset->format = 0;
- charset->num_entries = num_glyphs - 1;
+ charset->num_entries = (card16) (num_glyphs - 1);
charset->data.glyphs = xcalloc(num_glyphs, sizeof(s_SID));
gid = 0;
@@ -3031,7 +3106,7 @@ void write_cff(cff_font * cffont, fd_entry * fd)
for (found = (glw_entry *) avl_t_first(&t, fd->gl_tree);
found != NULL; found = (glw_entry *) avl_t_next(&t)) {
if (found->id != 0) {
- charset->data.glyphs[gid] = found->id;
+ charset->data.glyphs[gid] = (s_SID) found->id;
gid++;
}
}
@@ -3060,19 +3135,19 @@ void write_cff(cff_font * cffont, fd_entry * fd)
cff_dict_remove(cffont->topdict, "Private");
cff_dict_remove(cffont->topdict, "Encoding");
- cffont->offset = cff_dict_get(cffont->topdict, "CharStrings", 0);
+ cffont->offset = (l_offset) cff_dict_get(cffont->topdict, "CharStrings", 0);
cs_idx = cff_get_index_header(cffont);
- offset = cffont->offset;
+ offset = (long) cffont->offset;
cs_count = cs_idx->count;
if (cs_count < 2) {
CFF_ERROR("No valid charstring data found.");
}
/* build the new charstrings entry */
- charstrings = cff_new_index(cs_count + 1);
+ charstrings = cff_new_index((card16) (cs_count + 1));
max_len = 2 * CS_STR_LEN_MAX;
- charstrings->data = xcalloc(max_len, sizeof(card8));
+ charstrings->data = xcalloc((unsigned) max_len, sizeof(card8));
charstring_len = 0;
gid = 0;
@@ -3081,7 +3156,7 @@ void write_cff(cff_font * cffont, fd_entry * fd)
{
int i;
for (i = 0; i < cs_count; i++) {
- code = i;
+ code = (card16) i;
glyph->id = code;
DO_COPY_CHARSTRING();
}
@@ -3096,13 +3171,13 @@ void write_cff(cff_font * cffont, fd_entry * fd)
xfree(data);
cff_release_index(cs_idx);
- (charstrings->offset)[num_glyphs] = charstring_len + 1;
+ (charstrings->offset)[num_glyphs] = (l_offset) (charstring_len + 1);
charstrings->count = num_glyphs;
cffont->num_glyphs = num_glyphs;
cffont->cstrings = charstrings;
/*
- * We don't use subroutines at all.
+ We don't use subroutines at all.
*/
if (cffont->gsubr)
cff_release_index(cffont->gsubr);
@@ -3131,17 +3206,20 @@ void write_cff(cff_font * cffont, fd_entry * fd)
(double) cff_get_sid(cffont, "Identity"));
cff_dict_set(cffont->topdict, "ROS", 2, 0.0);
- write_fontfile(cffont, fullname);
+ write_fontfile(pdf, cffont, fullname);
xfree(fullname);
cff_close(cffont);
}
+@ @c
+#undef ERROR /* for mingw */
#define ERROR(a) { perror(a); return 0; }
-/* Input : SID or CID (16-bit unsigned int)
- * Output: glyph index
- */
+@ Input : SID or CID (16-bit unsigned int)
+ Output: glyph index
+
+@c
card16 cff_charsets_lookup(cff_font * cff, card16 cid)
{
card16 gid = 0;
@@ -3165,7 +3243,7 @@ card16 cff_charsets_lookup(cff_font * cff, card16 cid)
case 0:
for (i = 0; i < charset->num_entries; i++) {
if (cid == charset->data.glyphs[i]) {
- gid = i + 1;
+ gid = (card16) (i + 1);
return gid;
}
}
@@ -3176,10 +3254,10 @@ card16 cff_charsets_lookup(cff_font * cff, card16 cid)
cid <=
charset->data.range1[i].first +
charset->data.range1[i].n_left) {
- gid += cid - charset->data.range1[i].first + 1;
+ gid = (card16) (gid + cid - charset->data.range1[i].first + 1);
return gid;
}
- gid += charset->data.range1[i].n_left + 1;
+ gid = (card16) (gid + charset->data.range1[i].n_left + 1);
}
break;
case 2:
@@ -3188,10 +3266,10 @@ card16 cff_charsets_lookup(cff_font * cff, card16 cid)
cid <=
charset->data.range2[i].first +
charset->data.range2[i].n_left) {
- gid += cid - charset->data.range2[i].first + 1;
+ gid = (card16) (gid + cid - charset->data.range2[i].first + 1);
return gid;
}
- gid += charset->data.range2[i].n_left + 1;
+ gid = (card16) (gid + charset->data.range2[i].n_left + 1);
}
break;
default:
@@ -3202,10 +3280,11 @@ card16 cff_charsets_lookup(cff_font * cff, card16 cid)
}
+@ @c
#define is_cidfont(a) ((a)->flag & FONTTYPE_CIDFONT)
#define CID_MAX 65535
-void write_cid_cff(cff_font * cffont, fd_entry * fd)
+void write_cid_cff(PDF pdf, cff_font * cffont, fd_entry * fd)
{
cff_index *charstrings, *cs_idx;
@@ -3232,7 +3311,7 @@ void write_cid_cff(cff_font * cffont, fd_entry * fd)
return;
}
- fullname = xcalloc(8 + strlen(fd->fontname), 1);
+ fullname = xcalloc((unsigned) (8 + strlen(fd->fontname)), 1);
sprintf(fullname, "%s+%s", fd->subset_tag, fd->fontname);
/* finish parsing the CFF */
@@ -3243,8 +3322,9 @@ void write_cid_cff(cff_font * cffont, fd_entry * fd)
cid_count = CFF_CIDCOUNT_DEFAULT;
}
cff_read_charsets(cffont);
- CIDToGIDMap = xmalloc((2 * cid_count) * sizeof(unsigned char));
- memset(CIDToGIDMap, 0, 2 * cid_count);
+ CIDToGIDMap = xmalloc((unsigned)
+ ((2 * (unsigned) cid_count) * sizeof(unsigned char)));
+ memset(CIDToGIDMap, 0, (size_t) (2 * cid_count));
glyph = xtalloc(1, glw_entry);
@@ -3259,12 +3339,12 @@ void write_cid_cff(cff_font * cffont, fd_entry * fd)
last_cid = 0;
num_glyphs = 0;
for (cid = 0; cid <= CID_MAX; cid++) {
- glyph->id = cid;
+ glyph->id = (unsigned) cid;
if (avl_find(fd->gl_tree, glyph) != NULL) {
- gid = cff_charsets_lookup(cffont, cid);
- CIDToGIDMap[2 * cid] = (gid >> 8) & 0xff;
- CIDToGIDMap[2 * cid + 1] = gid & 0xff;
- last_cid = cid;
+ gid = (card16) cff_charsets_lookup(cffont, (card16) cid);
+ CIDToGIDMap[2 * cid] = (unsigned char) ((gid >> 8) & 0xff);
+ CIDToGIDMap[2 * cid + 1] = (unsigned char) (gid & 0xff);
+ last_cid = (card16) cid;
num_glyphs++;
}
}
@@ -3276,10 +3356,10 @@ void write_cid_cff(cff_font * cffont, fd_entry * fd)
cff_read_subrs(cffont);
- cffont->offset = cff_dict_get(cffont->topdict, "CharStrings", 0);
+ cffont->offset = (l_offset) cff_dict_get(cffont->topdict, "CharStrings", 0);
cs_idx = cff_get_index_header(cffont);
- offset = cffont->offset;
+ offset = (long) cffont->offset;
cs_count = cs_idx->count;
if (cs_count < 2) {
CFF_ERROR("No valid charstring data found.");
@@ -3295,9 +3375,9 @@ void write_cid_cff(cff_font * cffont, fd_entry * fd)
fdselect->num_entries = 0;
fdselect->data.ranges = xcalloc(num_glyphs, sizeof(cff_range3));
- charstrings = cff_new_index(cs_count + 1);
+ charstrings = cff_new_index((card16) (cs_count + 1));
max_len = 2 * CS_STR_LEN_MAX;
- charstrings->data = xcalloc(max_len, sizeof(card8));
+ charstrings->data = xcalloc((unsigned) max_len, sizeof(card8));
charstring_len = 0;
prev_fd = -1;
@@ -3306,23 +3386,27 @@ void write_cid_cff(cff_font * cffont, fd_entry * fd)
for (cid = 0; cid <= last_cid; cid++) {
unsigned short gid_org;
- glyph->id = cid;
+ glyph->id = (unsigned) cid;
if (avl_find(fd->gl_tree, glyph) == NULL)
continue;
- gid_org = (CIDToGIDMap[2 * cid] << 8) | (CIDToGIDMap[2 * cid + 1]);
- size = cs_idx->offset[gid_org + 1] - cs_idx->offset[gid_org];
+ gid_org =
+ (short unsigned) ((CIDToGIDMap[2 * cid] << 8) |
+ (CIDToGIDMap[2 * cid + 1]));
+ size = (long) (cs_idx->offset[gid_org + 1] - cs_idx->offset[gid_org]);
if (size > CS_STR_LEN_MAX) {
pdftex_fail("Charstring too long: gid=%u, %ld bytes", cid, size);
}
if (charstring_len + CS_STR_LEN_MAX >= max_len) {
max_len = charstring_len + 2 * CS_STR_LEN_MAX;
charstrings->data =
- xrealloc(charstrings->data, max_len * sizeof(card8));
+ xrealloc(charstrings->data,
+ (unsigned) ((unsigned) max_len * sizeof(card8)));
}
- (charstrings->offset)[gid] = charstring_len + 1;
- cffont->offset = offset + (cs_idx->offset)[gid_org] - 1;
- memcpy(data, &cffont->stream[cffont->offset], size);
+ (charstrings->offset)[gid] = (l_offset) (charstring_len + 1);
+ cffont->offset =
+ (l_offset) ((unsigned) offset + (cs_idx->offset)[gid_org] - 1);
+ memcpy(data, &cffont->stream[cffont->offset], (size_t) size);
fdsel = cff_fdselect_lookup(cffont, gid_org);
charstring_len += cs_copy_charstring(charstrings->data + charstring_len,
max_len - charstring_len,
@@ -3332,13 +3416,13 @@ void write_cid_cff(cff_font * cffont, fd_entry * fd)
NULL);
if (cid > 0 && gid_org > 0) {
- charset->data.glyphs[charset->num_entries] = cid;
- charset->num_entries += 1;
+ charset->data.glyphs[charset->num_entries] = (s_SID) cid;
+ charset->num_entries++;
}
if (fdsel != prev_fd) {
fdselect->data.ranges[fdselect->num_entries].first = gid;
- fdselect->data.ranges[fdselect->num_entries].fd = fdsel;
- fdselect->num_entries += 1;
+ fdselect->data.ranges[fdselect->num_entries].fd = (card8) fdsel;
+ fdselect->num_entries++;
prev_fd = fdsel;
}
gid++;
@@ -3351,7 +3435,7 @@ void write_cid_cff(cff_font * cffont, fd_entry * fd)
xfree(CIDToGIDMap);
- (charstrings->offset)[num_glyphs] = charstring_len + 1;
+ (charstrings->offset)[num_glyphs] = (l_offset) (charstring_len + 1);
charstrings->count = num_glyphs;
cffont->num_glyphs = num_glyphs;
cffont->cstrings = charstrings;
@@ -3378,20 +3462,18 @@ void write_cid_cff(cff_font * cffont, fd_entry * fd)
}
}
- write_fontfile(cffont, fullname);
+ write_fontfile(pdf, cffont, fullname);
xfree(fullname);
cff_close(cffont);
}
+@ here is a sneaky trick: fontforge knows how to convert Type1 to CFF, so
+I have defined a utility function in luafflib.c that does exactly that.
+If it works out ok, I will clean up this code.
-/* here is a sneaky trick: fontforge knows how to convert Type1 to CFF, so
- * I have defined a utility function in luafflib.c that does exactly that.
- * If it works out ok, I will clean up this code.
- */
-#include <luafontloader/src/luafflib.h>
-
-void writetype1w(fd_entry * fd)
+@c
+void writetype1w(PDF pdf, fd_entry * fd)
{
cff_font *cff;
int i;
@@ -3423,10 +3505,10 @@ void writetype1w(fd_entry * fd)
if (tfm_size > 0) {
cff = read_cff(tfm_buffer, tfm_size, 0);
if (cff != NULL) {
- write_cff(cff, fd);
+ write_cff(pdf, cff, fd);
} else {
for (i = 0; i < tfm_size; i++)
- fb_putchar(tfm_buffer[i]);
+ fb_putchar(pdf, tfm_buffer[i]);
}
fd->ff_found = 1;
} else {
diff --git a/Build/source/texk/web2c/luatexdir/font/writeenc.c b/Build/source/texk/web2c/luatexdir/font/writeenc.c
deleted file mode 100644
index e0cd7bc43a0..00000000000
--- a/Build/source/texk/web2c/luatexdir/font/writeenc.c
+++ /dev/null
@@ -1,187 +0,0 @@
-/* writeenc.c
-
- Copyright 1996-2006 Han The Thanh <thanh@pdftex.org>
- Copyright 2006-2008 Taco Hoekwater <taco@luatex.org>
-
- This file is part of LuaTeX.
-
- LuaTeX 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 2 of the License, or (at your
- option) any later version.
-
- LuaTeX 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 Lesser General Public
- License for more details.
-
- You should have received a copy of the GNU General Public License along
- with LuaTeX; if not, see <http://www.gnu.org/licenses/>. */
-
-#include "ptexlib.h"
-#include "inc-epdf.h"
-
-static const char _svn_version[] =
- "$Id: writeenc.c 2448 2009-06-08 07:43:50Z taco $ $URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.40.6/source/texk/web2c/luatexdir/font/writeenc.c $";
-
-/**********************************************************************/
-/* All encoding entries go into AVL tree for fast search by name. */
-
-struct avl_table *fe_tree = NULL;
-
-/* AVL sort fe_entry into fe_tree by name */
-
-static int comp_fe_entry(const void *pa, const void *pb, void *p)
-{
- (void) p;
- return strcmp(((const fe_entry *) pa)->name, ((const fe_entry *) pb)->name);
-}
-
-static fe_entry *new_fe_entry(void)
-{
- fe_entry *fe;
- fe = xtalloc(1, fe_entry);
- fe->name = NULL;
- fe->fe_objnum = 0;
- fe->glyph_names = NULL; /* encoding file not yet read in */
- fe->tx_tree = NULL;
- return fe;
-}
-
-static fe_entry *lookup_fe_entry(char *s)
-{
- fe_entry fe;
- assert(s != NULL);
- fe.name = s;
- if (fe_tree == NULL) {
- fe_tree = avl_create(comp_fe_entry, NULL, &avl_xallocator);
- assert(fe_tree != NULL);
- }
- return (fe_entry *) avl_find(fe_tree, &fe);
-}
-
-static void register_fe_entry(fe_entry * fe)
-{
- void **aa;
- if (fe_tree == NULL) {
- fe_tree = avl_create(comp_fe_entry, NULL, &avl_xallocator);
- assert(fe_tree != NULL);
- }
- assert(fe != NULL);
- assert(fe->name != NULL);
- assert(lookup_fe_entry(fe->name) == NULL); /* encoding not yet registered */
- aa = avl_probe(fe_tree, fe);
- assert(aa != NULL);
-}
-
-fe_entry *get_fe_entry(char *s)
-{
- fe_entry *fe;
- char **gl;
- if ((fe = lookup_fe_entry(s)) == NULL && (gl = load_enc_file(s)) != NULL) {
- fe = new_fe_entry();
- fe->name = s;
- fe->glyph_names = gl;
- register_fe_entry(fe);
- }
- return fe;
-}
-
-/**********************************************************************/
-
-void epdf_write_enc(char **glyph_names, integer fe_objnum)
-{
- int i, i_old;
- assert(glyph_names != NULL);
- assert(fe_objnum != 0);
- pdf_begin_dict(fe_objnum, 1);
- pdf_puts("/Type /Encoding\n");
- pdf_puts("/Differences [");
- for (i = 0, i_old = -2; i < 256; i++)
- if (glyph_names[i] != notdef) {
- if (i == i_old + 1) /* no gap */
- pdf_printf("/%s", glyph_names[i]);
- else {
- if (i_old == -2)
- pdf_printf("%i/%s", i, glyph_names[i]);
- else
- pdf_printf(" %i/%s", i, glyph_names[i]);
- }
- i_old = i;
- }
- pdf_puts("]\n");
- pdf_end_dict();
-}
-
-static void write_enc(char **glyph_names, struct avl_table *tx_tree, integer fe_objnum)
-{
- int i_old, *p;
- struct avl_traverser t;
- assert(glyph_names != NULL);
- assert(tx_tree != NULL);
- assert(fe_objnum != 0);
- pdf_begin_dict(fe_objnum, 1);
- pdf_puts("/Type /Encoding\n");
- pdf_puts("/Differences [");
- avl_t_init(&t, tx_tree);
- for (i_old = -2, p = (int *) avl_t_first(&t, tx_tree); p != NULL;
- p = (int *) avl_t_next(&t)) {
- if (*p == i_old + 1) /* no gap */
- pdf_printf("/%s", glyph_names[*p]);
- else {
- if (i_old == -2)
- pdf_printf("%i/%s", *p, glyph_names[*p]);
- else
- pdf_printf(" %i/%s", *p, glyph_names[*p]);
- }
- i_old = *p;
- }
- pdf_puts("]\n");
- pdf_end_dict();
-}
-
-static void write_fontencoding(fe_entry * fe)
-{
- assert(fe != NULL);
- write_enc(fe->glyph_names, fe->tx_tree, fe->fe_objnum);
-}
-
-void write_fontencodings(void)
-{
- fe_entry *fe;
- struct avl_traverser t;
- if (fe_tree == NULL)
- return;
- avl_t_init(&t, fe_tree);
- for (fe = (fe_entry *) avl_t_first(&t, fe_tree); fe != NULL;
- fe = (fe_entry *) avl_t_next(&t))
- if (fe->fe_objnum != 0)
- write_fontencoding(fe);
-}
-
-/**********************************************************************/
-/* cleaning up... */
-
-static void destroy_fe_entry(void *pa, void *pb)
-{
- fe_entry *p;
- int i;
- (void) pb;
- p = (fe_entry *) pa;
- xfree(p->name);
- if (p->glyph_names != NULL)
- for (i = 0; i < 256; i++)
- if (p->glyph_names[i] != notdef)
- xfree(p->glyph_names[i]);
- xfree(p->glyph_names);
- xfree(p);
-}
-
-void enc_free(void)
-{
- if (fe_tree != NULL)
- avl_destroy(fe_tree, destroy_fe_entry);
- fe_tree = NULL;
-}
-
-/**********************************************************************/
diff --git a/Build/source/texk/web2c/luatexdir/font/writeenc.w b/Build/source/texk/web2c/luatexdir/font/writeenc.w
new file mode 100644
index 00000000000..1b98c824970
--- /dev/null
+++ b/Build/source/texk/web2c/luatexdir/font/writeenc.w
@@ -0,0 +1,161 @@
+% writeenc.w
+%
+% Copyright 1996-2006 Han The Thanh <thanh@@pdftex.org>
+% Copyright 2006-2008 Taco Hoekwater <taco@@luatex.org>
+
+% This file is part of LuaTeX.
+
+% LuaTeX 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 2 of the License, or (at your
+% option) any later version.
+
+% LuaTeX 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 Lesser General Public
+% License for more details.
+
+% You should have received a copy of the GNU General Public License along
+% with LuaTeX; if not, see <http://www.gnu.org/licenses/>. */
+
+@ @c
+#include "ptexlib.h"
+
+static const char _svn_version[] =
+ "$Id: writeenc.w 3584 2010-04-02 17:45:55Z hhenkel $ "
+"$URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.60.0/source/texk/web2c/luatexdir/font/writeenc.w $";
+
+@ All encoding entries go into AVL tree for fast search by name.
+@c
+struct avl_table *fe_tree = NULL;
+
+@ AVL sort |fe_entry| into |fe_tree| by name
+@c
+static int comp_fe_entry(const void *pa, const void *pb, void *p)
+{
+ (void) p;
+ return strcmp(((const fe_entry *) pa)->name, ((const fe_entry *) pb)->name);
+}
+
+fe_entry *new_fe_entry(void)
+{
+ fe_entry *fe;
+ fe = xtalloc(1, fe_entry);
+ fe->name = NULL;
+ fe->fe_objnum = 0;
+ fe->glyph_names = NULL; /* encoding file not yet read in */
+ fe->tx_tree = NULL;
+ return fe;
+}
+
+fe_entry *lookup_fe_entry(char *s)
+{
+ fe_entry fe;
+ assert(s != NULL);
+ fe.name = s;
+ if (fe_tree == NULL) {
+ fe_tree = avl_create(comp_fe_entry, NULL, &avl_xallocator);
+ assert(fe_tree != NULL);
+ }
+ return (fe_entry *) avl_find(fe_tree, &fe);
+}
+
+void register_fe_entry(fe_entry * fe)
+{
+ void **aa;
+ if (fe_tree == NULL) {
+ fe_tree = avl_create(comp_fe_entry, NULL, &avl_xallocator);
+ assert(fe_tree != NULL);
+ }
+ assert(fe != NULL);
+ assert(fe->name != NULL);
+ assert(lookup_fe_entry(fe->name) == NULL); /* encoding not yet registered */
+ aa = avl_probe(fe_tree, fe);
+ assert(aa != NULL);
+}
+
+fe_entry *get_fe_entry(char *s)
+{
+ fe_entry *fe;
+ char **gl;
+ if ((fe = lookup_fe_entry(s)) == NULL && (gl = load_enc_file(s)) != NULL) {
+ fe = new_fe_entry();
+ fe->name = s;
+ fe->glyph_names = gl;
+ register_fe_entry(fe);
+ }
+ return fe;
+}
+
+@ @c
+void write_enc(PDF pdf, char **glyph_names, struct avl_table *tx_tree,
+ int fe_objnum)
+{
+ int i_old, *p;
+ struct avl_traverser t;
+ assert(glyph_names != NULL);
+ assert(tx_tree != NULL);
+ assert(fe_objnum != 0);
+ pdf_begin_dict(pdf, fe_objnum, 1);
+ pdf_puts(pdf, "/Type /Encoding\n");
+ pdf_puts(pdf, "/Differences [");
+ avl_t_init(&t, tx_tree);
+ for (i_old = -2, p = (int *) avl_t_first(&t, tx_tree); p != NULL;
+ p = (int *) avl_t_next(&t)) {
+ if (*p == i_old + 1) /* no gap */
+ pdf_printf(pdf, "/%s", glyph_names[*p]);
+ else {
+ if (i_old == -2)
+ pdf_printf(pdf, "%i/%s", *p, glyph_names[*p]);
+ else
+ pdf_printf(pdf, " %i/%s", *p, glyph_names[*p]);
+ }
+ i_old = *p;
+ }
+ pdf_puts(pdf, "]\n");
+ pdf_end_dict(pdf);
+}
+
+void write_fontencoding(PDF pdf, fe_entry * fe)
+{
+ assert(fe != NULL);
+ write_enc(pdf, fe->glyph_names, fe->tx_tree, fe->fe_objnum);
+}
+
+void write_fontencodings(PDF pdf)
+{
+ fe_entry *fe;
+ struct avl_traverser t;
+ if (fe_tree == NULL)
+ return;
+ avl_t_init(&t, fe_tree);
+ for (fe = (fe_entry *) avl_t_first(&t, fe_tree); fe != NULL;
+ fe = (fe_entry *) avl_t_next(&t))
+ if (fe->fe_objnum != 0)
+ write_fontencoding(pdf, fe);
+}
+
+@ cleaning up...
+@c
+
+static void destroy_fe_entry(void *pa, void *pb)
+{
+ fe_entry *p;
+ int i;
+ (void) pb;
+ p = (fe_entry *) pa;
+ xfree(p->name);
+ if (p->glyph_names != NULL)
+ for (i = 0; i < 256; i++)
+ if (p->glyph_names[i] != notdef)
+ xfree(p->glyph_names[i]);
+ xfree(p->glyph_names);
+ xfree(p);
+}
+
+void enc_free(void)
+{
+ if (fe_tree != NULL)
+ avl_destroy(fe_tree, destroy_fe_entry);
+ fe_tree = NULL;
+}
diff --git a/Build/source/texk/web2c/luatexdir/font/writefont.c b/Build/source/texk/web2c/luatexdir/font/writefont.w
index 5dd861f88ee..523cae59740 100644
--- a/Build/source/texk/web2c/luatexdir/font/writefont.c
+++ b/Build/source/texk/web2c/luatexdir/font/writefont.w
@@ -1,33 +1,33 @@
-/* writefont.c
-
- Copyright 1996-2006 Han The Thanh <thanh@pdftex.org>
- Copyright 2006-2009 Taco Hoekwater <taco@luatex.org>
+% writefont.w
- This file is part of LuaTeX.
+% Copyright 1996-2006 Han The Thanh <thanh@@pdftex.org>
+% Copyright 2006-2010 Taco Hoekwater <taco@@luatex.org>
- LuaTeX 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 2 of the License, or (at your
- option) any later version.
+% This file is part of LuaTeX.
- LuaTeX 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 Lesser General Public
- License for more details.
+% LuaTeX 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 2 of the License, or (at your
+% option) any later version.
- You should have received a copy of the GNU General Public License along
- with LuaTeX; if not, see <http://www.gnu.org/licenses/>. */
+% LuaTeX 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 Lesser General Public
+% License for more details.
-#include "ptexlib.h"
-#include "luatexfont.h"
+% You should have received a copy of the GNU General Public License along
+% with LuaTeX; if not, see <http://www.gnu.org/licenses/>. */
+@ @c
static const char _svn_version[] =
- "$Id: writefont.c 2331 2009-04-18 16:39:50Z hhenkel $ "
- "$URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.40.6/source/texk/web2c/luatexdir/font/writefont.c $";
+ "$Id: writefont.w 3584 2010-04-02 17:45:55Z hhenkel $ "
+"$URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.60.0/source/texk/web2c/luatexdir/font/writefont.w $";
+
+#include "ptexlib.h"
+#include "lua/luatex-api.h"
-void write_cid_fontdictionary(fo_entry * fo, internalfontnumber f);
-void create_cid_fontdictionary(fm_entry * fm, integer font_objnum,
- internalfontnumber f);
+void write_cid_fontdictionary(PDF pdf, fo_entry * fo, internal_font_number f);
+static void create_cid_fontdictionary(PDF pdf, internal_font_number f);
const key_entry font_key[FONT_KEYS_NUM] = {
{"Ascent", "Ascender", 1}
@@ -43,8 +43,8 @@ const key_entry font_key[FONT_KEYS_NUM] = {
, {"FontName", "FontName", 1}
};
-/**********************************************************************/
-
+@
+@c
struct avl_table *fo_tree = NULL; /* tree of font dictionaries */
struct avl_table *fd_tree = NULL; /* tree of font descriptor objects */
@@ -57,22 +57,16 @@ static int comp_fo_entry(const void *pa, const void *pb, void *p)
static int comp_fd_entry(const void *pa, const void *pb, void *p)
{
- int i;
const fd_entry *p1 = (const fd_entry *) pa, *p2 = (const fd_entry *) pb;
(void) p;
assert(p1->fm != NULL && is_fontfile(p1->fm) &&
p2->fm != NULL && is_fontfile(p2->fm));
- if ((i = strcmp(p1->fm->ff_name, p2->fm->ff_name)) != 0)
- return i;
- cmp_return(p1->fm->slant, p2->fm->slant);
- cmp_return(p1->fm->extend, p2->fm->extend);
- return 0;
+ return strcmp(p1->fm->ff_name, p2->fm->ff_name);
}
-/**********************************************************************/
-/* initialize data structure for /Type /Font */
-
-static fo_entry *new_fo_entry(void)
+@ initialize data structure for /Type /Font
+@c
+fo_entry *new_fo_entry(void)
{
fo_entry *fo;
fo = xtalloc(1, fo_entry);
@@ -89,8 +83,8 @@ static fo_entry *new_fo_entry(void)
return fo;
}
-/* initialize data structure for /Type /FontDescriptor */
-
+@ initialize data structure for /Type /FontDescriptor
+@c
fd_entry *new_fd_entry(void)
{
fd_entry *fd;
@@ -101,7 +95,6 @@ fd_entry *new_fd_entry(void)
fd->subset_tag = NULL;
fd->ff_found = false;
fd->ff_objnum = 0;
- fd->fn_objnum = 0;
fd->all_glyphs = false;
fd->write_ttf_glyph_names = false;
for (i = 0; i < FONT_KEYS_NUM; i++) {
@@ -116,33 +109,30 @@ fd_entry *new_fd_entry(void)
return fd;
}
-/**********************************************************************/
-/*
- * Only fallback values of font metrics are taken from the TFM info
- * of f by preset_fontmetrics(). During reading of the font file,
- * these values are replaced by metrics from the font, if available.
- */
+@
+Only fallback values of font metrics are taken from the TFM info
+of |f| by |preset_fontmetrics|. During reading of the font file,
+these values are replaced by metrics from the font, if available.
-static void preset_fontmetrics(fd_entry * fd, internalfontnumber f)
+@c
+static void preset_fontmetrics(fd_entry * fd, internal_font_number f)
{
int i;
- fd->font_dim[ITALIC_ANGLE_CODE].val =
- divide_scaled(-atan(get_slant(f) / 65536.0) * (180 / M_PI),
- pdf_font_size(f), 3);
+ fd->font_dim[ITALIC_ANGLE_CODE].val = 0;
fd->font_dim[ASCENT_CODE].val =
- divide_scaled(char_height(f, 'h'), pdf_font_size(f), 3);
+ divide_scaled(char_height(f, 'h'), font_size(f), 3);
fd->font_dim[CAPHEIGHT_CODE].val =
- divide_scaled(char_height(f, 'H'), pdf_font_size(f), 3);
- i = -divide_scaled(char_depth(f, 'y'), pdf_font_size(f), 3);
+ divide_scaled(char_height(f, 'H'), font_size(f), 3);
+ i = -divide_scaled(char_depth(f, 'y'), font_size(f), 3);
fd->font_dim[DESCENT_CODE].val = i < 0 ? i : 0;
fd->font_dim[STEMV_CODE].val =
- divide_scaled(char_width(f, '.') / 3, pdf_font_size(f), 3);
+ divide_scaled(char_width(f, '.') / 3, font_size(f), 3);
fd->font_dim[XHEIGHT_CODE].val =
- divide_scaled(get_x_height(f), pdf_font_size(f), 3);
+ divide_scaled(get_x_height(f), font_size(f), 3);
fd->font_dim[FONTBBOX1_CODE].val = 0;
fd->font_dim[FONTBBOX2_CODE].val = fd->font_dim[DESCENT_CODE].val;
fd->font_dim[FONTBBOX3_CODE].val =
- divide_scaled(get_quad(f), pdf_font_size(f), 3);
+ divide_scaled(get_quad(f), font_size(f), 3);
fd->font_dim[FONTBBOX4_CODE].val =
fd->font_dim[CAPHEIGHT_CODE].val > fd->font_dim[ASCENT_CODE].val ?
fd->font_dim[CAPHEIGHT_CODE].val : fd->font_dim[ASCENT_CODE].val;
@@ -183,59 +173,52 @@ static void fix_fontmetrics(fd_entry * fd)
}
}
-static void write_fontmetrics(fd_entry * fd)
+static void write_fontmetrics(PDF pdf, fd_entry * fd)
{
int i;
fix_fontmetrics(fd);
- pdf_printf("/%s [%i %i %i %i]\n", font_key[FONTBBOX1_CODE].pdfname,
+ pdf_printf(pdf, "/%s [%i %i %i %i]\n", font_key[FONTBBOX1_CODE].pdfname,
(int) fd->font_dim[FONTBBOX1_CODE].val,
(int) fd->font_dim[FONTBBOX2_CODE].val,
(int) fd->font_dim[FONTBBOX3_CODE].val,
(int) fd->font_dim[FONTBBOX4_CODE].val);
for (i = 0; i < GEN_KEY_NUM; i++)
if (fd->font_dim[i].set)
- pdf_printf("/%s %i\n", font_key[i].pdfname, fd->font_dim[i].val);
+ pdf_printf(pdf, "/%s %i\n", font_key[i].pdfname,
+ fd->font_dim[i].val);
}
-/**********************************************************************/
-
-static void preset_fontname(fo_entry * fo)
+@
+@c
+static void preset_fontname(fo_entry * fo, internal_font_number f)
{
if (fo->fm->ps_name != NULL)
fo->fd->fontname = xstrdup(fo->fm->ps_name); /* just fallback */
+ else if (font_fullname(f) != NULL)
+ fo->fd->fontname = xstrdup(font_fullname(f));
else
fo->fd->fontname = xstrdup(fo->fm->tfm_name);
}
-static void write_fontname(fd_entry * fd, const char *key)
+static void write_fontname(PDF pdf, fd_entry * fd, const char *key)
{
assert(fd->fontname != NULL);
- pdf_puts("/");
+ pdf_puts(pdf, "/");
if (key != NULL)
- pdf_printf("%s /", key);
+ pdf_printf(pdf, "%s /", key);
if (fd->subset_tag != NULL)
- pdf_printf("%s+", fd->subset_tag);
- pdf_printf("%s\n", fd->fontname);
-}
-
-static void write_fontname_object(fd_entry * fd)
-{
- assert(fd->fn_objnum != 0);
- pdf_begin_obj(fd->fn_objnum, 1);
- write_fontname(fd, NULL);
- pdf_end_obj();
+ pdf_printf(pdf, "%s+", fd->subset_tag);
+ pdf_printf(pdf, "%s\n", fd->fontname);
}
-/**********************************************************************/
-
-fd_entry *lookup_fd_entry(char *s, integer slant, integer extend)
+@
+@c
+fd_entry *lookup_fd_entry(char *s)
{
fd_entry fd;
fm_entry fm;
assert(s != NULL);
fm.ff_name = s;
- fm.slant = slant;
- fm.extend = extend;
fd.fm = &fm;
if (fd_tree == NULL) {
fd_tree = avl_create(comp_fd_entry, NULL, &avl_xallocator);
@@ -244,12 +227,12 @@ fd_entry *lookup_fd_entry(char *s, integer slant, integer extend)
return (fd_entry *) avl_find(fd_tree, &fd);
}
-static fd_entry *lookup_fontdescriptor(fo_entry * fo)
+fd_entry *lookup_fontdescriptor(fo_entry * fo)
{
assert(fo != NULL);
assert(fo->fm != NULL);
assert(is_fontfile(fo->fm));
- return lookup_fd_entry(fo->fm->ff_name, fo->fm->slant, fo->fm->extend);
+ return lookup_fd_entry(fo->fm->ff_name);
}
void register_fd_entry(fd_entry * fd)
@@ -260,18 +243,18 @@ void register_fd_entry(fd_entry * fd)
assert(fd_tree != NULL);
}
assert(fd != NULL && fd->fm != NULL && is_fontfile(fd->fm));
- assert(lookup_fd_entry(fd->fm->ff_name, fd->fm->slant, fd->fm->extend) == NULL); /* font descriptor not yet registered */
+ assert(lookup_fd_entry(fd->fm->ff_name) == NULL); /* font descriptor not yet registered */
aa = avl_probe(fd_tree, fd);
assert(aa != NULL);
}
-static void create_fontdescriptor(fo_entry * fo, internalfontnumber f)
+void create_fontdescriptor(fo_entry * fo, internal_font_number f)
{
assert(fo != NULL);
assert(fo->fm != NULL);
assert(fo->fd == NULL);
fo->fd = new_fd_entry();
- preset_fontname(fo);
+ preset_fontname(fo, f);
preset_fontmetrics(fo->fd, f);
fo->fd->fe = fo->fe; /* encoding needed by TrueType writing */
fo->fd->fm = fo->fm; /* map entry needed by TrueType writing */
@@ -279,32 +262,13 @@ static void create_fontdescriptor(fo_entry * fo, internalfontnumber f)
assert(fo->fd->gl_tree != NULL);
}
-integer get_fd_objnum(fd_entry * fd)
-{
- assert(fd->fd_objnum != 0);
- return fd->fd_objnum;
-}
-
-integer get_fn_objnum(fd_entry * fd)
-{
- if (fd->fn_objnum == 0)
- fd->fn_objnum = pdf_new_objnum();
- return fd->fn_objnum;
-}
-
-void embed_whole_font(fd_entry * fd)
-{
- fd->all_glyphs = true;
-}
-
-/**********************************************************************/
-/*
- * For all used characters of TeX font f, get corresponding glyph names
- * from external reencoding (.enc) file and collect these in the glyph
- * tree gl_tree of font descriptor fd referenced by font dictionary fo.
- */
+@
+For all used characters of \TeX font |f|, get corresponding glyph names
+from external reencoding (.enc) file and collect these in the glyph
+tree |gl_tree| of font descriptor |fd| referenced by font dictionary |fo|.
-static void mark_reenc_glyphs(fo_entry * fo, internalfontnumber f)
+@c
+void mark_reenc_glyphs(fo_entry * fo, internal_font_number f)
{
int i;
char **g;
@@ -324,14 +288,14 @@ static void mark_reenc_glyphs(fo_entry * fo, internalfontnumber f)
}
}
-/*
- * Function mark_chars() has 2 uses:
- * 1. Mark characters as chars on TeX level.
- * 2. Mark encoding pairs used by TeX to optimize encoding vector.
- */
+@
+Function |mark_chars| has 2 uses:
+\item 1. Mark characters as chars on \TeX\ level.
+\item 2. Mark encoding pairs used by \TeX\ to optimize encoding vector.
-static struct avl_table *mark_chars(fo_entry * fo, struct avl_table *tx_tree,
- internalfontnumber f)
+@c
+struct avl_table *mark_chars(fo_entry * fo, struct avl_table *tx_tree,
+ internal_font_number f)
{
int i, *j;
void **aa;
@@ -350,13 +314,13 @@ static struct avl_table *mark_chars(fo_entry * fo, struct avl_table *tx_tree,
return tx_tree;
}
-/**********************************************************************/
-
-static void get_char_range(fo_entry * fo, internalfontnumber f)
+@
+@c
+void get_char_range(fo_entry * fo, internal_font_number f)
{
int i;
assert(fo != NULL);
- for (i = font_bc(f); i <= font_ec(f); i++) /* search for first_char and last_char */
+ for (i = font_bc(f); i <= font_ec(f); i++) /* search for |first_char| and |last_char| */
if (pdf_char_marked(f, i))
break;
fo->first_char = i;
@@ -371,10 +335,10 @@ static void get_char_range(fo_entry * fo, internalfontnumber f)
}
}
-static int font_has_subset(internalfontnumber f)
+static int font_has_subset(internal_font_number f)
{
int i, s;
- for (i = font_bc(f); i <= font_ec(f); i++) /* search for first_char and last_char */
+ for (i = font_bc(f); i <= font_ec(f); i++) /* search for |first_char| and |last_char| */
if (pdf_char_marked(f, i))
break;
s = i;
@@ -387,40 +351,40 @@ static int font_has_subset(internalfontnumber f)
return 1;
}
-static void write_charwidth_array(fo_entry * fo, internalfontnumber f)
+@
+@c
+static void write_charwidth_array(PDF pdf, fo_entry * fo,
+ internal_font_number f)
{
int i, j, *ip, *fip;
struct avl_traverser t;
assert(fo->tx_tree != NULL);
assert(fo->cw_objnum == 0);
- fo->cw_objnum = pdf_new_objnum();
- pdf_begin_obj(fo->cw_objnum, 1);
+ fo->cw_objnum = pdf_new_objnum(pdf);
+ pdf_begin_obj(pdf, fo->cw_objnum, 1);
avl_t_init(&t, fo->tx_tree);
fip = (int *) avl_t_first(&t, fo->tx_tree);
assert(fip != NULL);
- pdf_puts("[");
+ pdf_puts(pdf, "[");
for (ip = fip, j = *ip; ip != NULL; ip = (int *) avl_t_next(&t)) {
if (ip != fip)
- pdf_puts(" ");
+ pdf_puts(pdf, " ");
i = *ip;
while (j < i - 1) {
- pdf_puts("0 ");
+ pdf_puts(pdf, "0 ");
j++;
}
j = i;
- pdf_print_charwidth(f, i);
+ pdf_print_charwidth(pdf, f, i);
}
- pdf_puts("]\n");
- pdf_end_obj();
+ pdf_puts(pdf, "]\n");
+ pdf_end_obj(pdf);
}
-/**********************************************************************/
-/*
- * Remark: Font objects from embedded PDF files are never registered
- * into fo_tree; they are individually written out.
- */
-
-static fo_entry *lookup_fo_entry(char *s)
+@ Remark: Font objects from embedded PDF files are never registered
+into |fo_tree|; they are individually written out.
+@c
+fo_entry *lookup_fo_entry(char *s)
{
fo_entry fo;
fm_entry fm;
@@ -434,7 +398,7 @@ static fo_entry *lookup_fo_entry(char *s)
return (fo_entry *) avl_find(fo_tree, &fo);
}
-static void register_fo_entry(fo_entry * fo)
+void register_fo_entry(fo_entry * fo)
{
void **aa;
if (fo_tree == NULL) {
@@ -449,63 +413,65 @@ static void register_fo_entry(fo_entry * fo)
assert(aa != NULL);
}
-/**********************************************************************/
-
-static void write_fontfile(fd_entry * fd)
+@
+@c
+static void write_fontfile(PDF pdf, fd_entry * fd)
{
assert(is_included(fd->fm));
if (is_cidkeyed(fd->fm)) {
if (is_opentype(fd->fm))
- writetype0(fd);
+ writetype0(pdf, fd);
else if (is_truetype(fd->fm))
- writetype2(fd);
+ writetype2(pdf, fd);
else if (is_type1(fd->fm))
- writetype1w(fd);
+ writetype1w(pdf, fd);
else
assert(0);
} else {
if (is_type1(fd->fm))
- writet1(fd);
+ writet1(pdf, fd);
else if (is_truetype(fd->fm))
- writettf(fd);
+ writettf(pdf, fd);
else if (is_opentype(fd->fm))
- writeotf(fd);
+ writeotf(pdf, fd);
else
assert(0);
}
if (!fd->ff_found)
return;
assert(fd->ff_objnum == 0);
- fd->ff_objnum = pdf_new_objnum();
- pdf_begin_dict(fd->ff_objnum, 0); /* font file stream */
+ fd->ff_objnum = pdf_new_objnum(pdf);
+ pdf_begin_dict(pdf, fd->ff_objnum, 0); /* font file stream */
if (is_cidkeyed(fd->fm)) {
/* No subtype is used for TrueType-based OpenType fonts */
if (is_opentype(fd->fm) || is_type1(fd->fm))
- pdf_puts("/Subtype /CIDFontType0C\n");
- /* else
- pdf_puts("/Subtype /OpenType\n"); */
+ pdf_puts(pdf, "/Subtype /CIDFontType0C\n");
+#if 0
+ else
+ pdf_puts(pdf,"/Subtype /OpenType\n");
+#endif
} else {
if (is_type1(fd->fm))
- pdf_printf("/Length1 %i\n/Length2 %i\n/Length3 %i\n",
+ pdf_printf(pdf, "/Length1 %i\n/Length2 %i\n/Length3 %i\n",
(int) t1_length1, (int) t1_length2, (int) t1_length3);
else if (is_truetype(fd->fm))
- pdf_printf("/Length1 %i\n", (int) ttf_length);
+ pdf_printf(pdf, "/Length1 %i\n", (int) ttf_length);
else if (is_opentype(fd->fm))
- pdf_puts("/Subtype /Type1C\n");
+ pdf_puts(pdf, "/Subtype /Type1C\n");
else
assert(0);
}
- pdf_begin_stream();
- fb_flush();
- pdf_end_stream();
+ pdf_begin_stream(pdf);
+ fb_flush(pdf);
+ pdf_end_stream(pdf);
}
-/**********************************************************************/
-
-static void write_fontdescriptor(fd_entry * fd)
+@
+@c
+static void write_fontdescriptor(PDF pdf, fd_entry * fd)
{
static const int std_flags[] = {
- /* indices for << start with 0, but bits start with 1, so the numbers
+ /* indices for << start with 0, but bits start with 1, so the numbers
* for << are 1 lower than the bits in table 5.20 */
/* *INDENT-OFF* */
1 + 2 + (1 << 5), /* Courier */
@@ -529,15 +495,13 @@ static void write_fontdescriptor(fd_entry * fd)
int fd_flags;
assert(fd != NULL && fd->fm != NULL);
- if (is_fontfile(fd->fm))
- write_fontfile(fd); /* this will set fd->ff_found if font file is found */
- if (fd->fn_objnum != 0)
- write_fontname_object(fd);
+ if (is_fontfile(fd->fm) && is_included(fd->fm))
+ write_fontfile(pdf, fd); /* this will set |fd->ff_found| if font file is found */
if (fd->fd_objnum == 0)
- fd->fd_objnum = pdf_new_objnum();
- pdf_begin_dict(fd->fd_objnum, 1);
- pdf_puts("/Type /FontDescriptor\n");
- write_fontname(fd, "FontName");
+ fd->fd_objnum = pdf_new_objnum(pdf);
+ pdf_begin_dict(pdf, fd->fd_objnum, 1);
+ pdf_puts(pdf, "/Type /FontDescriptor\n");
+ write_fontname(pdf, fd, "FontName");
if (fd->fm->fd_flags != FD_FLAGS_NOT_SET_IN_MAPLINE)
fd_flags = (int) fd->fm->fd_flags;
else if (fd->ff_found)
@@ -552,15 +516,15 @@ static void write_fontdescriptor(fd_entry * fd)
fd->fm->ps_name != NULL ? fd->fm->ps_name : "No name given",
fd->fm->tfm_name, fd_flags);
}
- pdf_printf("/Flags %i\n", fd_flags);
- write_fontmetrics(fd);
+ pdf_printf(pdf, "/Flags %i\n", fd_flags);
+ write_fontmetrics(pdf, fd);
if (is_cidkeyed(fd->fm)) {
if (is_type1(fd->fm))
- pdf_printf("/FontFile3 %i 0 R\n", (int) fd->ff_objnum);
+ pdf_printf(pdf, "/FontFile3 %i 0 R\n", (int) fd->ff_objnum);
else if (is_truetype(fd->fm))
- pdf_printf("/FontFile2 %i 0 R\n", (int) fd->ff_objnum);
+ pdf_printf(pdf, "/FontFile2 %i 0 R\n", (int) fd->ff_objnum);
else if (is_opentype(fd->fm))
- pdf_printf("/FontFile3 %i 0 R\n", (int) fd->ff_objnum);
+ pdf_printf(pdf, "/FontFile3 %i 0 R\n", (int) fd->ff_objnum);
else
assert(0);
} else {
@@ -569,35 +533,35 @@ static void write_fontdescriptor(fd_entry * fd)
/* /CharSet is optional; names may appear in any order */
assert(fd->gl_tree != NULL);
avl_t_init(&t, fd->gl_tree);
- pdf_puts("/CharSet (");
+ pdf_puts(pdf, "/CharSet (");
for (glyph = (char *) avl_t_first(&t, fd->gl_tree);
glyph != NULL; glyph = (char *) avl_t_next(&t))
- pdf_printf("/%s", glyph);
- pdf_puts(")\n");
+ pdf_printf(pdf, "/%s", glyph);
+ pdf_puts(pdf, ")\n");
}
if (is_type1(fd->fm))
- pdf_printf("/FontFile %i 0 R\n", (int) fd->ff_objnum);
+ pdf_printf(pdf, "/FontFile %i 0 R\n", (int) fd->ff_objnum);
else if (is_truetype(fd->fm))
- pdf_printf("/FontFile2 %i 0 R\n", (int) fd->ff_objnum);
+ pdf_printf(pdf, "/FontFile2 %i 0 R\n", (int) fd->ff_objnum);
else if (is_opentype(fd->fm))
- pdf_printf("/FontFile3 %i 0 R\n", (int) fd->ff_objnum);
+ pdf_printf(pdf, "/FontFile3 %i 0 R\n", (int) fd->ff_objnum);
else
assert(0);
}
}
- /* TODO: Optional keys for CID fonts.
+ /* TODO: Optional keys for CID fonts.
The most interesting ones are
- /Style << /Panose <12-byte string>>>
+ \.{/Style << /Panose <12-byte string>>>}
and
- /CIDSET <stream>
+ \.{/CIDSET <stream>}
the latter can be used in subsets, to give the included CIDs
as a bitmap on the whole list.
*/
- pdf_end_dict();
+ pdf_end_dict(pdf);
}
-static void write_fontdescriptors(void)
+void write_fontdescriptors(PDF pdf)
{
fd_entry *fd;
struct avl_traverser t;
@@ -606,59 +570,60 @@ static void write_fontdescriptors(void)
avl_t_init(&t, fd_tree);
for (fd = (fd_entry *) avl_t_first(&t, fd_tree); fd != NULL;
fd = (fd_entry *) avl_t_next(&t))
- write_fontdescriptor(fd);
+ write_fontdescriptor(pdf, fd);
}
-/**********************************************************************/
-
-static void write_fontdictionary(fo_entry * fo)
+@
+@c
+void write_fontdictionary(PDF pdf, fo_entry * fo)
{
assert(fo != NULL);
assert(fo->fm != NULL);
- assert(fo->fo_objnum != 0); /* reserved as pdf_font_num(f) in pdftex.web */
+ assert(fo->fo_objnum != 0); /* reserved as |pdf_font_num(f)| elsewhere */
/* write ToUnicode entry if needed */
- if (fixed_gen_tounicode > 0 && fo->fd != NULL) {
+ if (pdf->gen_tounicode > 0 && fo->fd != NULL) {
if (fo->fe != NULL) {
fo->tounicode_objnum =
- write_tounicode(fo->fe->glyph_names, fo->fe->name);
+ write_tounicode(pdf, fo->fe->glyph_names, fo->fe->name);
} else if (is_type1(fo->fm)) {
assert(fo->fd->builtin_glyph_names != NULL);
fo->tounicode_objnum =
- write_tounicode(fo->fd->builtin_glyph_names, fo->fm->tfm_name);
+ write_tounicode(pdf, fo->fd->builtin_glyph_names,
+ fo->fm->tfm_name);
}
}
-
- pdf_begin_dict(fo->fo_objnum, 1);
- pdf_puts("/Type /Font\n");
- pdf_puts("/Subtype /");
+ pdf_begin_dict(pdf, fo->fo_objnum, 1);
+ pdf_puts(pdf, "/Type /Font\n");
+ pdf_puts(pdf, "/Subtype /");
if (is_type1(fo->fm))
- pdf_printf("%s\n", "Type1");
+ pdf_printf(pdf, "%s\n", "Type1");
else if (is_truetype(fo->fm))
- pdf_printf("%s\n", "TrueType");
+ pdf_printf(pdf, "%s\n", "TrueType");
else if (is_opentype(fo->fm))
- pdf_printf("%s\n", "Type1");
+ pdf_printf(pdf, "%s\n", "Type1");
else
assert(0);
assert(fo->fd != NULL && fo->fd->fd_objnum != 0);
- write_fontname(fo->fd, "BaseFont");
- pdf_printf("/FontDescriptor %i 0 R\n", (int) fo->fd->fd_objnum);
+ write_fontname(pdf, fo->fd, "BaseFont");
+ pdf_printf(pdf, "/FontDescriptor %i 0 R\n", (int) fo->fd->fd_objnum);
assert(fo->cw_objnum != 0);
- pdf_printf("/FirstChar %i\n/LastChar %i\n/Widths %i 0 R\n",
+ pdf_printf(pdf, "/FirstChar %i\n/LastChar %i\n/Widths %i 0 R\n",
(int) fo->first_char, (int) fo->last_char, (int) fo->cw_objnum);
if ((is_type1(fo->fm) || is_opentype(fo->fm)) && fo->fe != NULL
&& fo->fe->fe_objnum != 0)
- pdf_printf("/Encoding %i 0 R\n", (int) fo->fe->fe_objnum);
+ pdf_printf(pdf, "/Encoding %i 0 R\n", (int) fo->fe->fe_objnum);
if (fo->tounicode_objnum != 0)
- pdf_printf("/ToUnicode %i 0 R\n", (int) fo->tounicode_objnum);
- if (pdf_font_attr(fo->tex_font) != get_nullstr()) {
- pdf_print(pdf_font_attr(fo->tex_font));
- pdf_puts("\n");
+ pdf_printf(pdf, "/ToUnicode %i 0 R\n", (int) fo->tounicode_objnum);
+ if (pdf_font_attr(fo->tex_font) != get_nullstr() &&
+ pdf_font_attr(fo->tex_font) != 0) {
+ pdf_print(pdf, pdf_font_attr(fo->tex_font));
+ pdf_puts(pdf, "\n");
}
- pdf_end_dict();
+ pdf_end_dict(pdf);
}
-static void write_fontdictionaries(void)
+void write_fontdictionaries(PDF pdf)
{
fo_entry *fo;
struct avl_traverser t;
@@ -667,46 +632,44 @@ static void write_fontdictionaries(void)
avl_t_init(&t, fo_tree);
for (fo = (fo_entry *) avl_t_first(&t, fo_tree); fo != NULL;
fo = (fo_entry *) avl_t_next(&t))
- write_fontdictionary(fo);
+ write_fontdictionary(pdf, fo);
}
-/**********************************************************************/
-/*
- * Final flush of all font related stuff by call from
- * @<Output fonts definition@>= in pdftex.web.
- */
+@ Final flush of all font related stuff by call from
+ \.{Output fonts definitions} elsewhere
-void write_fontstuff(void)
+@c
+void write_fontstuff(PDF pdf)
{
- write_fontdescriptors();
- write_fontencodings(); /* see writeenc.c */
- write_fontdictionaries();
+ write_fontdescriptors(pdf);
+ write_fontencodings(pdf); /* see \.{writeenc.w} */
+ write_fontdictionaries(pdf);
}
-/**********************************************************************/
-
-static void create_fontdictionary(fm_entry * fm, integer font_objnum,
- internalfontnumber f)
+@
+@c
+static void create_fontdictionary(PDF pdf, internal_font_number f)
{
fo_entry *fo = new_fo_entry();
- get_char_range(fo, f); /* set fo->first_char and fo->last_char from f */
+ fm_entry *fm = font_map(f);
+ get_char_range(fo, f); /* set |fo->first_char| and |fo->last_char| from |f| */
if (fo->last_char > 255)
- fo->last_char = 255; /* added 9-4-2008, mantis #25 */
+ fo->last_char = 255; /* added 9-4-2008, mantis \#25 */
assert(fo->last_char >= fo->first_char);
fo->fm = fm;
- fo->fo_objnum = font_objnum;
+ fo->fo_objnum = pdf_font_num(f);
fo->tex_font = f;
if (is_reencoded(fo->fm)) { /* at least the map entry tells so */
- fo->fe = get_fe_entry(fo->fm->encname); /* returns NULL if .enc file couldn't be opened */
+ fo->fe = get_fe_entry(fo->fm->encname); /* returns |NULL| if .enc file couldn't be opened */
if (fo->fe != NULL && (is_type1(fo->fm) || is_opentype(fo->fm))) {
if (fo->fe->fe_objnum == 0)
- fo->fe->fe_objnum = pdf_new_objnum(); /* then it will be written out */
+ fo->fe->fe_objnum = pdf_new_objnum(pdf); /* then it will be written out */
/* mark encoding pairs used by TeX to optimize encoding vector */
fo->fe->tx_tree = mark_chars(fo, fo->fe->tx_tree, f);
}
}
- fo->tx_tree = mark_chars(fo, fo->tx_tree, f); /* for write_charwidth_array() */
- write_charwidth_array(fo, f);
+ fo->tx_tree = mark_chars(fo, fo->tx_tree, f); /* for |write_charwidth_array| */
+ write_charwidth_array(pdf, fo, f);
if (!is_builtin(fo->fm)) {
if (is_type1(fo->fm)) {
if ((fo->fd = lookup_fontdescriptor(fo)) == NULL) {
@@ -728,13 +691,13 @@ static void create_fontdictionary(fm_entry * fm, integer font_objnum,
/* mark non-reencoded characters as chars on TeX level */
fo->fd->tx_tree = mark_chars(fo, fo->fd->tx_tree, f);
if (!is_type1(fo->fm))
- write_fontdescriptor(fo->fd);
+ write_fontdescriptor(pdf, fo->fd);
} else {
/* builtin fonts still need the /Widths array and /FontDescriptor
* (to avoid error 'font FOO contains bad /BBox')
*/
create_fontdescriptor(fo, f);
- write_fontdescriptor(fo->fd);
+ write_fontdescriptor(pdf, fo->fd);
if (!is_std_t1font(fo->fm))
pdftex_warn("font `%s' is not a standard font; "
"I suppose it is available to your PDF viewer then",
@@ -743,11 +706,11 @@ static void create_fontdictionary(fm_entry * fm, integer font_objnum,
if (is_type1(fo->fm))
register_fo_entry(fo);
else
- write_fontdictionary(fo);
+ write_fontdictionary(pdf, fo);
}
-/**********************************************************************/
-
+@
+@c
static int has_ttf_outlines(fm_entry * fm)
{
FILE *f = fopen(fm->ff_name, "rb");
@@ -764,29 +727,54 @@ static int has_ttf_outlines(fm_entry * fm)
return 0;
}
-void do_pdf_font(integer font_objnum, internalfontnumber f)
+void do_pdf_font(PDF pdf, internal_font_number f)
{
+ int del_file = 0;
fm_entry *fm;
- /* This is not 100% true: CID is actually needed whenever (and
- * only) there are more than 256 separate glyphs used. But for
- * now, just assume the user knows what he is doing;
+ /* TODO This is not 100\% true: CID is actually needed whenever (and
+ only) there are more than 256 separate glyphs used. But for
+ now, just assume the user knows what he is doing;
*/
if (!font_has_subset(f))
return;
if (font_encodingbytes(f) == 2) {
/* Create a virtual font map entry, as this is needed by the
- * rest of the font inclusion mechanism.
+ rest of the font inclusion mechanism.
*/
- fm = new_fm_entry();
+ fm = font_map(f) = new_fm_entry();
fm->tfm_name = font_name(f); /* or whatever, not a real tfm */
fm->ff_name = font_filename(f); /* the actual file */
+ if (font_psname(f) != NULL)
+ fm->ps_name = font_psname(f); /* the true name */
+ else
+ fm->ps_name = font_fullname(f); /* the true name */
+ if (fm->ff_name
+ && strlen(fm->ff_name) >= 6
+ && strstr(fm->ff_name,
+ ".dfont") == (fm->ff_name + strlen(fm->ff_name) - 6)) {
+ /* In case of a .dfont, we will extract the correct ttf here,
+ and adjust |fm->ff_name| to point to the temporary file.
+ This file will be deleted later. Todo: keep a nicer name
+ somewhere for the terminal message.
+ */
+ char *s = FindResourceTtfFont(fm->ff_name, fm->ps_name);
+ if (s != NULL) {
+ fm->ff_name = s;
+ del_file = 1;
+ } else {
+ pdftex_fail
+ ("writefont.c: The file (%s) does not contain font `%s'",
+ fm->ff_name, fm->ps_name);
+ }
+ }
fm->encname = font_encodingname(f); /* for the CIDSystemInfo */
- fm->ps_name = font_fullname(f); /* the true name */
fm->slant = font_slant(f); /* slant factor */
+ set_slantset(fm);
fm->extend = font_extend(f); /* extension factor */
+ set_extendset(fm);
fm->fd_flags = 4; /* can perhaps be done better */
- fm->in_use = true;
+ set_inuse(fm);
switch (font_format(f)) {
case opentype_format:
@@ -815,47 +803,48 @@ void do_pdf_font(integer font_objnum, internalfontnumber f)
}
}
set_cidkeyed(fm);
- create_cid_fontdictionary(fm, font_objnum, f);
+ create_cid_fontdictionary(pdf, f);
+
+ if (del_file)
+ unlink(fm->ff_name);
} else {
- fm = hasfmentry(f) ? (fm_entry *) font_map(f) : NULL;
- if (fm == NULL || (fm->ps_name == NULL && fm->ff_name == NULL))
- writet3(font_objnum, f);
+ /* by now |font_map(f)|, if any, should have been set via |pdf_init_font()| */
+ if ((fm = font_map(f)) == NULL
+ || (fm->ps_name == NULL && fm->ff_name == NULL))
+ writet3(pdf, f);
else
- create_fontdictionary(fm, font_objnum, f);
+ create_fontdictionary(pdf, f);
}
}
-/**********************************************************************/
-
-
-/*
- The glyph width is included in |glw_entry|, because that width
+@ The glyph width is included in |glw_entry|, because that width
depends on the value it has in the font where it is actually
typeset from, not the font that is the 'owner' of the fd entry.
TODO: It is possible that the user messes with the metric width,
but handling that properly would require access to the 'hmtx' table
at this point in the program.
-*/
-static int comp_glw_entry(const void *pa, const void *pb, void *p)
+@c
+int comp_glw_entry(const void *pa, const void *pb, void *p
+ __attribute__ ((unused)))
{
unsigned short i, j;
- (void) p;
- i = (*(const glw_entry *) pa).id;
- j = (*(const glw_entry *) pb).id;
+
+ i = (unsigned short) (*(const glw_entry *) pa).id;
+ j = (unsigned short) (*(const glw_entry *) pb).id;
cmp_return(i, j);
return 0;
}
-static void create_cid_fontdescriptor(fo_entry * fo, internalfontnumber f)
+void create_cid_fontdescriptor(fo_entry * fo, internal_font_number f)
{
assert(fo != NULL);
assert(fo->fm != NULL);
assert(fo->fd == NULL);
fo->fd = new_fd_entry();
- preset_fontname(fo);
+ preset_fontname(fo, f);
preset_fontmetrics(fo->fd, f);
fo->fd->fe = fo->fe; /* encoding needed by TrueType writing */
fo->fd->fm = fo->fm; /* map entry needed by TrueType writing */
@@ -863,12 +852,12 @@ static void create_cid_fontdescriptor(fo_entry * fo, internalfontnumber f)
assert(fo->fd->gl_tree != NULL);
}
-/*
- The values |font_bc()| and |font_ec()| are potentially large
+
+@ The values |font_bc()| and |font_ec()| are potentially large
character ids, but the strings that are written out use CID
indexes, and those are limited to 16-bit values.
-*/
+@c
static void mark_cid_subset_glyphs(fo_entry * fo, internal_font_number f)
{
int i, k, l;
@@ -876,11 +865,11 @@ static void mark_cid_subset_glyphs(fo_entry * fo, internal_font_number f)
void *aa;
for (k = 1; k <= max_font_id(); k++) {
if (k == f || -f == pdf_font_num(k)) {
- l = pdf_font_size(k);
+ l = font_size(k);
for (i = font_bc(k); i <= font_ec(k); i++) {
- if (char_exists(k, i) && char_used(k, i)) {
+ if (quick_char_exists(k, i) && char_used(k, i)) {
j = xtalloc(1, glw_entry);
- j->id = char_index(k, i);
+ j->id = (unsigned) char_index(k, i);
j->wd = divide_scaled_n(char_width(k, i), l, 10000.0);
if ((glw_entry *) avl_find(fo->fd->gl_tree, j) == NULL) {
aa = avl_probe(fo->fd->gl_tree, j);
@@ -894,132 +883,128 @@ static void mark_cid_subset_glyphs(fo_entry * fo, internal_font_number f)
}
}
-/*
- It is possible to compress the widths array even better, by using the
- alternate 'range' syntax and possibly even using /DW to set
+
+@ It is possible to compress the widths array even better, by using the
+ alternate 'range' syntax and possibly even using /DW to set
a default value.
-
+
There is a some optimization here already: glyphs that are
- not used do not appear in the widths array at all.
+ not used do not appear in the widths array at all.
We have to make sure that we do not output an (incorrect!)
width for a character that exists in the font, but is not used
in typesetting. An enormous negative width is used as sentinel value
-*/
-
-static void write_cid_charwidth_array(fo_entry * fo)
+@c
+static void write_cid_charwidth_array(PDF pdf, fo_entry * fo)
{
int i, j;
glw_entry *glyph;
struct avl_traverser t;
assert(fo->cw_objnum == 0);
- fo->cw_objnum = pdf_new_objnum();
- pdf_begin_obj(fo->cw_objnum, 1);
+ fo->cw_objnum = pdf_new_objnum(pdf);
+ pdf_begin_obj(pdf, fo->cw_objnum, 1);
avl_t_init(&t, fo->fd->gl_tree);
glyph = (glw_entry *) avl_t_first(&t, fo->fd->gl_tree);
assert(glyph != NULL);
- i = glyph->id;
- pdf_printf("[ %i [", i);
+ i = (int) glyph->id;
+ pdf_printf(pdf, "[ %i [", i);
for (; glyph != NULL; glyph = (glw_entry *) avl_t_next(&t)) {
j = glyph->wd;
if (glyph->id > (unsigned) (i + 1)) {
- pdf_printf("] %i [", glyph->id);
+ pdf_printf(pdf, "] %i [", glyph->id);
j = glyph->wd;
}
if (glyph->id == (unsigned) (i + 1))
- pdf_puts(" ");
+ pdf_puts(pdf, " ");
if (j < 0) {
- pdf_puts("-");
+ pdf_puts(pdf, "-");
j = -j;
}
- /* pdf_print_charwidth(f, i); */
-
- pdf_printf("%i", (j / 10));
+ pdf_printf(pdf, "%i", (j / 10));
if ((j % 10) != 0)
- pdf_printf(".%i", (j % 10));
+ pdf_printf(pdf, ".%i", (j % 10));
- i = glyph->id;
+ i = (int) glyph->id;
}
- pdf_puts("]]\n");
- pdf_end_obj();
+ pdf_puts(pdf, "]]\n");
+ pdf_end_obj(pdf);
}
-
-void create_cid_fontdictionary(fm_entry * fm, integer font_objnum,
- internalfontnumber f)
+static void create_cid_fontdictionary(PDF pdf, internal_font_number f)
{
+ fm_entry *fm = font_map(f);
fo_entry *fo = new_fo_entry();
- get_char_range(fo, f); /* set fo->first_char and fo->last_char from f */
+ get_char_range(fo, f); /* set |fo->first_char| and |fo->last_char| from |f| */
assert(fo->last_char >= fo->first_char);
fo->fm = fm;
- fo->fo_objnum = font_objnum;
+ fo->fo_objnum = pdf_font_num(f);
fo->tex_font = f;
create_cid_fontdescriptor(fo, f);
mark_cid_subset_glyphs(fo, f);
if (is_subsetted(fo->fm)) {
- /*
+ /*
this is a bit sneaky. |make_subset_tag()| actually expects the glyph tree
to contain strings instead of |glw_entry| items. However, all calculations
are done using explicit typecasts, so it works out ok.
*/
make_subset_tag(fo->fd);
}
- write_cid_charwidth_array(fo);
- write_fontdescriptor(fo->fd);
+ write_cid_charwidth_array(pdf, fo);
+ write_fontdescriptor(pdf, fo->fd);
- write_cid_fontdictionary(fo, f);
+ write_cid_fontdictionary(pdf, fo, f);
xfree(fo);
}
-void write_cid_fontdictionary(fo_entry * fo, internalfontnumber f)
+@ @c
+void write_cid_fontdictionary(PDF pdf, fo_entry * fo, internal_font_number f)
{
int i;
- fo->tounicode_objnum = write_cid_tounicode(fo, f);
+ fo->tounicode_objnum = write_cid_tounicode(pdf, fo, f);
- pdf_begin_dict(fo->fo_objnum, 1);
- pdf_puts("/Type /Font\n");
- pdf_puts("/Subtype /Type0\n");
- pdf_puts("/Encoding /Identity-H\n");
- write_fontname(fo->fd, "BaseFont");
- i = pdf_new_objnum();
- pdf_printf("/DescendantFonts [%i 0 R]\n", i);
+ pdf_begin_dict(pdf, fo->fo_objnum, 1);
+ pdf_puts(pdf, "/Type /Font\n");
+ pdf_puts(pdf, "/Subtype /Type0\n");
+ pdf_puts(pdf, "/Encoding /Identity-H\n");
+ write_fontname(pdf, fo->fd, "BaseFont");
+ i = pdf_new_objnum(pdf);
+ pdf_printf(pdf, "/DescendantFonts [%i 0 R]\n", i);
/* todo: the ToUnicode CMap */
if (fo->tounicode_objnum != 0)
- pdf_printf("/ToUnicode %i 0 R\n", (int) fo->tounicode_objnum);
+ pdf_printf(pdf, "/ToUnicode %i 0 R\n", (int) fo->tounicode_objnum);
- pdf_end_dict();
+ pdf_end_dict(pdf);
- pdf_begin_dict(i, 1);
- pdf_puts("/Type /Font\n");
+ pdf_begin_dict(pdf, i, 1);
+ pdf_puts(pdf, "/Type /Font\n");
if (is_opentype(fo->fm) || is_type1(fo->fm)) {
- pdf_puts("/Subtype /CIDFontType0\n");
+ pdf_puts(pdf, "/Subtype /CIDFontType0\n");
} else {
- pdf_puts("/Subtype /CIDFontType2\n");
- pdf_printf("/CIDToGIDMap /Identity\n");
+ pdf_puts(pdf, "/Subtype /CIDFontType2\n");
+ pdf_printf(pdf, "/CIDToGIDMap /Identity\n");
}
- write_fontname(fo->fd, "BaseFont");
- pdf_printf("/FontDescriptor %i 0 R\n", (int) fo->fd->fd_objnum);
- pdf_printf("/W %i 0 R\n", (int) fo->cw_objnum);
- pdf_printf("/CIDSystemInfo <<\n");
- pdf_printf("/Registry (%s)\n",
+ write_fontname(pdf, fo->fd, "BaseFont");
+ pdf_printf(pdf, "/FontDescriptor %i 0 R\n", (int) fo->fd->fd_objnum);
+ pdf_printf(pdf, "/W %i 0 R\n", (int) fo->cw_objnum);
+ pdf_printf(pdf, "/CIDSystemInfo <<\n");
+ pdf_printf(pdf, "/Registry (%s)\n",
(font_cidregistry(f) ? font_cidregistry(f) : "Adobe"));
- pdf_printf("/Ordering (%s)\n",
+ pdf_printf(pdf, "/Ordering (%s)\n",
(font_cidordering(f) ? font_cidordering(f) : "Identity"));
- pdf_printf("/Supplement %u\n", (unsigned int) font_cidsupplement(f));
- pdf_printf(">>\n");
+ pdf_printf(pdf, "/Supplement %u\n", (unsigned int) font_cidsupplement(f));
+ pdf_printf(pdf, ">>\n");
/* I doubt there is anything useful that could be written here */
- /*
+#if 0
if (pdf_font_attr(fo->tex_font) != get_nullstr()) {
pdf_print(pdf_font_attr(fo->tex_font));
- pdf_puts("\n");
+ pdf_puts(pdf,"\n");
}
- */
- pdf_end_dict();
-
+#endif
+ pdf_end_dict(pdf);
}
diff --git a/Build/source/texk/web2c/luatexdir/font/writet1.c b/Build/source/texk/web2c/luatexdir/font/writet1.w
index 01881ccbb52..69ac40bac04 100644
--- a/Build/source/texk/web2c/luatexdir/font/writet1.c
+++ b/Build/source/texk/web2c/luatexdir/font/writet1.w
@@ -1,29 +1,30 @@
-/* writet1.c
-
- Copyright 1996-2006 Han The Thanh <thanh@pdftex.org>
- Copyright 2006-2009 Taco Hoekwater <taco@luatex.org>
-
- This file is part of LuaTeX.
-
- LuaTeX 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 2 of the License, or (at your
- option) any later version.
-
- LuaTeX 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 Lesser General Public
- License for more details.
-
- You should have received a copy of the GNU General Public License along
- with LuaTeX; if not, see <http://www.gnu.org/licenses/>. */
+% writet1.w
+%
+% Copyright 1996-2006 Han The Thanh <thanh@@pdftex.org>
+% Copyright 2006-2009 Taco Hoekwater <taco@@luatex.org>
+%
+% This file is part of LuaTeX.
+%
+% LuaTeX 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 2 of the License, or (at your
+% option) any later version.
+%
+% LuaTeX 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 Lesser General Public
+% License for more details.
+%
+% You should have received a copy of the GNU General Public License along
+% with LuaTeX; if not, see <http://www.gnu.org/licenses/>.
+
+@ @c
+static const char _svn_version[] =
+ "$Id: writet1.w 3584 2010-04-02 17:45:55Z hhenkel $ "
+"$URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.60.0/source/texk/web2c/luatexdir/font/writet1.w $";
#include "ptexlib.h"
#include <string.h>
-#include "luatex-api.h"
-
-static const char _svn_version[] =
- "$Id: writet1.c 2599 2009-06-25 10:35:26Z taco $ $URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.40.6/source/texk/web2c/luatexdir/font/writet1.c $";
#define t1_log(str) if(tracefilenames) tex_printf("%s", str)
#define get_length1() t1_length1 = t1_offset() - t1_save_offset
@@ -31,8 +32,8 @@ static const char _svn_version[] =
#define get_length3() t1_length3 = fixedcontent? t1_offset() - t1_save_offset : 0
#define save_offset() t1_save_offset = t1_offset()
-#define t1_putchar fb_putchar
-#define t1_offset fb_offset
+#define t1_putchar(A) fb_putchar(pdf,(A))
+#define t1_offset() fb_offset(pdf)
#define out_eexec_char t1_putchar
#define end_last_eexec_line() \
@@ -41,17 +42,18 @@ static const char _svn_version[] =
#define embed_all_glyphs(tex_font) fm_cur->all_glyphs
#define extra_charset() fm_cur->charset
#define update_subset_tag() \
- strncpy(fb_array + t1_fontname_offset, fm_cur->subset_tag, 6)
+ strncpy(pdf->fb_array + t1_fontname_offset, fm_cur->subset_tag, 6)
#define fixedcontent false
-integer t1_length1, t1_length2, t1_length3;
-static integer t1_save_offset;
-static integer t1_fontname_offset;
+int t1_length1, t1_length2, t1_length3;
+static int t1_save_offset;
+static int t1_fontname_offset;
static unsigned char *t1_buffer = NULL;
-static integer t1_size = 0;
-static integer t1_curbyte = 0;
+static int t1_size = 0;
+static int t1_curbyte = 0;
+@ @c
#define t1_read_file() \
readbinfile(t1_file,&t1_buffer,&t1_size)
#define t1_close() xfclose(t1_file,cur_file_name)
@@ -69,11 +71,12 @@ static integer t1_curbyte = 0;
#define t1_cleartomark() t1_prefix("cleartomark")
static unsigned char *enc_buffer = NULL;
-static integer enc_size = 0;
-static integer enc_curbyte = 0;
+static int enc_size = 0;
+static int enc_curbyte = 0;
-#define enc_open() \
- (enc_file = fopen((char *)nameoffile+1, FOPEN_RBIN_MODE))
+@ @c
+#define enc_open(a) \
+ (enc_file = fopen((char *)(a), FOPEN_RBIN_MODE))
#define enc_read_file() \
readbinfile(enc_file,&enc_buffer,&enc_size)
#define enc_close() xfclose(enc_file,cur_file_name)
@@ -83,6 +86,7 @@ static integer enc_curbyte = 0;
#define valid_code(c) (c >= 0 && c < 256)
#define fixedcontent false
+@ @c
static const char *standard_glyph_names[256] = {
/* 0x00 */
notdef, notdef, notdef, notdef, notdef, notdef, notdef, notdef, notdef,
@@ -140,6 +144,7 @@ static const char *standard_glyph_names[256] = {
"oslash", "oe", "germandbls", notdef, notdef, notdef, notdef
};
+@ @c
static fd_entry *fd_cur;
static char charstringname[] = "/CharStrings";
@@ -149,6 +154,7 @@ enum { ENC_STANDARD, ENC_BUILTIN } t1_encoding;
#define T1_BUF_SIZE 0x10
#define ENC_BUF_SIZE 0x1000
+@ @c
#define CS_HSTEM 1
#define CS_VSTEM 3
#define CS_VMOVETO 4
@@ -180,6 +186,7 @@ enum { ENC_STANDARD, ENC_BUILTIN } t1_encoding;
#define CS_2BYTE_MAX (CS_SETCURRENTPOINT + 1)
#define CS_MAX CS_2BYTE_MAX
+@ @c
typedef unsigned char byte;
typedef struct {
@@ -204,12 +211,14 @@ static unsigned short t1_cslen;
static short t1_lenIV;
static char enc_line[ENC_BUF_SIZE];
-/* define t1_line_ptr, t1_line_array & t1_line_limit */
-typedef char t1_line_entry;
+@ define |t1_line_ptr|, |t1_line_array|, and |t1_line_limit|
+@c
+#define t1_line_entry char
define_array(t1_line);
-/* define t1_buf_ptr, t1_buf_array & t1_buf_limit */
-typedef char t1_buf_entry;
+@ define |t1_buf_ptr|, |t1_buf_array|, and |t1_buf_limit|
+@c
+#define t1_buf_entry char
define_array(t1_buf);
static int cs_start;
@@ -222,9 +231,10 @@ static cs_entry *subr_tab;
static char *subr_array_start, *subr_array_end;
static int subr_max, subr_size, subr_size_pos;
-/* This list contains the begin/end tokens commonly used in the */
-/* /Subrs array of a Type 1 font. */
+@ This list contains the begin/end tokens commonly used in the
+/Subrs array of a Type 1 font.
+@c
static const char *cs_token_pairs_list[][2] = {
{" RD", "NP"},
{" -|", "|"},
@@ -232,6 +242,8 @@ static const char *cs_token_pairs_list[][2] = {
{" -|", "noaccess put"},
{NULL, NULL}
};
+
+@ @c
static const char **cs_token_pair;
static boolean t1_pfa, t1_cs, t1_scan, t1_eexec_encrypt, t1_synthetic;
@@ -241,16 +253,17 @@ static int last_hexbyte;
static FILE *t1_file;
static FILE *enc_file;
+@ @c
static void enc_getline(void)
{
char *p;
- int c;
+ char c;
restart:
if (enc_eof())
pdftex_fail("unexpected end of file");
p = enc_line;
do {
- c = enc_getchar();
+ c = (char) enc_getchar();
append_char_to_buf(c, p, enc_line, ENC_BUF_SIZE);
}
while (c != 10 && !enc_eof());
@@ -259,56 +272,34 @@ static void enc_getline(void)
goto restart;
}
-/* read encoding from .enc file, return glyph_names array, or pdffail() */
-
+@ read encoding from .enc file, return |glyph_names array|, or |pdffail()|
+@c
char **load_enc_file(char *enc_name)
{
int callback_id = 0;
int file_opened = 0;
- char *ftemp = NULL;
+
char buf[ENC_BUF_SIZE], *p, *r;
int i, names_count;
char **glyph_names;
- char *tempname;
- set_cur_file_name(enc_name);
- callback_id = callback_defined(find_enc_file_callback);
- if (callback_id > 0) {
- if (run_callback
- (callback_id, "S->S", (char *) (nameoffile + 1), &ftemp)) {
- if (ftemp != NULL && strlen(ftemp)) {
- free(nameoffile);
- namelength = strlen(ftemp);
- nameoffile = xmalloc(namelength + 2);
- strcpy((char *) (nameoffile + 1), ftemp);
- free(ftemp);
- } else {
- pdftex_fail("cannot find encoding file for reading");
- }
- }
- } else {
- ftemp = kpse_find_file((char *) (nameoffile + 1), kpse_enc_format, 0);
- if (ftemp == NULL) {
- pdftex_fail("cannot find encoding file for reading");
- } else {
- free(nameoffile);
- namelength = strlen(ftemp);
- nameoffile = xmalloc(namelength + 2);
- strcpy((char *) (nameoffile + 1), ftemp);
- free(ftemp);
- }
+
+ cur_file_name = luatex_find_file(enc_name, find_enc_file_callback);
+
+ if (cur_file_name == NULL) {
+ pdftex_fail("cannot find encoding file for reading");
}
callback_id = callback_defined(read_enc_file_callback);
enc_curbyte = 0;
enc_size = 0;
if (callback_id > 0) {
- if (run_callback(callback_id, "S->bSd", (char *) (nameoffile + 1),
+ if (run_callback(callback_id, "S->bSd", cur_file_name,
&file_opened, &enc_buffer, &enc_size)) {
if ((!file_opened) || enc_size == 0) {
pdftex_fail("cannot open encoding file for reading");
}
}
} else {
- if (!enc_open()) {
+ if (!enc_open(cur_file_name)) {
pdftex_fail("cannot open encoding file for reading");
}
enc_read_file();
@@ -319,9 +310,6 @@ char **load_enc_file(char *enc_name)
glyph_names[i] = (char *) notdef;
t1_log("{");
- tempname = xmalloc(namelength + 2);
- strcpy(tempname, (char *) (nameoffile + 1));
- set_cur_file_name(tempname);
t1_log(cur_file_name);
enc_getline();
if (*enc_line != '/' || (r = strchr(enc_line, '[')) == NULL) {
@@ -364,8 +352,8 @@ char **load_enc_file(char *enc_name)
return glyph_names;
}
-#if 0 /* unused */
-static void free_glyph_names(char **glyph_names)
+@ @c
+void free_glyph_names(char **glyph_names)
{
int i;
assert(glyph_names != NULL);
@@ -374,7 +362,6 @@ static void free_glyph_names(char **glyph_names)
xfree(glyph_names[i]);
xfree(glyph_names);
}
-#endif
static void t1_check_pfa(void)
@@ -425,32 +412,33 @@ static byte edecrypt(byte cipher)
byte plain;
if (t1_pfa) {
while (cipher == 10 || cipher == 13)
- cipher = t1_getbyte();
- last_hexbyte = cipher = (hexval(cipher) << 4) + hexval(t1_getbyte());
+ cipher = (byte) t1_getbyte();
+ last_hexbyte = cipher =
+ (byte) ((hexval(cipher) << 4) + hexval(t1_getbyte()));
}
- plain = (cipher ^ (t1_dr >> 8));
- t1_dr = (cipher + t1_dr) * t1_c1 + t1_c2;
+ plain = (byte) (cipher ^ (t1_dr >> 8));
+ t1_dr = (unsigned short) ((cipher + t1_dr) * t1_c1 + t1_c2);
return plain;
}
static byte cdecrypt(byte cipher, unsigned short *cr)
{
- const byte plain = (cipher ^ (*cr >> 8));
- *cr = (cipher + *cr) * t1_c1 + t1_c2;
+ const byte plain = (byte) (cipher ^ (*cr >> 8));
+ *cr = (unsigned short) ((cipher + *cr) * t1_c1 + t1_c2);
return plain;
}
static byte eencrypt(byte plain)
{
- const byte cipher = (plain ^ (t1_er >> 8));
- t1_er = (cipher + t1_er) * t1_c1 + t1_c2;
+ const byte cipher = (byte) (plain ^ (t1_er >> 8));
+ t1_er = (unsigned short) ((cipher + t1_er) * t1_c1 + t1_c2);
return cipher;
}
static byte cencrypt(byte plain, unsigned short *cr)
{
- const byte cipher = (plain ^ (*cr >> 8));
- *cr = (cipher + *cr) * t1_c1 + t1_c2;
+ const byte cipher = (byte) (plain ^ (*cr >> 8));
+ *cr = (unsigned short) ((cipher + *cr) * t1_c1 + t1_c2);
return cipher;
}
@@ -493,12 +481,13 @@ static boolean str_suffix(const char *begin_buf, const char *end_buf,
return s2 < s;
}
+@ @c
static void t1_getline(void)
{
int c, l, eexec_scan;
char *p;
static const char eexec_str[] = "currentfile eexec";
- static int eexec_len = 17; /* strlen(eexec_str) */
+ static int eexec_len = 17; /* |strlen(eexec_str)| */
restart:
if (t1_eof())
pdftex_fail("unexpected end of file");
@@ -511,73 +500,81 @@ static void t1_getline(void)
goto exit;
while (!t1_eof()) {
if (t1_in_eexec == 1)
- c = edecrypt(c);
+ c = edecrypt((byte) c);
alloc_array(t1_line, 1, T1_BUF_SIZE);
- append_char_to_buf(c, t1_line_ptr, t1_line_array, t1_line_limit);
+ {
+ char cc = (char) c;
+ append_char_to_buf(cc, t1_line_ptr, t1_line_array, t1_line_limit);
+ }
if (t1_in_eexec == 0 && eexec_scan >= 0 && eexec_scan < eexec_len) {
if (t1_line_array[eexec_scan] == eexec_str[eexec_scan])
eexec_scan++;
else
eexec_scan = -1;
}
- if (c == 10 || (t1_pfa && eexec_scan == eexec_len && c == 32))
+ if (c == 10 || c == 13
+ || (t1_pfa && eexec_scan == eexec_len && c == 32)) {
break;
+ }
if (t1_cs && t1_cslen == 0 && (t1_line_ptr - t1_line_array > 4) &&
(t1_suffix(" RD ") || t1_suffix(" -| "))) {
p = t1_line_ptr - 5;
while (*p != ' ')
p--;
- t1_cslen = l = t1_scan_num(p + 1, 0);
- cs_start = t1_line_ptr - t1_line_array; /* cs_start is an index now */
+ l = (int) t1_scan_num(p + 1, 0);
+ t1_cslen = (unsigned short) l;
+ cs_start = (int) (t1_line_ptr - t1_line_array); /* |cs_start| is an index now */
alloc_array(t1_line, l, T1_BUF_SIZE);
while (l-- > 0)
- *t1_line_ptr++ = edecrypt(t1_getbyte());
+ *t1_line_ptr++ = (t1_line_entry) edecrypt((byte) t1_getbyte());
}
c = t1_getbyte();
}
- alloc_array(t1_line, 2, T1_BUF_SIZE); /* append_eol can append 2 chars */
+ alloc_array(t1_line, 2, T1_BUF_SIZE); /* |append_eol| can append 2 chars */
append_eol(t1_line_ptr, t1_line_array, t1_line_limit);
if (t1_line_ptr - t1_line_array < 2)
goto restart;
if (eexec_scan == eexec_len)
t1_in_eexec = 1;
exit:
- /* ensure that t1_buf_array has as much room as t1_line_array */
+ /* ensure that |t1_buf_array| has as much room as |t1_line_array| */
t1_buf_ptr = t1_buf_array;
alloc_array(t1_buf, t1_line_limit, t1_line_limit);
}
-static void t1_putline(void)
+@ @c
+static void t1_putline(PDF pdf)
{
char *p = t1_line_array;
if (t1_line_ptr - t1_line_array <= 1)
return;
if (t1_eexec_encrypt) {
while (p < t1_line_ptr)
- t1_putchar(eencrypt(*p++));
+ t1_putchar((eight_bits) eencrypt((byte) * p++));
} else
while (p < t1_line_ptr)
- t1_putchar(*p++);
+ t1_putchar((eight_bits) * p++);
}
-static void t1_puts(const char *s)
+static void t1_puts(PDF pdf, const char *s)
{
if (s != t1_line_array)
strcpy(t1_line_array, s);
t1_line_ptr = strend(t1_line_array);
- t1_putline();
+ t1_putline(pdf);
}
-__attribute__ ((format(printf, 1, 2)))
-static void t1_printf(const char *fmt, ...)
+__attribute__ ((format(printf, 2, 3)))
+static void t1_printf(PDF pdf, const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
vsprintf(t1_line_array, fmt, args);
- t1_puts(t1_line_array);
+ t1_puts(pdf, t1_line_array);
va_end(args);
}
+@ @c
static void t1_init_params(const char *open_name_prefix)
{
t1_log(open_name_prefix);
@@ -607,14 +604,15 @@ static void t1_check_block_len(boolean decrypt)
return;
c = t1_getbyte();
if (decrypt)
- c = edecrypt(c);
- l = t1_block_length;
+ c = edecrypt((byte) c);
+ l = (int) t1_block_length;
if (!(l == 0 && (c == 10 || c == 13))) {
pdftex_fail("%i bytes more than expected were ignored", l + 1);
}
}
-static void t1_start_eexec(void)
+@ @c
+static void t1_start_eexec(PDF pdf)
{
int i;
assert(is_included(fd_cur->fm));
@@ -624,14 +622,14 @@ static void t1_start_eexec(void)
if (!t1_pfa)
t1_check_block_len(false);
for (t1_line_ptr = t1_line_array, i = 0; i < 4; i++) {
- edecrypt(t1_getbyte());
+ edecrypt((byte) t1_getbyte());
*t1_line_ptr++ = 0;
}
t1_eexec_encrypt = true;
- t1_putline(); /* to put the first four bytes */
+ t1_putline(pdf); /* to put the first four bytes */
}
-static void t1_stop_eexec(void)
+static void t1_stop_eexec(PDF pdf)
{
int c;
assert(is_included(fd_cur->fm));
@@ -641,10 +639,10 @@ static void t1_stop_eexec(void)
if (!t1_pfa)
t1_check_block_len(true);
else {
- c = edecrypt(t1_getbyte());
+ c = edecrypt((byte) t1_getbyte());
if (!(c == 10 || c == 13)) {
if (last_hexbyte == 0)
- t1_puts("00");
+ t1_puts(pdf, "00");
else
pdftex_fail("unexpected data after eexec");
}
@@ -653,17 +651,19 @@ static void t1_stop_eexec(void)
t1_in_eexec = 2;
}
-/* macros for various transforms; currently only slant and extend are used */
-
-#define do_xshift(x,a) {x[4]+=a;}
-#define do_yshift(x,a) {x[5]+=a;}
-#define do_xscale(x,a) {x[0]*=a; x[2]*=a; x[4]*=a;}
-#define do_yscale(x,a) {x[1]*=a; x[3]*=a; x[5]*=a;}
-#define do_extend(x,a) {do_xscale(x,a);}
-#define do_scale(x,a) {do_xscale(x,a); do_yscale(x,a);}
-#define do_slant(x,a) {x[0]+=x[1]*(a); x[2]+=x[3]*(a); x[4]+=x[5]*(a);}
-#define do_shear(x,a) {x[1]+=x[0]*(a); x[3]+=x[2]*(a); x[5]+=x[4]*(a);}
-#define do_rotate(x,a) \
+@ macros for various transforms; unused, left for reference
+
+@c
+#ifdef T1TRANSFORMMACROS
+# define do_xshift(x,a) {x[4]+=a;}
+# define do_yshift(x,a) {x[5]+=a;}
+# define do_xscale(x,a) {x[0]*=a; x[2]*=a; x[4]*=a;}
+# define do_yscale(x,a) {x[1]*=a; x[3]*=a; x[5]*=a;}
+# define do_extend(x,a) {do_xscale(x,a);}
+# define do_scale(x,a) {do_xscale(x,a); do_yscale(x,a);}
+# define do_slant(x,a) {x[0]+=x[1]*(a); x[2]+=x[3]*(a); x[4]+=x[5]*(a);}
+# define do_shear(x,a) {x[1]+=x[0]*(a); x[3]+=x[2]*(a); x[5]+=x[4]*(a);}
+# define do_rotate(x,a) \
{float t, u=cos(a), v=sin(a); \
t =x[0]*u+x[1]*-v; \
x[1] =x[0]*v+x[1]* u; x[0]=t; \
@@ -671,121 +671,31 @@ static void t1_stop_eexec(void)
x[3] =x[2]*v+x[3]* u; x[2]=t; \
t =x[4]*u+x[5]*-v; \
x[5] =x[4]*v+x[5]* u; x[4]=t;}
+#endif
-static void t1_modify_fm(void)
-{
- /*
- * font matrix is given as six numbers a0..a5, which stands for the matrix
- *
- * a0 a1 0
- * M = a2 a3 0
- * a4 a5 1
- *
- * ExtendFont is given as
- *
- * e 0 0
- * E = 0 1 0
- * 0 0 1
- *
- * SlantFont is given as
- *
- * 1 0 0
- * S = s 1 0
- * 0 0 1
- *
- * The slant transform must be done _before_ the extend transform
- * for compatibility!
- */
- float a[6];
- int i, c;
- char *p, *q, *r;
- if ((p = strchr(t1_line_array, '[')) == 0)
- if ((p = strchr(t1_line_array, '{')) == 0) {
- remove_eol(p, t1_line_array);
- pdftex_fail("FontMatrix: an array expected: `%s'", t1_line_array);
- }
- c = *p++; /* save the character '[' resp. '{' */
- strncpy(t1_buf_array, t1_line_array, (size_t) (p - t1_line_array));
- r = t1_buf_array + (p - t1_line_array);
- for (i = 0; i < 6; i++) {
- a[i] = t1_scan_num(p, &q);
- p = q;
- }
- if (fm_slant(fd_cur->fm) != 0)
- do_slant(a, fm_slant(fd_cur->fm) * 1E-3);
- if (fm_extend(fd_cur->fm) != 0)
- do_extend(a, fm_extend(fd_cur->fm) * 1E-3);
- for (i = 0; i < 6; i++) {
- sprintf(r, "%g ", a[i]);
- r = strend(r);
- }
- if (c == '[') {
- while (*p != ']' && *p != 0)
- p++;
- } else {
- while (*p != '}' && *p != 0)
- p++;
- }
- if (*p == 0) {
- remove_eol(p, t1_line_array);
- pdftex_fail
- ("FontMatrix: cannot find the corresponding character to '%c': `%s'",
- c, t1_line_array);
- }
- strcpy(r, p);
- strcpy(t1_line_array, t1_buf_array);
- t1_line_ptr = eol(t1_line_array);
-}
-
-static void t1_modify_italic(void)
-{
- float a;
- char *p, *r;
- if (fm_slant(fd_cur->fm) == 0)
- return;
- p = strchr(t1_line_array, ' ');
- strncpy(t1_buf_array, t1_line_array, (size_t) (p - t1_line_array + 1));
- a = t1_scan_num(p + 1, &r);
- a -= atan(fm_slant(fd_cur->fm) * 1E-3) * (180 / M_PI);
- sprintf(t1_buf_array + (p - t1_line_array + 1), "%g", a);
- strcpy(strend(t1_buf_array), r);
- strcpy(t1_line_array, t1_buf_array);
- t1_line_ptr = eol(t1_line_array);
- fd_cur->font_dim[ITALIC_ANGLE_CODE].val = round(a);
- fd_cur->font_dim[ITALIC_ANGLE_CODE].set = true;
-}
-
-static void t1_scan_keys(void)
+@ @c
+static void t1_scan_keys(PDF pdf)
{
int i, k;
char *p, *q, *r;
const key_entry *key;
- if (fm_extend(fd_cur->fm) != 0 || fm_slant(fd_cur->fm) != 0) {
- if (t1_prefix("/FontMatrix")) {
- t1_modify_fm();
- return;
- }
- if (t1_prefix("/ItalicAngle")) {
- t1_modify_italic();
- return;
- }
- }
if (t1_prefix("/FontType")) {
p = t1_line_array + strlen("FontType") + 1;
- if ((i = t1_scan_num(p, 0)) != 1)
+ if ((i = (int) t1_scan_num(p, 0)) != 1)
pdftex_fail("Type%d fonts unsupported by pdfTeX", i);
return;
}
- for (key = font_key; key - font_key < FONT_KEYS_NUM; key++) {
- if (key->t1name[0] != '\0' &&
- str_prefix(t1_line_array + 1, key->t1name))
+ for (key = (const key_entry *) font_key; key - font_key < FONT_KEYS_NUM;
+ key++) {
+ if (key->t1name[0] != '\0'
+ && str_prefix(t1_line_array + 1, key->t1name))
break;
}
if (key - font_key == FONT_KEYS_NUM)
return;
p = t1_line_array + strlen(key->t1name) + 1;
skip(p, ' ');
- if ((k = key - font_key) == FONTNAME_CODE) {
+ if ((k = (int) (key - font_key)) == FONTNAME_CODE) {
if (*p != '/') {
remove_eol(p, t1_line_array);
pdftex_fail("a name expected: `%s'", t1_line_array);
@@ -793,54 +703,47 @@ static void t1_scan_keys(void)
r = ++p; /* skip the slash */
for (q = t1_buf_array; *p != ' ' && *p != 10; *q++ = *p++);
*q = 0;
- if (fm_slant(fd_cur->fm) != 0) {
- sprintf(q, "-Slant_%i", (int) fm_slant(fd_cur->fm));
- q = strend(q);
- }
- if (fm_extend(fd_cur->fm) != 0) {
- sprintf(q, "-Extend_%i", (int) fm_extend(fd_cur->fm));
- }
xfree(fd_cur->fontname);
fd_cur->fontname = xstrdup(t1_buf_array);
- /* at this moment we cannot call make_subset_tag() yet, as the encoding
- * is not read; thus we mark the offset of the subset tag and write it
- * later */
+ /* at this moment we cannot call |make_subset_tag()| yet, as the encoding
+ is not read; thus we mark the offset of the subset tag and write it
+ later */
if (is_subsetted(fd_cur->fm)) {
assert(is_included(fd_cur->fm));
- t1_fontname_offset = t1_offset() + (r - t1_line_array);
+ t1_fontname_offset = (int) (t1_offset() + (r - t1_line_array));
strcpy(t1_buf_array, p);
sprintf(r, "ABCDEF+%s%s", fd_cur->fontname, t1_buf_array);
t1_line_ptr = eol(r);
}
return;
}
- if ((k == STEMV_CODE || k == FONTBBOX1_CODE)
- && (*p == '[' || *p == '{'))
+ if ((k == STEMV_CODE || k == FONTBBOX1_CODE) && (*p == '[' || *p == '{'))
p++;
if (k == FONTBBOX1_CODE) {
for (i = 0; i < 4; i++, k++) {
- fd_cur->font_dim[k].val = t1_scan_num(p, &r);
+ fd_cur->font_dim[k].val = (int) t1_scan_num(p, &r);
fd_cur->font_dim[k].set = true;
p = r;
}
return;
}
- fd_cur->font_dim[k].val = t1_scan_num(p, 0);
+ fd_cur->font_dim[k].val = (int) t1_scan_num(p, 0);
fd_cur->font_dim[k].set = true;
}
-static void t1_scan_param(void)
+@ @c
+static void t1_scan_param(PDF pdf)
{
static const char *lenIV = "/lenIV";
if (!t1_scan || *t1_line_array != '/')
return;
if (t1_prefix(lenIV)) {
- t1_lenIV = t1_scan_num(t1_line_array + strlen(lenIV), 0);
+ t1_lenIV = (short) t1_scan_num(t1_line_array + strlen(lenIV), 0);
if (t1_lenIV < 0)
pdftex_fail("negative value of lenIV is not supported");
return;
}
- t1_scan_keys();
+ t1_scan_keys(pdf);
}
static void copy_glyph_names(char **glyph_names, int a, int b)
@@ -854,13 +757,14 @@ static void copy_glyph_names(char **glyph_names, int a, int b)
}
}
-/* read encoding from Type1 font file, return glyph_names array, or pdffail() */
+@ read encoding from Type1 font file, return |glyph_names| array, or |pdffail()|
-static char **t1_builtin_enc(void)
+@c
+char **t1_builtin_enc(void)
{
int i, a, b, c, counter = 0;
char *r, *p, **glyph_names;
- /* At this moment "/Encoding" is the prefix of t1_line_array */
+ /* At this moment \.{/Encoding} is the prefix of |t1_line_array| */
glyph_names = xtalloc(256, char *);
for (i = 0; i < 256; i++)
glyph_names[i] = (char *) notdef;
@@ -878,20 +782,21 @@ static char **t1_builtin_enc(void)
("cannot subset font (unknown predefined encoding `%s')",
t1_buf_array);
}
- /* At this moment "/Encoding" is the prefix of t1_line_array, and the encoding is
- * not a predefined encoding.
- *
- * We have two possible forms of Encoding vector. The first case is
- *
- * /Encoding [/a /b /c...] readonly def
- *
- * and the second case can look like
- *
- * /Encoding 256 array 0 1 255 {1 index exch /.notdef put} for
- * dup 0 /x put
- * dup 1 /y put
- * ...
- * readonly def
+ /* At this moment \.{/Encoding} is the prefix of |t1_line_array|, and the encoding is
+ not a predefined encoding.
+
+ We have two possible forms of Encoding vector. The first case is
+
+ \.{/Encoding [/a /b /c...] readonly def}
+
+ and the second case can look like
+
+ {\obeylines
+ \.{/Encoding 256 array 0 1 255 {1 index exch /.notdef put} for}
+ \.{dup 0 /x put}
+ \.{dup 1 /y put}
+ \.{...}
+ \.{readonly def}}
*/
t1_encoding = ENC_BUILTIN;
if (t1_prefix("/Encoding [") || t1_prefix("/Encoding[")) { /* the first case */
@@ -911,8 +816,7 @@ static char **t1_builtin_enc(void)
counter++;
}
if (*r != 10 && *r != '%') {
- if (str_prefix(r, "] def")
- || str_prefix(r, "] readonly def"))
+ if (str_prefix(r, "] def") || str_prefix(r, "] readonly def"))
break;
else {
remove_eol(r, t1_line_array);
@@ -932,7 +836,7 @@ static char **t1_builtin_enc(void)
p = t1_line_array;
}
/*
- check for `dup <index> <glyph> put'
+ check for \.{dup <index> <glyph> put}
*/
if (sscanf(p, "dup %i%256s put", &i, t1_buf_array) == 2 &&
*t1_buf_array == '/' && valid_code(i)) {
@@ -942,7 +846,7 @@ static char **t1_builtin_enc(void)
skip(p, ' ');
}
/*
- check for `dup dup <to> exch <from> get put'
+ check for \.{dup dup <to> exch <from> get put}
*/
else if (sscanf(p, "dup dup %i exch %i get put", &b, &a) == 2
&& valid_code(a) && valid_code(b)) {
@@ -951,7 +855,7 @@ static char **t1_builtin_enc(void)
skip(p, ' ');
}
/*
- check for `dup dup <from> <size> getinterval <to> exch putinterval'
+ check for \.{dup dup <from> <size> getinterval <to> exch putinterval}
*/
else if (sscanf
(p, "dup dup %i %i getinterval %i exch putinterval",
@@ -963,7 +867,7 @@ static char **t1_builtin_enc(void)
skip(p, ' ');
}
/*
- check for `def' or `readonly def'
+ check for \.{def} or \.{readonly def}
*/
else if ((p == t1_line_array || (p > t1_line_array && p[-1] == ' '))
&& strcmp(p, "def\n") == 0)
@@ -982,92 +886,92 @@ static char **t1_builtin_enc(void)
}
-static void t1_check_end(void)
+@
+@c
+static void t1_check_end(PDF pdf)
{
if (t1_eof())
return;
t1_getline();
if (t1_prefix("{restore}"))
- t1_putline();
+ t1_putline(pdf);
}
+@
+@c
static boolean t1_open_fontfile(const char *open_name_prefix)
{
+ ff_entry *ff;
int callback_id = 0;
int file_opened = 0;
- char *ftemp = NULL;
- ff_entry *ff;
- ff = check_ff_exist(fd_cur->fm->ff_name, is_truetype(fd_cur->fm));
t1_curbyte = 0;
t1_size = 0;
- if (ff->ff_path != NULL) {
- callback_id = callback_defined(find_type1_file_callback);
- if (callback_id > 0) {
- if (run_callback(callback_id, "S->S", ff->ff_path, &ftemp)) {
- if (ftemp != NULL && strlen(ftemp)) {
- strcpy(ff->ff_path, ftemp);
- }
- }
- }
- callback_id = callback_defined(read_type1_file_callback);
- if (callback_id > 0) {
- if (run_callback(callback_id, "S->bSd", ff->ff_path,
- &file_opened, &t1_buffer, &t1_size)
- && file_opened && t1_size > 0) {
- cur_file_name = ff->ff_path;
- } else {
- set_cur_file_name(fd_cur->fm->ff_name);
- pdftex_warn("cannot open Type 1 font file for reading");
- return false;
- }
- } else {
- t1_file = xfopen(cur_file_name = ff->ff_path, FOPEN_RBIN_MODE);
- t1_read_file();
- t1_close();
+ ff = check_ff_exist(fd_cur->fm->ff_name, is_truetype(fd_cur->fm));
+ if (ff->ff_path == NULL) {
+ pdftex_fail("cannot open Type 1 font file for reading (%s)",
+ fd_cur->fm->ff_name);
+ return false;
+ }
+ cur_file_name = luatex_find_file(ff->ff_path, find_type1_file_callback);
+ if (cur_file_name == NULL) {
+ pdftex_fail("cannot open Type 1 font file for reading (%s)",
+ ff->ff_path);
+ return false;
+ }
+ callback_id = callback_defined(read_type1_file_callback);
+ if (callback_id > 0) {
+ if (!run_callback(callback_id, "S->bSd", cur_file_name,
+ &file_opened, &t1_buffer, &t1_size)
+ && file_opened && t1_size > 0) {
+ pdftex_warn("cannot open Type 1 font file for reading (%s)",
+ cur_file_name);
+ return false;
}
- recorder_record_input(ff->ff_path);
} else {
- set_cur_file_name(fd_cur->fm->ff_name);
- pdftex_fail("cannot open Type 1 font file for reading");
- return false;
+ t1_file = xfopen(cur_file_name, FOPEN_RBIN_MODE);
+ t1_read_file();
+ t1_close();
}
+ recorder_record_input(cur_file_name);
t1_init_params(open_name_prefix);
return true;
}
-static void t1_include(void)
+static void t1_include(PDF pdf)
{
do {
t1_getline();
- t1_scan_param();
- t1_putline();
+ t1_scan_param(pdf);
+ t1_putline(pdf);
}
while (t1_in_eexec == 0);
- t1_start_eexec();
+ t1_start_eexec(pdf);
do {
t1_getline();
- t1_scan_param();
- t1_putline();
+ t1_scan_param(pdf);
+ t1_putline(pdf);
}
while (!(t1_charstrings() || t1_subrs()));
t1_cs = true;
do {
t1_getline();
- t1_putline();
+ t1_putline(pdf);
}
while (!t1_end_eexec());
- t1_stop_eexec();
+ t1_stop_eexec(pdf);
if (fixedcontent) { /* copy 512 zeros (not needed for PDF) */
do {
t1_getline();
- t1_putline();
+ t1_putline(pdf);
}
while (!t1_cleartomark());
- t1_check_end(); /* write "{restore}if" if found */
+ t1_check_end(pdf); /* write "{restore}if" if found */
}
get_length3();
}
+@
+@c
#define check_subr(subr) \
if (subr >= subr_size || subr < 0) \
pdftex_fail("Subrs array: entry index out of range (%i)", subr);
@@ -1090,7 +994,7 @@ static void cs_store(boolean is_subr)
*t1_buf_ptr++ = *p++);
*t1_buf_ptr = 0;
if (is_subr) {
- subr = t1_scan_num(p + 1, 0);
+ subr = (int) t1_scan_num(p + 1, 0);
check_subr(subr);
ptr = subr_tab + subr;
} else {
@@ -1103,16 +1007,16 @@ static void cs_store(boolean is_subr)
else
ptr->name = xstrdup(t1_buf_array + 1);
}
- /* copy " RD " + cs data to t1_buf_array */
+ /* copy |" RD " + cs data| to |t1_buf_array| */
memcpy(t1_buf_array, t1_line_array + cs_start - 4,
(unsigned) (t1_cslen + 4));
- /* copy the end of cs data to t1_buf_array */
+ /* copy the end of cs data to |t1_buf_array| */
for (p = t1_line_array + cs_start + t1_cslen, t1_buf_ptr =
t1_buf_array + t1_cslen + 4; *p != 10; *t1_buf_ptr++ = *p++);
*t1_buf_ptr++ = 10;
if (is_subr && cs_token_pair == NULL)
cs_token_pair = check_cs_token_pair();
- ptr->len = t1_buf_ptr - t1_buf_array;
+ ptr->len = (unsigned short) (t1_buf_ptr - t1_buf_array);
ptr->cslen = t1_cslen;
xfree(ptr->data); /* mem leak? */
ptr->data = xtalloc(ptr->len, byte);
@@ -1120,12 +1024,14 @@ static void cs_store(boolean is_subr)
ptr->valid = true;
}
+@
+@c
#define store_subr() cs_store(true)
#define store_cs() cs_store(false)
#define CC_STACK_SIZE 24
-static integer cc_stack[CC_STACK_SIZE], *stack_ptr = cc_stack;
+static int cc_stack[CC_STACK_SIZE], *stack_ptr = cc_stack;
static cc_entry cc_tab[CS_MAX];
static boolean is_cc_init = false;
@@ -1141,22 +1047,6 @@ static boolean is_cc_init = false;
goto cs_error; \
}
-/*
-static integer cc_get(integer index)
-{
- if (index < 0) {
- if (stack_ptr + index < cc_stack )
- stack_error(stack_ptr - cc_stack + index);
- return *(stack_ptr + index);
- }
- else {
- if (cc_stack + index >= stack_ptr)
- stack_error(index);
- return cc_stack[index];
- }
-}
-*/
-
#define cc_get(N) ((N) < 0 ? *(stack_ptr + (N)) : *(cc_stack + (N)))
#define cc_push(V) *stack_ptr++ = V
@@ -1185,9 +1075,9 @@ static void cc_init(void)
set_cc(CS_CLOSEPATH, false, 0, true);
set_cc(CS_CALLSUBR, false, 1, false);
set_cc(CS_RETURN, false, 0, false);
- /*
+#if 0
set_cc(CS_ESCAPE, false, 0, false);
- */
+#endif
set_cc(CS_HSBW, true, 2, true);
set_cc(CS_ENDCHAR, false, 0, true);
set_cc(CS_RMOVETO, true, 2, true);
@@ -1206,12 +1096,14 @@ static void cc_init(void)
is_cc_init = true;
}
+@
+@c
#define cs_getchar() cdecrypt(*data++, &cr)
#define mark_subr(n) cs_mark(0, n)
#define mark_cs(s) cs_mark(s, 0)
-__attribute__ ((format(printf, 3, 4)))
+__attribute__ ((noreturn, format(printf, 3, 4)))
static void cs_fail(const char *cs_name, int subr, const char *fmt, ...)
{
char buf[SMALL_BUF_SIZE];
@@ -1225,7 +1117,8 @@ static void cs_fail(const char *cs_name, int subr, const char *fmt, ...)
pdftex_fail("CharString (/%s): %s", cs_name, buf);
}
-/* fix a return-less subr by appending CS_RETURN */
+@ fix a return-less subr by appending |CS_RETURN|
+@c
static void append_cs_return(cs_entry * ptr)
{
unsigned short cr;
@@ -1233,7 +1126,7 @@ static void append_cs_return(cs_entry * ptr)
byte *p, *q, *data, *new_data;
assert(ptr != NULL && ptr->valid && ptr->used);
- /* decrypt the cs data to t1_buf_array, append CS_RETURN */
+ /* decrypt the cs data to |t1_buf_array|, append |CS_RETURN| */
p = (byte *) t1_buf_array;
data = ptr->data + 4;
cr = 4330;
@@ -1241,32 +1134,34 @@ static void append_cs_return(cs_entry * ptr)
*p++ = cs_getchar();
*p = CS_RETURN;
- /* encrypt the new cs data to new_data */
- new_data = xtalloc(ptr->len + 1, byte);
+ /* encrypt the new cs data to |new_data| */
+ new_data = xtalloc((unsigned) (ptr->len + 1), byte);
memcpy(new_data, ptr->data, 4);
p = new_data + 4;
q = (byte *) t1_buf_array;
cr = 4330;
for (i = 0; i < ptr->cslen + 1; i++)
*p++ = cencrypt(*q++, &cr);
- memcpy(p, ptr->data + 4 + ptr->cslen, ptr->len - ptr->cslen - 4);
+ memcpy(p, ptr->data + 4 + ptr->cslen, (size_t) (ptr->len - ptr->cslen - 4));
- /* update *ptr */
+ /* update |*ptr| */
xfree(ptr->data);
ptr->data = new_data;
ptr->len++;
ptr->cslen++;
}
+@
+@c
static void cs_mark(const char *cs_name, int subr)
{
byte *data;
int i, b, cs_len;
int last_cmd = 0;
- integer a, a1, a2;
+ int a, a1, a2;
unsigned short cr;
- static integer lastargOtherSubr3 = 3; /* the argument of last call to
- OtherSubrs[3] */
+ static int lastargOtherSubr3 = 3; /* the argument of last call to
+ OtherSubrs[3] */
cs_entry *ptr;
cc_entry *cc;
if (cs_name == NULL) {
@@ -1318,7 +1213,7 @@ static void cs_mark(const char *cs_name, int subr)
a |= (cs_getchar() & 0xff) << 16;
a |= (cs_getchar() & 0xff) << 8;
a |= (cs_getchar() & 0xff) << 0;
- if (sizeof(integer) > 4 && (a & 0x80000000))
+ if (sizeof(int) > 4 && (a & 0x80000000))
a |= ~0x7FFFFFFF;
}
cc_push(a);
@@ -1401,16 +1296,15 @@ static void cs_mark(const char *cs_name, int subr)
ptr->used = false;
}
-/**********************************************************************/
-/* AVL search tree for glyph code by glyph name */
-
-static int comp_t1_glyphs(const void *pa, const void *pb, void *p)
+@ AVL search tree for glyph code by glyph name
+@c
+static int comp_t1_glyphs(const void *pa, const void *pb, void *p
+ __attribute__ ((unused)))
{
- (void) p;
- return strcmp(*((const char * const *) pa), *((const char * const *) pb));
+ return strcmp(*(const char *const *) pa, *(const char *const *) pb);
}
-static struct avl_table *create_t1_glyph_tree(char **glyph_names)
+struct avl_table *create_t1_glyph_tree(char **glyph_names)
{
int i;
void **aa;
@@ -1420,7 +1314,7 @@ static struct avl_table *create_t1_glyph_tree(char **glyph_names)
for (i = 0; i < 256; i++) {
if (glyph_names[i] != notdef &&
(char **) avl_find(gl_tree, &glyph_names[i]) == NULL) {
- /* no strdup here, just point to the glyph_names array members */
+ /* no |strdup| here, just point to the |glyph_names| array members */
aa = avl_probe(gl_tree, &glyph_names[i]);
assert(aa != NULL);
}
@@ -1428,15 +1322,15 @@ static struct avl_table *create_t1_glyph_tree(char **glyph_names)
return gl_tree;
}
-static void destroy_t1_glyph_tree(struct avl_table *gl_tree)
+void destroy_t1_glyph_tree(struct avl_table *gl_tree)
{
assert(gl_tree != NULL);
avl_destroy(gl_tree, NULL);
}
-/**********************************************************************/
-
-static void t1_subset_ascii_part(void)
+@
+@c
+static void t1_subset_ascii_part(PDF pdf)
{
int j, *p;
char *glyph, **gg, **glyph_names;
@@ -1447,8 +1341,8 @@ static void t1_subset_ascii_part(void)
assert(fd_cur->gl_tree != NULL);
t1_getline();
while (!t1_prefix("/Encoding")) {
- t1_scan_param();
- t1_putline();
+ t1_scan_param(pdf);
+ t1_putline(pdf);
t1_getline();
}
glyph_names = t1_builtin_enc();
@@ -1456,7 +1350,7 @@ static void t1_subset_ascii_part(void)
if (is_subsetted(fd_cur->fm)) {
assert(is_included(fd_cur->fm));
if (fd_cur->tx_tree != NULL) {
- /* take over collected non-reencoded characters from TeX */
+ /* take over collected non-reencoded characters from \TeX */
avl_t_init(&t, fd_cur->tx_tree);
for (p = (int *) avl_t_first(&t, fd_cur->tx_tree); p != NULL;
p = (int *) avl_t_next(&t)) {
@@ -1469,42 +1363,45 @@ static void t1_subset_ascii_part(void)
}
make_subset_tag(fd_cur);
assert(t1_fontname_offset != 0);
- strncpy(fb_array + t1_fontname_offset, fd_cur->subset_tag, 6);
+ strncpy(pdf->fb_array + t1_fontname_offset, fd_cur->subset_tag, 6);
}
- /* now really all glyphs needed from this font are in the fd_cur->gl_tree */
+ /* now really all glyphs needed from this font are in the |fd_cur->gl_tree| */
if (t1_encoding == ENC_STANDARD)
- t1_puts("/Encoding StandardEncoding def\n");
+ t1_puts(pdf, "/Encoding StandardEncoding def\n");
else {
t1_puts
- ("/Encoding 256 array\n0 1 255 {1 index exch /.notdef put} for\n");
+ (pdf,
+ "/Encoding 256 array\n0 1 255 {1 index exch /.notdef put} for\n");
gl_tree = create_t1_glyph_tree(glyph_names);
avl_t_init(&t, fd_cur->gl_tree);
j = 0;
for (glyph = (char *) avl_t_first(&t, fd_cur->gl_tree); glyph != NULL;
glyph = (char *) avl_t_next(&t)) {
if ((gg = (char **) avl_find(gl_tree, &glyph)) != NULL) {
- t1_printf("dup %i /%s put\n", (int) (gg - glyph_names), *gg);
+ t1_printf(pdf, "dup %i /%s put\n", (int) (gg - glyph_names),
+ *gg);
j++;
}
}
destroy_t1_glyph_tree(gl_tree);
if (j == 0)
- /* We didn't mark anything for the Encoding array. */
- /* We add "dup 0 /.notdef put" for compatibility */
- /* with Acrobat 5.0. */
- t1_puts("dup 0 /.notdef put\n");
- t1_puts("readonly def\n");
+ /* We didn't mark anything for the Encoding array.
+ We add \.{dup 0 /.notdef put} for compatibility with Acrobat 5.0. */
+ t1_puts(pdf, "dup 0 /.notdef put\n");
+ t1_puts(pdf, "readonly def\n");
}
do {
t1_getline();
- t1_scan_param();
+ t1_scan_param(pdf);
if (!t1_prefix("/UniqueID")) /* ignore UniqueID for subsetted fonts */
- t1_putline();
+ t1_putline(pdf);
}
while (t1_in_eexec == 0);
}
+@
+@c
static void cs_init(void)
{
cs_ptr = cs_tab = NULL;
@@ -1526,15 +1423,17 @@ static void init_cs_entry(cs_entry * cs)
cs->valid = false;
}
-static void t1_read_subrs(void)
+@
+@c
+static void t1_read_subrs(PDF pdf)
{
int i, s;
cs_entry *ptr;
t1_getline();
while (!(t1_charstrings() || t1_subrs())) {
- t1_scan_param();
+ t1_scan_param(pdf);
if (!t1_prefix("/UniqueID")) /* ignore UniqueID for subsetted fonts */
- t1_putline();
+ t1_putline(pdf);
t1_getline();
}
found:
@@ -1543,14 +1442,14 @@ static void t1_read_subrs(void)
if (!t1_subrs())
return;
subr_size_pos = strlen("/Subrs") + 1;
- /* subr_size_pos points to the number indicating dict size after "/Subrs" */
- subr_size = t1_scan_num(t1_line_array + subr_size_pos, 0);
+ /* |subr_size_pos| points to the number indicating dict size after |"Subrs"| */
+ subr_size = (int) t1_scan_num(t1_line_array + subr_size_pos, 0);
if (subr_size == 0) {
while (!t1_charstrings())
t1_getline();
return;
}
- subr_tab = xtalloc(subr_size, cs_entry);
+ subr_tab = xtalloc((unsigned) subr_size, cs_entry);
for (ptr = subr_tab; ptr - subr_tab < subr_size; ptr++)
init_cs_entry(ptr);
subr_array_start = xstrdup(t1_line_array);
@@ -1563,9 +1462,9 @@ static void t1_read_subrs(void)
for (i = 0; i < subr_size && i < 4; i++)
subr_tab[i].used = true;
/* the end of the Subrs array might have more than one line so we need to
- concatnate them to subr_array_end. Unfortunately some fonts don't have
+ concatenate them to |subr_array_end|. Unfortunately some fonts don't have
the Subrs array followed by the CharStrings dict immediately (synthetic
- fonts). If we cannot find CharStrings in next POST_SUBRS_SCAN lines then
+ fonts). If we cannot find CharStrings in next |POST_SUBRS_SCAN| lines then
we will treat the font as synthetic and ignore everything until next
Subrs is found
*/
@@ -1575,7 +1474,7 @@ static void t1_read_subrs(void)
for (i = 0; i < POST_SUBRS_SCAN; i++) {
if (t1_charstrings())
break;
- s += t1_line_ptr - t1_line_array;
+ s = (int) (s + t1_line_ptr - t1_line_array);
alloc_array(t1_buf, s, T1_BUF_SIZE);
strcat(t1_buf_array, t1_line_array);
t1_getline();
@@ -1598,10 +1497,12 @@ static void t1_read_subrs(void)
}
}
-#define t1_subr_flush() t1_flush_cs(true)
-#define t1_cs_flush() t1_flush_cs(false)
+@
+@c
+#define t1_subr_flush() t1_flush_cs(pdf, true)
+#define t1_cs_flush() t1_flush_cs(pdf, false)
-static void t1_flush_cs(boolean is_subr)
+static void t1_flush_cs(PDF pdf, boolean is_subr)
{
char *p;
byte *r, *return_cs = NULL;
@@ -1632,16 +1533,16 @@ static void t1_flush_cs(boolean is_subr)
sprintf(t1_line_ptr, "%u", count);
strcat(t1_line_ptr, p);
t1_line_ptr = eol(t1_line_array);
- t1_putline();
+ t1_putline(pdf);
cs_len = 0; /* for -Wall */
- /* create return_cs to replace unsused subr's */
+ /* create |return_cs| to replace unsused subr's */
if (is_subr) {
cr = 4330;
cs_len = 0;
- /* at this point we have t1_lenIV >= 0;
- * a negative value would be caught in t1_scan_param() */
- return_cs = xtalloc(t1_lenIV + 1, byte);
+ /* at this point we have |t1_lenIV >= 0;|
+ a negative value would be caught in |t1_scan_param| */
+ return_cs = xtalloc((unsigned) (t1_lenIV + 1), byte);
for (cs_len = 0, r = return_cs; cs_len < t1_lenIV; cs_len++, r++)
*r = cencrypt(0x00, &cr);
*r = cencrypt(CS_RETURN, &cr);
@@ -1658,19 +1559,19 @@ static void t1_flush_cs(boolean is_subr)
p = strend(t1_line_array);
memcpy(p, ptr->data, ptr->len);
t1_line_ptr = p + ptr->len;
- t1_putline();
+ t1_putline(pdf);
} else {
- /* replace unsused subr's by return_cs */
+ /* replace unsused subr's by |return_cs| */
if (is_subr) {
sprintf(t1_line_array, "dup %li %u%s ", (long int) (ptr - tab),
cs_len, cs_token_pair[0]);
p = strend(t1_line_array);
memcpy(p, return_cs, cs_len);
t1_line_ptr = p + cs_len;
- t1_putline();
+ t1_putline(pdf);
sprintf(t1_line_array, " %s", cs_token_pair[1]);
t1_line_ptr = eol(t1_line_array);
- t1_putline();
+ t1_putline(pdf);
}
}
xfree(ptr->data);
@@ -1679,7 +1580,7 @@ static void t1_flush_cs(boolean is_subr)
}
sprintf(t1_line_array, "%s", line_end);
t1_line_ptr = eol(t1_line_array);
- t1_putline();
+ t1_putline(pdf);
if (is_subr)
xfree(return_cs);
xfree(tab);
@@ -1687,6 +1588,8 @@ static void t1_flush_cs(boolean is_subr)
xfree(line_end);
}
+@
+@c
static void t1_mark_glyphs(void)
{
char *glyph;
@@ -1714,19 +1617,22 @@ static void t1_mark_glyphs(void)
if (subr_tab != NULL)
for (subr_max = -1, ptr = subr_tab; ptr - subr_tab < subr_size; ptr++)
if (ptr->used && ptr - subr_tab > subr_max)
- subr_max = ptr - subr_tab;
+ subr_max = (int) (ptr - subr_tab);
}
-static void t1_subset_charstrings(void)
+@
+@c
+static void t1_subset_charstrings(PDF pdf)
{
cs_entry *ptr;
- cs_size_pos = strstr(t1_line_array, charstringname) + strlen(charstringname)
- - t1_line_array + 1;
- /* cs_size_pos points to the number indicating
- dict size after "/CharStrings" */
- cs_size = t1_scan_num(t1_line_array + cs_size_pos, 0);
- cs_ptr = cs_tab = xtalloc(cs_size, cs_entry);
+ cs_size_pos = (int) (strstr(t1_line_array,
+ charstringname) + strlen(charstringname) -
+ t1_line_array + 1);
+ /* |cs_size_pos| points to the number indicating
+ dict size after |"/CharStrings"| */
+ cs_size = (int) t1_scan_num(t1_line_array + cs_size_pos, 0);
+ cs_ptr = cs_tab = xtalloc((unsigned) cs_size, cs_entry);
for (ptr = cs_tab; ptr - cs_tab < cs_size; ptr++)
init_cs_entry(ptr);
cs_notdef = NULL;
@@ -1750,36 +1656,40 @@ static void t1_subset_charstrings(void)
t1_cs_flush();
}
-static void t1_subset_end(void)
+@
+@c
+static void t1_subset_end(PDF pdf)
{
- if (t1_synthetic) { /* copy to "dup /FontName get exch definefont pop" */
+ if (t1_synthetic) { /* copy to \.{dup /FontName get exch definefont pop} */
while (!strstr(t1_line_array, "definefont")) {
t1_getline();
- t1_putline();
+ t1_putline(pdf);
}
while (!t1_end_eexec())
t1_getline(); /* ignore the rest */
- t1_putline(); /* write "mark currentfile closefile" */
+ t1_putline(pdf); /* write \.{mark currentfile closefile} */
} else
- while (!t1_end_eexec()) { /* copy to "mark currentfile closefile" */
+ while (!t1_end_eexec()) { /* copy to \.{mark currentfile closefile} */
t1_getline();
- t1_putline();
+ t1_putline(pdf);
}
- t1_stop_eexec();
+ t1_stop_eexec(pdf);
if (fixedcontent) { /* copy 512 zeros (not needed for PDF) */
while (!t1_cleartomark()) {
t1_getline();
- t1_putline();
+ t1_putline(pdf);
}
- if (!t1_synthetic) /* don't check "{restore}if" for synthetic fonts */
- t1_check_end(); /* write "{restore}if" if found */
+ if (!t1_synthetic) /* don't check \.{{restore}if} for synthetic fonts */
+ t1_check_end(pdf); /* write \.{{restore}if} if found */
}
get_length3();
}
-void writet1(fd_entry * fd)
+@
+@c
+void writet1(PDF pdf, fd_entry * fd)
{
- fd_cur = fd; /* fd_cur is global inside writet1.c */
+ fd_cur = fd; /* |fd_cur| is global inside \.{writet1.w} */
assert(fd_cur->fm != NULL);
assert(is_type1(fd->fm));
assert(is_included(fd->fm));
@@ -1788,7 +1698,7 @@ void writet1(fd_entry * fd)
if (!is_subsetted(fd_cur->fm)) { /* include entire font */
if (!(fd->ff_found = t1_open_fontfile("<<")))
return;
- t1_include();
+ t1_include(pdf);
t1_close_font_file(">>");
xfree(t1_buffer);
return;
@@ -1796,17 +1706,19 @@ void writet1(fd_entry * fd)
/* partial downloading */
if (!(fd->ff_found = t1_open_fontfile("<")))
return;
- t1_subset_ascii_part();
- t1_start_eexec();
+ t1_subset_ascii_part(pdf);
+ t1_start_eexec(pdf);
cc_init();
cs_init();
- t1_read_subrs();
- t1_subset_charstrings();
- t1_subset_end();
+ t1_read_subrs(pdf);
+ t1_subset_charstrings(pdf);
+ t1_subset_end(pdf);
t1_close_font_file(">");
xfree(t1_buffer);
}
+@
+@c
void t1_free(void)
{
xfree(t1_line_array);
diff --git a/Build/source/texk/web2c/luatexdir/font/writet3.c b/Build/source/texk/web2c/luatexdir/font/writet3.w
index 30dab2e8b14..9301ba5f4f3 100644
--- a/Build/source/texk/web2c/luatexdir/font/writet3.c
+++ b/Build/source/texk/web2c/luatexdir/font/writet3.w
@@ -1,31 +1,32 @@
-/* writet3.c
-
- Copyright 1996-2006 Han The Thanh <thanh@pdftex.org>
- Copyright 2006-2008 Taco Hoekwater <taco@luatex.org>
+% writet3.w
- This file is part of LuaTeX.
+% Copyright 1996-2006 Han The Thanh <thanh@@pdftex.org>
+% Copyright 2006-2010 Taco Hoekwater <taco@@luatex.org>
- LuaTeX 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 2 of the License, or (at your
- option) any later version.
+% This file is part of LuaTeX.
- LuaTeX 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 Lesser General Public
- License for more details.
+% LuaTeX 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 2 of the License, or (at your
+% option) any later version.
- You should have received a copy of the GNU General Public License along
- with LuaTeX; if not, see <http://www.gnu.org/licenses/>. */
+% LuaTeX 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 Lesser General Public
+% License for more details.
+
+% You should have received a copy of the GNU General Public License along
+% with LuaTeX; if not, see <http://www.gnu.org/licenses/>.
+
+@ @c
+static const char _svn_version[] =
+ "$Id: writet3.w 3584 2010-04-02 17:45:55Z hhenkel $ "
+"$URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.60.0/source/texk/web2c/luatexdir/font/writet3.w $";
#include "ptexlib.h"
#include <kpathsea/tex-glyph.h>
#include <kpathsea/magstep.h>
#include <string.h>
-#include "luatexfont.h"
-
-static const char _svn_version[] =
- "$Id: writet3.c 2271 2009-04-12 23:42:21Z oneiros $ $URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.40.6/source/texk/web2c/luatexdir/font/writet3.c $";
#define T3_BUF_SIZE 1024
@@ -35,24 +36,25 @@ define_array(t3_line);
FILE *t3_file;
static boolean t3_image_used;
-static integer t3_char_procs[256];
+static int t3_char_procs[256];
static float t3_char_widths[256];
static int t3_glyph_num;
static float t3_font_scale;
-static integer t3_b0, t3_b1, t3_b2, t3_b3;
+static int t3_b0, t3_b1, t3_b2, t3_b3;
static boolean is_pk_font;
/* not static because used by pkin.c */
unsigned char *t3_buffer = NULL;
-integer t3_size = 0;
-integer t3_curbyte = 0;
+int t3_size = 0;
+int t3_curbyte = 0;
#define t3_check_eof() \
if (t3_eof()) \
pdftex_fail("unexpected end of file");
-
-static void update_bbox(integer llx, integer lly, integer urx, integer ury,
+@
+@c
+static void update_bbox(int llx, int lly, int urx, int ury,
boolean is_first_glyph)
{
if (is_first_glyph) {
@@ -72,59 +74,54 @@ static void update_bbox(integer llx, integer lly, integer urx, integer ury,
}
}
-static integer get_pk_font_scale(internalfontnumber f)
+static int get_pk_font_scale(internal_font_number f, int precision,
+ int scale_factor)
{
return
- divide_scaled(pk_scale_factor,
- divide_scaled(pdf_font_size(f), one_hundred_bp,
- fixed_decimal_digits + 2), 0);
+ divide_scaled(scale_factor,
+ divide_scaled(font_size(f), one_hundred_bp,
+ precision + 2), 0);
}
-static integer pk_char_width(internalfontnumber f, scaled w)
+static int pk_char_width(internal_font_number f, scaled w, int precision,
+ int scale_factor)
{
return
- divide_scaled(divide_scaled(w, pdf_font_size(f), 7),
- get_pk_font_scale(f), 0);
+ divide_scaled(divide_scaled(w, font_size(f), 7),
+ get_pk_font_scale(f, precision, scale_factor), 0);
}
-scaled get_pk_char_width(internalfontnumber f, scaled w)
-{
- return (get_pk_font_scale(f) / 100000.0) *
- (pk_char_width(f, w) / 100.0) * pdf_font_size(f);
-}
-
-static boolean writepk(internalfontnumber f)
+@
+@c
+static boolean writepk(PDF pdf, internal_font_number f)
{
kpse_glyph_file_type font_ret;
- integer llx, lly, urx, ury;
- integer cw, rw, i, j;
+ int llx, lly, urx, ury;
+ int cw, rw, i, j;
halfword *row;
char *name;
char *ftemp = NULL;
chardesc cd;
boolean is_null_glyph, check_preamble;
- integer dpi;
+ int dpi;
int callback_id = 0;
int file_opened = 0;
- int mallocsize = 0;
- if (t3_buffer != NULL) {
- xfree(t3_buffer);
- t3_buffer = NULL;
- }
+ unsigned mallocsize = 0;
+ xfree(t3_buffer);
t3_curbyte = 0;
t3_size = 0;
callback_id = callback_defined(find_pk_file_callback);
if (callback_id > 0) {
- dpi = round(fixed_pk_resolution *
- (((float) pdf_font_size(f)) / font_dsize(f)));
+ dpi = round((float) pdf->pk_resolution *
+ (((float) font_size(f)) / (float) font_dsize(f)));
/* <base>.dpi/<fontname>.<tdpi>pk */
cur_file_name = font_name(f);
- mallocsize = strlen(cur_file_name) + 24 + 9;
+ mallocsize = (unsigned) (strlen(cur_file_name) + 24 + 9);
name = xmalloc(mallocsize);
- snprintf(name, mallocsize, "%ddpi/%s.%dpk", (int) fixed_pk_resolution,
- cur_file_name, (int) dpi);
+ snprintf(name, (size_t) mallocsize, "%ddpi/%s.%dpk",
+ (int) pdf->pk_resolution, cur_file_name, (int) dpi);
if (run_callback(callback_id, "S->S", name, &ftemp)) {
if (ftemp != NULL && strlen(ftemp)) {
free(name);
@@ -133,11 +130,11 @@ static boolean writepk(internalfontnumber f)
}
}
} else {
- dpi =
- kpse_magstep_fix(round
- (fixed_pk_resolution *
- (((float) pdf_font_size(f)) / font_dsize(f))),
- fixed_pk_resolution, NULL);
+ dpi = (int)
+ kpse_magstep_fix((unsigned) round
+ ((float) pdf->pk_resolution *
+ ((float) font_size(f) / (float) font_dsize(f))),
+ (unsigned) pdf->pk_resolution, NULL);
cur_file_name = font_name(f);
name = kpse_find_pk(cur_file_name, (unsigned) dpi, &font_ret);
if (name == NULL ||
@@ -167,14 +164,15 @@ static boolean writepk(internalfontnumber f)
if (tracefilenames)
tex_printf(" <%s", (char *) name);
cd.rastersize = 256;
- cd.raster = xtalloc(cd.rastersize, halfword);
+ cd.raster = xtalloc((unsigned long) cd.rastersize, halfword);
check_preamble = true;
while (readchar(check_preamble, &cd) != 0) {
check_preamble = false;
if (!pdf_char_marked(f, cd.charcode))
continue;
- t3_char_widths[cd.charcode] =
- pk_char_width(f, get_charwidth(f, cd.charcode));
+ t3_char_widths[cd.charcode] = (float)
+ pk_char_width(f, get_charwidth(f, cd.charcode),
+ pdf->decimal_digits, pdf->pk_scale_factor);
if (cd.cwidth < 1 || cd.cheight < 1) {
cd.xescape = cd.cwidth = round(t3_char_widths[cd.charcode] / 100.0);
cd.cheight = 1;
@@ -189,71 +187,65 @@ static boolean writepk(internalfontnumber f)
ury = cd.cheight + lly;
update_bbox(llx, lly, urx, ury, t3_glyph_num == 0);
t3_glyph_num++;
- pdf_new_dict(0, 0, 0);
- t3_char_procs[cd.charcode] = obj_ptr;
- pdf_begin_stream();
- pdf_print_real(t3_char_widths[cd.charcode], 2);
- pdf_printf(" 0 %i %i %i %i d1\n",
+ pdf_new_dict(pdf, obj_type_others, 0, 0);
+ t3_char_procs[cd.charcode] = pdf->obj_ptr;
+ pdf_begin_stream(pdf);
+ pdf_print_real(pdf, (int) t3_char_widths[cd.charcode], 2);
+ pdf_printf(pdf, " 0 %i %i %i %i d1\n",
(int) llx, (int) lly, (int) urx, (int) ury);
if (is_null_glyph)
goto end_stream;
- pdf_printf("q\n%i 0 0 %i %i %i cm\nBI\n", (int) cd.cwidth,
+ pdf_printf(pdf, "q\n%i 0 0 %i %i %i cm\nBI\n", (int) cd.cwidth,
(int) cd.cheight, (int) llx, (int) lly);
- pdf_printf("/W %i\n/H %i\n", (int) cd.cwidth, (int) cd.cheight);
- pdf_puts("/IM true\n/BPC 1\n/D [1 0]\nID ");
+ pdf_printf(pdf, "/W %i\n/H %i\n", (int) cd.cwidth, (int) cd.cheight);
+ pdf_puts(pdf, "/IM true\n/BPC 1\n/D [1 0]\nID ");
cw = (cd.cwidth + 7) / 8;
rw = (cd.cwidth + 15) / 16;
row = cd.raster;
for (i = 0; i < cd.cheight; i++) {
for (j = 0; j < rw - 1; j++) {
- pdfout(*row / 256);
- pdfout(*row % 256);
+ pdf_out(pdf, (unsigned char) (*row / 256));
+ pdf_out(pdf, (unsigned char) (*row % 256));
row++;
}
- pdfout(*row / 256);
+ pdf_out(pdf, (unsigned char) (*row / 256));
if (2 * rw == cw)
- pdfout(*row % 256);
+ pdf_out(pdf, (unsigned char) (*row % 256));
row++;
}
- pdf_puts("\nEI\nQ\n");
+ pdf_puts(pdf, "\nEI\nQ\n");
end_stream:
- pdf_end_stream();
+ pdf_end_stream(pdf);
}
xfree(cd.raster);
cur_file_name = NULL;
return true;
}
-void writet3(int objnum, internalfontnumber f)
+@
+@c
+void writet3(PDF pdf, internal_font_number f)
{
int i;
- integer wptr, eptr, cptr;
+ int wptr, eptr, cptr;
int first_char, last_char;
- integer pk_font_scale;
+ int pk_font_scale;
boolean is_notdef;
-
t3_glyph_num = 0;
t3_image_used = false;
for (i = 0; i < 256; i++) {
t3_char_procs[i] = 0;
t3_char_widths[i] = 0;
}
- pack_file_name(tex_font_name(f), get_nullstr(), maketexlstring(".pgc", 4));
- cur_file_name = makecstring(make_name_string());
is_pk_font = false;
- if (t3_buffer != NULL) {
- xfree(t3_buffer);
- t3_buffer = NULL;
- }
+ xfree(t3_buffer);
t3_curbyte = 0;
t3_size = 0;
- if (!writepk(f)) {
- cur_file_name = NULL;
+ if (!writepk(pdf, f))
return;
- }
for (i = font_bc(f); i <= font_ec(f); i++)
if (pdf_char_marked(f, i))
break;
@@ -262,76 +254,77 @@ void writet3(int objnum, internalfontnumber f)
if (pdf_char_marked(f, i))
break;
last_char = i;
- pdf_begin_dict(objnum, 1); /* Type 3 font dictionary */
- pdf_puts("/Type /Font\n/Subtype /Type3\n");
- pdf_printf("/Name /F%i\n", (int) f);
- if (pdf_font_attr(f) != get_nullstr()) {
- pdf_print(pdf_font_attr(f));
- pdf_puts("\n");
+ pdf_begin_dict(pdf, pdf_font_num(f), 1); /* Type 3 font dictionary */
+ pdf_puts(pdf, "/Type /Font\n/Subtype /Type3\n");
+ pdf_printf(pdf, "/Name /F%i\n", (int) f);
+ if (pdf_font_attr(f) != get_nullstr() && pdf_font_attr(f) != 0) {
+ pdf_print(pdf, pdf_font_attr(f));
+ pdf_puts(pdf, "\n");
}
if (is_pk_font) {
- pk_font_scale = get_pk_font_scale(f);
- pdf_puts("/FontMatrix [");
- pdf_print_real(pk_font_scale, 5);
- pdf_puts(" 0 0 ");
- pdf_print_real(pk_font_scale, 5);
- pdf_puts(" 0 0]\n");
+ pk_font_scale =
+ get_pk_font_scale(f, pdf->decimal_digits, pdf->pk_scale_factor);
+ pdf_puts(pdf, "/FontMatrix [");
+ pdf_print_real(pdf, pk_font_scale, 5);
+ pdf_puts(pdf, " 0 0 ");
+ pdf_print_real(pdf, pk_font_scale, 5);
+ pdf_puts(pdf, " 0 0]\n");
} else
- pdf_printf("/FontMatrix [%g 0 0 %g 0 0]\n",
+ pdf_printf(pdf, "/FontMatrix [%g 0 0 %g 0 0]\n",
(double) t3_font_scale, (double) t3_font_scale);
- pdf_printf("/%s [ %i %i %i %i ]\n",
+ pdf_printf(pdf, "/%s [ %i %i %i %i ]\n",
font_key[FONTBBOX1_CODE].pdfname,
(int) t3_b0, (int) t3_b1, (int) t3_b2, (int) t3_b3);
- pdf_printf("/Resources << /ProcSet [ /PDF %s] >>\n",
+ pdf_printf(pdf, "/Resources << /ProcSet [ /PDF %s] >>\n",
t3_image_used ? "/ImageB " : "");
- pdf_printf("/FirstChar %i\n/LastChar %i\n", first_char, last_char);
- wptr = pdf_new_objnum();
- eptr = pdf_new_objnum();
- cptr = pdf_new_objnum();
- pdf_printf("/Widths %i 0 R\n/Encoding %i 0 R\n/CharProcs %i 0 R\n",
+ pdf_printf(pdf, "/FirstChar %i\n/LastChar %i\n", first_char, last_char);
+ wptr = pdf_new_objnum(pdf);
+ eptr = pdf_new_objnum(pdf);
+ cptr = pdf_new_objnum(pdf);
+ pdf_printf(pdf, "/Widths %i 0 R\n/Encoding %i 0 R\n/CharProcs %i 0 R\n",
(int) wptr, (int) eptr, (int) cptr);
- pdf_end_dict();
- pdf_begin_obj(wptr, 1); /* chars width array */
- pdf_puts("[");
+ pdf_end_dict(pdf);
+ pdf_begin_obj(pdf, wptr, 1); /* chars width array */
+ pdf_puts(pdf, "[");
if (is_pk_font)
for (i = first_char; i <= last_char; i++) {
- pdf_print_real(t3_char_widths[i], 2);
- pdf_puts(" ");
+ pdf_print_real(pdf, (int) t3_char_widths[i], 2);
+ pdf_puts(pdf, " ");
} else
for (i = first_char; i <= last_char; i++)
- pdf_printf("%i ", (int) t3_char_widths[i]);
- pdf_puts("]\n");
- pdf_end_obj();
- pdf_begin_dict(eptr, 1); /* encoding dictionary */
- pdf_printf("/Type /Encoding\n/Differences [%i", first_char);
+ pdf_printf(pdf, "%i ", (int) t3_char_widths[i]);
+ pdf_puts(pdf, "]\n");
+ pdf_end_obj(pdf);
+ pdf_begin_dict(pdf, eptr, 1); /* encoding dictionary */
+ pdf_printf(pdf, "/Type /Encoding\n/Differences [%i", first_char);
if (t3_char_procs[first_char] == 0) {
- pdf_printf("/%s", notdef);
+ pdf_printf(pdf, "/%s", notdef);
is_notdef = true;
} else {
- pdf_printf("/a%i", first_char);
+ pdf_printf(pdf, "/a%i", first_char);
is_notdef = false;
}
for (i = first_char + 1; i <= last_char; i++) {
if (t3_char_procs[i] == 0) {
if (!is_notdef) {
- pdf_printf(" %i/%s", i, notdef);
+ pdf_printf(pdf, " %i/%s", i, notdef);
is_notdef = true;
}
} else {
if (is_notdef) {
- pdf_printf(" %i", i);
+ pdf_printf(pdf, " %i", i);
is_notdef = false;
}
- pdf_printf("/a%i", i);
+ pdf_printf(pdf, "/a%i", i);
}
}
- pdf_puts("]\n");
- pdf_end_dict();
- pdf_begin_dict(cptr, 1); /* CharProcs dictionary */
+ pdf_puts(pdf, "]\n");
+ pdf_end_dict(pdf);
+ pdf_begin_dict(pdf, cptr, 1); /* CharProcs dictionary */
for (i = first_char; i <= last_char; i++)
if (t3_char_procs[i] != 0)
- pdf_printf("/a%i %i 0 R\n", (int) i, (int) t3_char_procs[i]);
- pdf_end_dict();
+ pdf_printf(pdf, "/a%i %i 0 R\n", (int) i, (int) t3_char_procs[i]);
+ pdf_end_dict(pdf);
if (tracefilenames)
tex_printf(">");
cur_file_name = NULL;
diff --git a/Build/source/texk/web2c/luatexdir/font/writettf.h b/Build/source/texk/web2c/luatexdir/font/writettf.h
index 03b5cc9da12..a66cf011251 100644
--- a/Build/source/texk/web2c/luatexdir/font/writettf.h
+++ b/Build/source/texk/web2c/luatexdir/font/writettf.h
@@ -18,7 +18,7 @@
You should have received a copy of the GNU General Public License along
with LuaTeX; if not, see <http://www.gnu.org/licenses/>. */
-/* $Id: writettf.h 2271 2009-04-12 23:42:21Z oneiros $ */
+/* $Id: writettf.h 3400 2010-01-27 16:10:42Z taco $ */
#ifndef WRITETTF_H
# define WRITETTF_H 1
@@ -74,7 +74,7 @@ typedef unsigned short TTF_F2DOT14;
# define get_ufword() get_type(TTF_UFWORD)
# define get_f2dot14() get_type(TTF_F2DOT14)
-# define put_num(t,n) ((t)ttf_putnum(t##_SIZE, n))
+# define put_num(t,n) ((t)ttf_putnum(pdf,t##_SIZE, n))
# define put_char(n) (void)put_num(TTF_CHAR, n)
# define put_byte(n) (void)put_num(TTF_BYTE, n)
@@ -146,8 +146,8 @@ typedef struct {
extern fd_entry *fd_cur; /* pointer to the current font descriptor */
extern unsigned char *ttf_buffer;
-extern integer ttf_size;
-extern integer ttf_curbyte;
+extern int ttf_size;
+extern int ttf_curbyte;
extern glyph_entry *glyph_tab;
extern dirtab_entry *dir_tab;
extern dirtab_entry *ttf_name_lookup(const char *s, boolean required);
@@ -161,16 +161,16 @@ extern void ttf_read_post(void);
extern FILE *ttf_file;
-# define ttf_open() \
- (ttf_file = fopen((char *) nameoffile + 1, FOPEN_RBIN_MODE))
-# define otf_open() \
- (ttf_file = fopen((char *) nameoffile + 1, FOPEN_RBIN_MODE))
+# define ttf_open(a) \
+ (ttf_file = fopen((char *) (a), FOPEN_RBIN_MODE))
+# define otf_open(a) \
+ (ttf_file = fopen((char *) (a), FOPEN_RBIN_MODE))
# define ttf_read_file() \
readbinfile(ttf_file,&ttf_buffer,&ttf_size)
# define ttf_close() xfclose(ttf_file,cur_file_name)
# define ttf_getchar() ttf_buffer[ttf_curbyte++]
# define ttf_eof() (ttf_curbyte>ttf_size)
-extern long ttf_putnum(int s, long n);
+extern long ttf_putnum(PDF pdf, int s, long n);
extern long ttf_getnum(int s);
#endif
diff --git a/Build/source/texk/web2c/luatexdir/font/writettf.c b/Build/source/texk/web2c/luatexdir/font/writettf.w
index 0e4bb43802c..bbeb346c020 100644
--- a/Build/source/texk/web2c/luatexdir/font/writettf.c
+++ b/Build/source/texk/web2c/luatexdir/font/writettf.w
@@ -1,47 +1,48 @@
-/* writettf.c
-
- Copyright 1996-2006 Han The Thanh <thanh@pdftex.org>
- Copyright 2006-2008 Taco Hoekwater <taco@luatex.org>
+% writettf.w
+%
+% Copyright 1996-2006 Han The Thanh <thanh@@pdftex.org>
+% Copyright 2006-2010 Taco Hoekwater <taco@@luatex.org>
- This file is part of LuaTeX.
+% This file is part of LuaTeX.
- LuaTeX 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 2 of the License, or (at your
- option) any later version.
+% LuaTeX 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 2 of the License, or (at your
+% option) any later version.
- LuaTeX 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 Lesser General Public
- License for more details.
+% LuaTeX 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 Lesser General Public
+% License for more details.
- You should have received a copy of the GNU General Public License along
- with LuaTeX; if not, see <http://www.gnu.org/licenses/>. */
+% You should have received a copy of the GNU General Public License along
+% with LuaTeX; if not, see <http://www.gnu.org/licenses/>.
+@ @c
#include "ptexlib.h"
-#include "writettf.h"
+#include "font/writettf.h"
#include <string.h>
static const char _svn_version[] =
- "$Id: writettf.c 2448 2009-06-08 07:43:50Z taco $ $URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.40.6/source/texk/web2c/luatexdir/font/writettf.c $";
+ "$Id: writettf.w 3584 2010-04-02 17:45:55Z hhenkel $ "
+"$URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.60.0/source/texk/web2c/luatexdir/font/writettf.w $";
#define DEFAULT_NTABS 14
#define NEW_CMAP_SIZE 2
-#define ttf_putchar fb_putchar
-#define ttf_offset fb_offset
-#define ttf_seek_outbuf fb_seek
-
- /* #define INFILE ttf_file */
+#define ttf_putchar(A) fb_putchar(pdf,(A))
+#define ttf_offset() fb_offset(pdf)
+#define ttf_seek_outbuf(A) fb_seek(pdf,(A))
unsigned char *ttf_buffer = NULL;
-integer ttf_size = 0;
-integer ttf_curbyte = 0;
+int ttf_size = 0;
+int ttf_curbyte = 0;
typedef struct {
- const char *name; /* name of glyph */
+ char *name; /* name of glyph */
long code; /* charcode in case of subfonts */
long newindex; /* new index of glyph in output file */
+
} ttfenc_entry;
typedef struct {
@@ -93,9 +94,301 @@ fd_entry *fd_cur; /* pointer to the current font descriptor */
static struct avl_table *ttf_cmap_tree = NULL;
-integer ttf_length;
+int ttf_length;
+
+@ This used to be macnames.c
+
+@c
+char notdef[] = ".notdef";
+
+const char *mac_glyph_names[] = {
+/* 0x00 */
+ notdef,
+ ".null",
+ "CR",
+ "space",
+ "exclam",
+ "quotedbl",
+ "numbersign",
+ "dollar",
+ "percent",
+ "ampersand",
+ "quotesingle",
+ "parenleft",
+ "parenright",
+ "asterisk",
+ "plus",
+ "comma",
+/* 0x10 */
+ "hyphen",
+ "period",
+ "slash",
+ "zero",
+ "one",
+ "two",
+ "three",
+ "four",
+ "five",
+ "six",
+ "seven",
+ "eight",
+ "nine",
+ "colon",
+ "semicolon",
+ "less",
+/* 0x20 */
+ "equal",
+ "greater",
+ "question",
+ "at",
+ "A",
+ "B",
+ "C",
+ "D",
+ "E",
+ "F",
+ "G",
+ "H",
+ "I",
+ "J",
+ "K",
+ "L",
+/* 0x30 */
+ "M",
+ "N",
+ "O",
+ "P",
+ "Q",
+ "R",
+ "S",
+ "T",
+ "U",
+ "V",
+ "W",
+ "X",
+ "Y",
+ "Z",
+ "bracketleft",
+ "backslash",
+/* 0x40 */
+ "bracketright",
+ "asciicircum",
+ "underscore",
+ "grave",
+ "a",
+ "b",
+ "c",
+ "d",
+ "e",
+ "f",
+ "g",
+ "h",
+ "i",
+ "j",
+ "k",
+ "l",
+/* 0x50 */
+ "m",
+ "n",
+ "o",
+ "p",
+ "q",
+ "r",
+ "s",
+ "t",
+ "u",
+ "v",
+ "w",
+ "x",
+ "y",
+ "z",
+ "braceleft",
+ "bar",
+/* 0x60 */
+ "braceright",
+ "asciitilde",
+ "Adieresis",
+ "Aring",
+ "Ccedilla",
+ "Eacute",
+ "Ntilde",
+ "Odieresis",
+ "Udieresis",
+ "aacute",
+ "agrave",
+ "acircumflex",
+ "adieresis",
+ "atilde",
+ "aring",
+ "ccedilla",
+/* 0x70 */
+ "eacute",
+ "egrave",
+ "ecircumflex",
+ "edieresis",
+ "iacute",
+ "igrave",
+ "icircumflex",
+ "idieresis",
+ "ntilde",
+ "oacute",
+ "ograve",
+ "ocircumflex",
+ "odieresis",
+ "otilde",
+ "uacute",
+ "ugrave",
+/* 0x80 */
+ "ucircumflex",
+ "udieresis",
+ "dagger",
+ "degree",
+ "cent",
+ "sterling",
+ "section",
+ "bullet",
+ "paragraph",
+ "germandbls",
+ "registered",
+ "copyright",
+ "trademark",
+ "acute",
+ "dieresis",
+ "notequal",
+/* 0x90 */
+ "AE",
+ "Oslash",
+ "infinity",
+ "plusminus",
+ "lessequal",
+ "greaterequal",
+ "yen",
+ "mu",
+ "partialdiff",
+ "Sigma",
+ "Pi",
+ "pi",
+ "integral",
+ "ordfeminine",
+ "ordmasculine",
+ "Omega",
+/* 0xa0 */
+ "ae",
+ "oslash",
+ "questiondown",
+ "exclamdown",
+ "logicalnot",
+ "radical",
+ "florin",
+ "approxequal",
+ "Delta",
+ "guillemotleft",
+ "guillemotright",
+ "ellipsis",
+ "nbspace",
+ "Agrave",
+ "Atilde",
+ "Otilde",
+/* 0xb0 */
+ "OE",
+ "oe",
+ "endash",
+ "emdash",
+ "quotedblleft",
+ "quotedblright",
+ "quoteleft",
+ "quoteright",
+ "divide",
+ "lozenge",
+ "ydieresis",
+ "Ydieresis",
+ "fraction",
+ "currency",
+ "guilsinglleft",
+ "guilsinglright",
+/* 0xc0 */
+ "fi",
+ "fl",
+ "daggerdbl",
+ "periodcentered",
+ "quotesinglbase",
+ "quotedblbase",
+ "perthousand",
+ "Acircumflex",
+ "Ecircumflex",
+ "Aacute",
+ "Edieresis",
+ "Egrave",
+ "Iacute",
+ "Icircumflex",
+ "Idieresis",
+ "Igrave",
+/* 0xd0 */
+ "Oacute",
+ "Ocircumflex",
+ "applelogo",
+ "Ograve",
+ "Uacute",
+ "Ucircumflex",
+ "Ugrave",
+ "dotlessi",
+ "circumflex",
+ "tilde",
+ "macron",
+ "breve",
+ "dotaccent",
+ "ring",
+ "cedilla",
+ "hungarumlaut",
+/* 0xe0 */
+ "ogonek",
+ "caron",
+ "Lslash",
+ "lslash",
+ "Scaron",
+ "scaron",
+ "Zcaron",
+ "zcaron",
+ "brokenbar",
+ "Eth",
+ "eth",
+ "Yacute",
+ "yacute",
+ "Thorn",
+ "thorn",
+ "minus",
+/* 0xf0 */
+ "multiply",
+ "onesuperior",
+ "twosuperior",
+ "threesuperior",
+ "onehalf",
+ "onequarter",
+ "threequarters",
+ "franc",
+ "Gbreve",
+ "gbreve",
+ "Idot",
+ "Scedilla",
+ "scedilla",
+ "Cacute",
+ "cacute",
+ "Ccaron",
+/* 0x100 */
+ "ccaron",
+ "dmacron"
+};
-#include "macnames.c"
+const char *ambiguous_names[] = {
+ "Delta", /* increment */
+ "Omega", /* Ohm */
+ "Pi", /* product */
+ "Sigma", /* summation */
+ "dmacron", /* dslash */
+ "macron", /* overscore */
+ "periodcentered", /* middot */
+ NULL
+};
static const char *newtabnames[] = {
"OS/2",
@@ -114,7 +407,10 @@ static const char *newtabnames[] = {
"prep"
};
-static ttf_cmap_entry *new_ttf_cmap_entry(void)
+@ Back to code. Low-level helpers first.
+
+@c
+ttf_cmap_entry *new_ttf_cmap_entry(void)
{
ttf_cmap_entry *e;
e = xtalloc(1, ttf_cmap_entry);
@@ -164,24 +460,24 @@ static unsigned char ttf_addchksm(unsigned char b)
return b;
}
-static TTF_ULONG ttf_getchksm(void)
+static TTF_ULONG ttf_getchksm(PDF pdf)
{
while (tab_length % 4 != 0)
- ttf_putchar(ttf_addchksm(0)); /* ttf_addchksm updates tab_length */
+ ttf_putchar(ttf_addchksm(0)); /* |ttf_addchksm| updates |tab_length| */
return checksum;
}
-long ttf_putnum(int s, long n)
+long ttf_putnum(PDF pdf, int s, long n)
{
long i = n;
char buf[TTF_LONG_SIZE + 1], *p = buf;
while (s-- > 0) {
- *p++ = i & 0xFF;
+ *p++ = (char) (i & 0xFF);
i >>= 8;
}
p--;
while (p >= buf)
- ttf_putchar(ttf_addchksm(*p--));
+ ttf_putchar(ttf_addchksm((unsigned char) (*p--)));
return n;
}
@@ -207,7 +503,7 @@ static long ttf_funit(long n)
return (n / upem) * 1000 + ((n % upem) * 1000) / upem;
}
-static void ttf_ncopy(int n)
+static void ttf_ncopy(PDF pdf, int n)
{
while (n-- > 0)
copy_byte();
@@ -231,15 +527,13 @@ dirtab_entry *ttf_name_lookup(const char *s, boolean required)
dirtab_entry *ttf_seek_tab(const char *name, TTF_LONG offset)
{
dirtab_entry *tab = ttf_name_lookup(name, true);
- /*xfseek (INFILE, tab->offset + offset, SEEK_SET, cur_file_name); */
- ttf_curbyte = tab->offset + offset;
+ ttf_curbyte = (int) (tab->offset + (unsigned long) offset);
return tab;
}
static void ttf_seek_off(TTF_LONG offset)
{
- ttf_curbyte = offset;
- //xfseek (INFILE, offset, SEEK_SET, cur_file_name);
+ ttf_curbyte = (int) offset;
}
static void ttf_copy_encoding(void)
@@ -252,14 +546,14 @@ static void ttf_copy_encoding(void)
struct avl_traverser t;
ttfenc_entry *e = ttfenc_tab;
- assert(fd_cur->tx_tree != NULL); /* this must be set in create_fontdictionary */
+ assert(fd_cur->tx_tree != NULL); /* this must be set in |create_fontdictionary| */
if (fd_cur->fe != NULL) {
glyph_names = fd_cur->fe->glyph_names;
assert(glyph_names != NULL);
for (i = 0; i < 256; i++)
- ttfenc_tab[i].name = notdef;
+ ttfenc_tab[i].name = (char *) notdef;
/* a workaround for a bug of AcroReader 4.0 */
if (strcmp(glyph_names[97], "a") == 0) {
@@ -270,7 +564,7 @@ static void ttf_copy_encoding(void)
}
/* end of workaround */
- /* take over collected characters from TeX, reencode them */
+ /* take over collected characters from \TeX, reencode them */
avl_t_init(&t, fd_cur->tx_tree);
for (q = (int *) avl_t_first(&t, fd_cur->tx_tree); q != NULL;
q = (int *) avl_t_next(&t)) {
@@ -285,7 +579,7 @@ static void ttf_copy_encoding(void)
for (i = 0; i < 256; i++)
ttfenc_tab[i].code = -1;
- /* take over collected characters from TeX */
+ /* take over collected characters from \TeX */
avl_t_init(&t, fd_cur->tx_tree);
for (q = (int *) avl_t_first(&t, fd_cur->tx_tree); q != NULL;
q = (int *) avl_t_next(&t)) {
@@ -308,6 +602,8 @@ static void ttf_copy_encoding(void)
assert(0);
}
+@
+@c
#define ttf_append_byte(B)\
do {\
if (name_tab[i].platform_id == 3)\
@@ -340,10 +636,11 @@ static void ttf_read_name(void)
dirtab_entry *tab = ttf_seek_tab("name", TTF_USHORT_SIZE);
char *p, buf[SMALL_BUF_SIZE];
name_record_num = get_ushort();
- name_tab = xtalloc(name_record_num, name_record);
- name_buf_size = tab->length -
- (3 * TTF_USHORT_SIZE + name_record_num * 6 * TTF_USHORT_SIZE);
- name_buf = xtalloc(name_buf_size, char);
+ name_tab = xtalloc((unsigned) name_record_num, name_record);
+ name_buf_size = (int) ((unsigned) tab->length -
+ (3 * TTF_USHORT_SIZE +
+ (TTF_ULONG) name_record_num * 6 * TTF_USHORT_SIZE));
+ name_buf = xtalloc((unsigned) name_buf_size, char);
ttf_skip(TTF_USHORT_SIZE);
for (i = 0; i < name_record_num; i++) {
name_tab[i].platform_id = get_ushort();
@@ -378,7 +675,7 @@ static void ttf_read_name(void)
*p++ = name_buf[name_tab[i].offset + j + 1];
*p = 0;
fd_cur->fontname =
- xstrdup(strip_spaces_and_delims(buf, strlen(buf)));
+ xstrdup(strip_spaces_and_delims(buf, (int) strlen(buf)));
fd_cur->font_dim[FONTNAME_CODE].set = true;
break;
}
@@ -390,14 +687,15 @@ static void ttf_read_mapx(void)
{
glyph_entry *glyph;
ttf_seek_tab("maxp", TTF_FIXED_SIZE);
- glyph_tab = xtalloc(1 + (glyphs_count = get_ushort()), glyph_entry);
+ glyph_tab =
+ xtalloc((unsigned) (1 + (glyphs_count = get_ushort())), glyph_entry);
for (glyph = glyph_tab; glyph - glyph_tab < glyphs_count; glyph++) {
glyph->newindex = -1;
glyph->newoffset = 0;
glyph->name_index = 0;
- glyph->name = notdef;
+ glyph->name = (char *) notdef;
}
- glyph_index = xtalloc(glyphs_count, long);
+ glyph_index = xtalloc((unsigned) (glyphs_count + 1), long);
glyph_index[0] = 0; /* index of ".notdef" glyph */
glyph_index[1] = 1; /* index of ".null" glyph */
}
@@ -408,10 +706,10 @@ void ttf_read_head(void)
2 * TTF_FIXED_SIZE + 2 * TTF_ULONG_SIZE + TTF_USHORT_SIZE);
upem = get_ushort();
ttf_skip(16);
- fd_cur->font_dim[FONTBBOX1_CODE].val = ttf_funit(get_fword());
- fd_cur->font_dim[FONTBBOX2_CODE].val = ttf_funit(get_fword());
- fd_cur->font_dim[FONTBBOX3_CODE].val = ttf_funit(get_fword());
- fd_cur->font_dim[FONTBBOX4_CODE].val = ttf_funit(get_fword());
+ fd_cur->font_dim[FONTBBOX1_CODE].val = (int) ttf_funit(get_fword());
+ fd_cur->font_dim[FONTBBOX2_CODE].val = (int) ttf_funit(get_fword());
+ fd_cur->font_dim[FONTBBOX3_CODE].val = (int) ttf_funit(get_fword());
+ fd_cur->font_dim[FONTBBOX4_CODE].val = (int) ttf_funit(get_fword());
fd_cur->font_dim[FONTBBOX1_CODE].set = true;
fd_cur->font_dim[FONTBBOX2_CODE].set = true;
fd_cur->font_dim[FONTBBOX3_CODE].set = true;
@@ -423,8 +721,8 @@ void ttf_read_head(void)
void ttf_read_hhea(void)
{
ttf_seek_tab("hhea", TTF_FIXED_SIZE);
- fd_cur->font_dim[ASCENT_CODE].val = ttf_funit(get_fword());
- fd_cur->font_dim[DESCENT_CODE].val = ttf_funit(get_fword());
+ fd_cur->font_dim[ASCENT_CODE].val = (int) ttf_funit(get_fword());
+ fd_cur->font_dim[DESCENT_CODE].val = (int) ttf_funit(get_fword());
fd_cur->font_dim[ASCENT_CODE].set = true;
fd_cur->font_dim[DESCENT_CODE].set = true;
ttf_skip(TTF_FWORD_SIZE + TTF_UFWORD_SIZE + 3 * TTF_FWORD_SIZE +
@@ -437,9 +735,9 @@ void ttf_read_pclt(void)
if (ttf_name_lookup("PCLT", false) == NULL)
return;
ttf_seek_tab("PCLT", TTF_FIXED_SIZE + TTF_ULONG_SIZE + TTF_USHORT_SIZE);
- fd_cur->font_dim[XHEIGHT_CODE].val = ttf_funit(get_ushort());
+ fd_cur->font_dim[XHEIGHT_CODE].val = (int) ttf_funit(get_ushort());
ttf_skip(2 * TTF_USHORT_SIZE);
- fd_cur->font_dim[CAPHEIGHT_CODE].val = ttf_funit(get_ushort());
+ fd_cur->font_dim[CAPHEIGHT_CODE].val = (int) ttf_funit(get_ushort());
fd_cur->font_dim[XHEIGHT_CODE].set = true;
fd_cur->font_dim[CAPHEIGHT_CODE].set = true;
}
@@ -451,13 +749,13 @@ static void ttf_read_hmtx(void)
ttf_seek_tab("hmtx", 0);
for (glyph = glyph_tab; glyph - glyph_tab < nhmtxs; glyph++) {
glyph->advWidth = get_ufword();
- glyph->lsb = get_ufword();
+ glyph->lsb = (TTF_FWORD) get_ufword();
}
if (nhmtxs < glyphs_count) {
last_advWidth = glyph[-1].advWidth;
for (; glyph - glyph_tab < glyphs_count; glyph++) {
glyph->advWidth = last_advWidth;
- glyph->lsb = get_ufword();
+ glyph->lsb = (TTF_FWORD) get_ufword();
}
}
}
@@ -474,14 +772,14 @@ void ttf_read_post(void)
const dirtab_entry *tab = ttf_seek_tab("post", 0);
post_format = get_fixed();
italic_angle = get_fixed();
- int_part = italic_angle >> 16;
+ int_part = (long) (italic_angle >> 16);
if (int_part > 0x7FFF) { /* a negative number */
int_part = 0x10000 - int_part;
sign = -1;
}
- frac_part = italic_angle % 0x10000;
+ frac_part = (long) (italic_angle % 0x10000);
fd_cur->font_dim[ITALIC_ANGLE_CODE].val =
- sign * (int_part + frac_part * 1.0 / 0x10000);
+ (int) (sign * ((double) int_part + (double) frac_part * 1.0 / 0x10000));
fd_cur->font_dim[ITALIC_ANGLE_CODE].set = true;
if (glyph_tab == NULL)
return; /* being called from writeotf() */
@@ -489,17 +787,18 @@ void ttf_read_post(void)
switch (post_format) {
case 0x10000:
for (glyph = glyph_tab; glyph - glyph_tab < NMACGLYPHS; glyph++) {
- glyph->name = mac_glyph_names[glyph - glyph_tab];
- glyph->name_index = glyph - glyph_tab;
+ glyph->name = (const char *) mac_glyph_names[glyph - glyph_tab];
+ glyph->name_index = (TTF_USHORT) (glyph - glyph_tab);
}
break;
case 0x20000:
nnames = get_ushort(); /* some fonts have this value different from nglyphs */
for (glyph = glyph_tab; glyph - glyph_tab < nnames; glyph++)
glyph->name_index = get_ushort();
- /*length = tab->length - (xftell (INFILE, cur_file_name) - tab->offset); */
- length = tab->length - (ttf_curbyte - tab->offset);
- glyph_name_buf = xtalloc(length, char);
+ length =
+ (long) ((long) tab->length -
+ (long) ((long) ttf_curbyte - (long) tab->offset));
+ glyph_name_buf = xtalloc((unsigned) length, char);
for (p = glyph_name_buf; p - glyph_name_buf < length;) {
for (k = get_byte(); k > 0; k--)
*p++ = get_char();
@@ -519,7 +818,7 @@ void ttf_read_post(void)
break;
case 0x00030000:
for (glyph = glyph_tab; glyph - glyph_tab < NMACGLYPHS; glyph++) {
- glyph->name_index = glyph - glyph_tab;
+ glyph->name_index = (TTF_USHORT) (glyph - glyph_tab);
}
break;
default:
@@ -534,7 +833,7 @@ static void ttf_read_loca(void)
ttf_seek_tab("loca", 0);
if (loca_format != 0)
for (glyph = glyph_tab; glyph - glyph_tab < glyphs_count + 1; glyph++)
- glyph->offset = get_ulong();
+ glyph->offset = (TTF_LONG) get_ulong();
else
for (glyph = glyph_tab; glyph - glyph_tab < glyphs_count + 1; glyph++)
glyph->offset = get_ushort() << 1;
@@ -567,10 +866,10 @@ static ttf_cmap_entry *ttf_read_cmap(char *ttf_name, int pid, int eid,
ttf_cmap_entry tmp_e, *p;
void **aa;
- /* loop up in ttf_cmap_tree first, return if found */
+ /* look up in |ttf_cmap_tree| first, return if found */
tmp_e.ttf_name = ttf_name;
- tmp_e.pid = pid;
- tmp_e.eid = eid;
+ tmp_e.pid = (TTF_USHORT) pid;
+ tmp_e.eid = (TTF_USHORT) eid;
if (ttf_cmap_tree == NULL) {
ttf_cmap_tree = avl_create(comp_ttf_cmap_entry, NULL, &avl_xallocator);
assert(ttf_cmap_tree != NULL);
@@ -580,17 +879,16 @@ static ttf_cmap_entry *ttf_read_cmap(char *ttf_name, int pid, int eid,
return p;
/* not found, have to read it */
- ttf_seek_tab("cmap", TTF_USHORT_SIZE); /* skip the table vesrion number (=0) */
+ ttf_seek_tab("cmap", TTF_USHORT_SIZE); /* skip the table version number (=0) */
ncmapsubtabs = get_ushort();
- /* cmap_offset = xftell (INFILE, cur_file_name) - 2 * TTF_USHORT_SIZE; */
- cmap_offset = ttf_curbyte - 2 * TTF_USHORT_SIZE;
+ cmap_offset = (TTF_ULONG) (ttf_curbyte - 2 * TTF_USHORT_SIZE);
cmap_tab = xtalloc(ncmapsubtabs, cmap_entry);
for (i = 0; i < ncmapsubtabs; ++i) {
tmp_pid = get_ushort();
tmp_eid = get_ushort();
tmp_offset = get_ulong();
if (tmp_pid == pid && tmp_eid == eid) {
- ttf_seek_off(cmap_offset + tmp_offset);
+ ttf_seek_off((TTF_LONG) (cmap_offset + tmp_offset));
format = get_ushort();
if (format == 4)
goto read_cmap_format_4;
@@ -609,8 +907,8 @@ static ttf_cmap_entry *ttf_read_cmap(char *ttf_name, int pid, int eid,
/* initialize the new entry */
p = new_ttf_cmap_entry();
p->ttf_name = xstrdup(ttf_name);
- p->pid = pid;
- p->eid = eid;
+ p->pid = (TTF_USHORT) pid;
+ p->eid = (TTF_USHORT) eid;
p->table = xtalloc(0x10000, long);
for (i = 0; i < 0x10000; ++i)
p->table[i] = -1; /* unassigned yet */
@@ -634,7 +932,7 @@ static ttf_cmap_entry *ttf_read_cmap(char *ttf_name, int pid, int eid,
s->idRangeOffset = get_ushort();
length -= 8 * TTF_USHORT_SIZE + 4 * segCount * TTF_USHORT_SIZE;
n = length / TTF_USHORT_SIZE; /* number of glyphID's */
- glyphId = xtalloc(n, TTF_USHORT);
+ glyphId = xtalloc((unsigned) n, TTF_USHORT);
for (i = 0; i < n; i++)
glyphId[i] = get_ushort();
for (s = seg_tab; s - seg_tab < segCount; s++) {
@@ -672,6 +970,8 @@ static ttf_cmap_entry *ttf_read_cmap(char *ttf_name, int pid, int eid,
return p;
}
+@
+@c
static void ttf_read_font(void)
{
ttf_read_tabdir();
@@ -693,37 +993,39 @@ static void ttf_read_font(void)
ttf_read_name();
}
-static void ttf_reset_chksm(dirtab_entry * tab)
+static void ttf_reset_chksm(PDF pdf, dirtab_entry * tab)
{
checksum = 0;
tab_length = 0;
tmp_ulong = 0;
- tab->offset = ttf_offset();
+ tab->offset = (TTF_ULONG) ttf_offset();
if (tab->offset % 4 != 0)
pdftex_warn("offset of `%4.4s' is not a multiple of 4", tab->tag);
}
-static void ttf_set_chksm(dirtab_entry * tab)
+static void ttf_set_chksm(PDF pdf, dirtab_entry * tab)
{
- tab->length = ttf_offset() - tab->offset;
- tab->checksum = ttf_getchksm();
+ tab->length = (TTF_ULONG) ttf_offset() - tab->offset;
+ tab->checksum = ttf_getchksm(pdf);
}
-static void ttf_copytab(const char *name)
+static void ttf_copytab(PDF pdf, const char *name)
{
long i;
dirtab_entry *tab = ttf_seek_tab(name, 0);
- ttf_reset_chksm(tab);
- for (i = tab->length; i > 0; i--)
+ ttf_reset_chksm(pdf, tab);
+ for (i = (long) tab->length; i > 0; i--)
copy_char();
- ttf_set_chksm(tab);
+ ttf_set_chksm(pdf, tab);
}
+@
+@c
#define BYTE_ENCODING_LENGTH \
((256)*TTF_BYTE_SIZE + 3*TTF_USHORT_SIZE)
-static void ttf_byte_encoding(void)
+static void ttf_byte_encoding(PDF pdf)
{
ttfenc_entry *e;
(void) put_ushort(0); /* format number (0: byte encoding table) */
@@ -741,9 +1043,11 @@ static void ttf_byte_encoding(void)
}
}
+@
+@c
#define TRIMMED_TABLE_MAP_LENGTH (TTF_USHORT_SIZE*(5 + (256)))
-static void ttf_trimmed_table_map(void)
+static void ttf_trimmed_table_map(PDF pdf)
{
ttfenc_entry *e;
(void) put_ushort(6); /* format number (6): trimmed table mapping */
@@ -755,9 +1059,11 @@ static void ttf_trimmed_table_map(void)
(void) put_ushort(e->newindex);
}
+@
+@c
#define SEG_MAP_DELTA_LENGTH ((16 + (256))*TTF_USHORT_SIZE)
-static void ttf_seg_map_delta(void)
+static void ttf_seg_map_delta(PDF pdf)
{
ttfenc_entry *e;
(void) put_ushort(4); /* format number (4: segment mapping to delta values) */
@@ -780,6 +1086,8 @@ static void ttf_seg_map_delta(void)
(void) put_ushort(e->newindex);
}
+@
+@c
#define CMAP_ENTRY_LENGTH (2*TTF_USHORT_SIZE + TTF_ULONG_SIZE)
static void ttf_select_cmap(void)
@@ -787,25 +1095,25 @@ static void ttf_select_cmap(void)
assert(sizeof(new_cmap_tab) <= NEW_CMAP_SIZE * sizeof(cmap_entry));
new_cmap_tab[0].platform_id = 1; /* Macintosh */
new_cmap_tab[0].encoding_id = 0; /* Symbol; ignore code page */
- new_cmap_tab[0].format = new_glyphs_count < 256 ? 0 /* byte encoding */
- : 6; /* trimmed table mapping */
+ new_cmap_tab[0].format = (TTF_USHORT) (new_glyphs_count < 256 ? 0 /* byte encoding */
+ : 6); /* trimmed table mapping */
new_cmap_tab[1].platform_id = 3; /* Microsoft */
new_cmap_tab[1].encoding_id = 0; /* Symbol; ignore code page */
new_cmap_tab[1].format = 4; /* segment mapping to delta */
}
-static void ttf_write_cmap(void)
+static void ttf_write_cmap(PDF pdf)
{
cmap_entry *ce;
long offset;
dirtab_entry *tab = ttf_name_lookup("cmap", true);
ttf_select_cmap();
- ttf_reset_chksm(tab);
+ ttf_reset_chksm(pdf, tab);
(void) put_ushort(0); /* table version number (0) */
(void) put_ushort(NEW_CMAP_SIZE); /* number of encoding tables */
offset = 2 * TTF_USHORT_SIZE + NEW_CMAP_SIZE * CMAP_ENTRY_LENGTH;
for (ce = new_cmap_tab; ce - new_cmap_tab < NEW_CMAP_SIZE; ce++) {
- ce->offset = offset;
+ ce->offset = (TTF_ULONG) offset;
switch (ce->format) {
case 0:
offset += BYTE_ENCODING_LENGTH;
@@ -821,24 +1129,26 @@ static void ttf_write_cmap(void)
}
(void) put_ushort(ce->platform_id);
(void) put_ushort(ce->encoding_id);
- put_ulong(ce->offset);
+ put_ulong((long) ce->offset);
}
for (ce = new_cmap_tab; ce - new_cmap_tab < NEW_CMAP_SIZE; ce++) {
switch (ce->format) {
case 0:
- ttf_byte_encoding();
+ ttf_byte_encoding(pdf);
break;
case 4:
- ttf_seg_map_delta();
+ ttf_seg_map_delta(pdf);
break;
case 6:
- ttf_trimmed_table_map();
+ ttf_trimmed_table_map(pdf);
break;
}
}
- ttf_set_chksm(tab);
+ ttf_set_chksm(pdf, tab);
}
+@
+@c
static int prepend_subset_tags(int index, char *p)
{
boolean is_unicode;
@@ -862,7 +1172,7 @@ static int prepend_subset_tags(int index, char *p)
}
-static void ttf_write_name(void)
+static void ttf_write_name(PDF pdf)
{
int i, l;
char *p;
@@ -874,12 +1184,12 @@ static void ttf_write_name(void)
l = 0;
for (i = 0; i < name_record_num; i++)
l += name_tab[i].length + 14; /* maximum lengh of new stogare area */
- new_name_buf = xtalloc(l, char);
+ new_name_buf = xtalloc((unsigned) l, char);
/* additional space for subset tags */
p = new_name_buf;
for (i = 0; i < name_record_num; i++) {
n = name_tab + i;
- n->new_offset = p - new_name_buf;
+ n->new_offset = (TTF_USHORT) (p - new_name_buf);
if ((n->name_id == 1 || n->name_id == 3 ||
n->name_id == 4 || n->name_id == 6) &&
((n->platform_id == 1 && n->encoding_id == 0) ||
@@ -891,14 +1201,14 @@ static void ttf_write_name(void)
l = 0;
memcpy(p, name_buf + n->offset, n->length);
p += n->length;
- n->new_length = n->length + l;
+ n->new_length = (TTF_USHORT) (n->length + l);
}
- new_name_buf_size = p - new_name_buf;
+ new_name_buf_size = (int) (p - new_name_buf);
} else {
new_name_buf = name_buf;
new_name_buf_size = name_buf_size;
}
- ttf_reset_chksm(tab);
+ ttf_reset_chksm(pdf, tab);
(void) put_ushort(0); /* Format selector */
(void) put_ushort(name_record_num);
(void) put_ushort(3 * TTF_USHORT_SIZE +
@@ -913,17 +1223,19 @@ static void ttf_write_name(void)
}
for (p = new_name_buf; p - new_name_buf < new_name_buf_size; p++)
put_char(*p);
- ttf_set_chksm(tab);
+ ttf_set_chksm(pdf, tab);
if (new_name_buf != name_buf)
xfree(new_name_buf);
}
-static void ttf_write_dirtab(void)
+@
+@c
+static void ttf_write_dirtab(PDF pdf)
{
dirtab_entry *tab;
TTF_ULONG i, k;
char *p;
- const integer save_offset = ttf_offset();
+ const int save_offset = ttf_offset();
ttf_seek_outbuf(TABDIR_OFF);
if (is_subsetted(fd_cur->fm)) {
for (i = 0; i < DEFAULT_NTABS; i++) {
@@ -932,24 +1244,24 @@ static void ttf_write_dirtab(void)
continue;
for (k = 0; k < 4; k++)
put_char(tab->tag[k]);
- put_ulong(tab->checksum);
- put_ulong(tab->offset);
- put_ulong(tab->length);
+ put_ulong((long) tab->checksum);
+ put_ulong((long) tab->offset);
+ put_ulong((long) tab->length);
}
} else {
for (tab = dir_tab; tab - dir_tab < ntabs; tab++) {
for (k = 0; k < 4; k++)
put_char(tab->tag[k]);
- put_ulong(tab->checksum);
- put_ulong(tab->offset);
- put_ulong(tab->length);
+ put_ulong((long) tab->checksum);
+ put_ulong((long) tab->offset);
+ put_ulong((long) tab->length);
}
}
/* adjust checkSumAdjustment */
tmp_ulong = 0;
checksum = 0;
- for (p = fb_array, i = 0; i < (unsigned) save_offset;) {
- tmp_ulong = (tmp_ulong << 8) + *p++;
+ for (p = pdf->fb_array, i = 0; i < (unsigned) save_offset;) {
+ tmp_ulong = (tmp_ulong << 8) + (TTF_ULONG) * p++;
i++;
if (i % 4 == 0) {
checksum += tmp_ulong;
@@ -961,61 +1273,70 @@ static void ttf_write_dirtab(void)
checksum <<= 8 * (4 - i % 4);
}
k = 0xB1B0AFBA - checksum;
- ttf_seek_outbuf(checkSumAdjustment_offset);
- put_ulong(k);
+ ttf_seek_outbuf((int) checkSumAdjustment_offset);
+ put_ulong((long) k);
ttf_seek_outbuf(save_offset);
}
-static void ttf_write_glyf(void)
+@
+@c
+static void ttf_write_glyf(PDF pdf)
{
long *id, k;
TTF_USHORT idx;
TTF_USHORT flags;
dirtab_entry *tab = ttf_name_lookup("glyf", true);
- const long glyf_offset = tab->offset;
+ const long glyf_offset = (long) tab->offset;
const long new_glyf_offset = ttf_offset();
- ttf_reset_chksm(tab);
+ ttf_reset_chksm(pdf, tab);
for (id = glyph_index; id - glyph_index < new_glyphs_count; id++) {
glyph_tab[*id].newoffset = ttf_offset() - new_glyf_offset;
if (glyph_tab[*id].offset != glyph_tab[*id + 1].offset) {
ttf_seek_off(glyf_offset + glyph_tab[*id].offset);
k = copy_short();
- ttf_ncopy(4 * TTF_FWORD_SIZE);
+ ttf_ncopy(pdf, 4 * TTF_FWORD_SIZE);
if (k < 0) {
do {
flags = copy_ushort();
idx = get_ushort();
if (glyph_tab[idx].newindex < 0) {
- glyph_tab[idx].newindex = new_glyphs_count;
+ glyph_tab[idx].newindex = (TTF_SHORT) new_glyphs_count;
glyph_index[new_glyphs_count++] = idx;
/*
- N.B.: Here we change `new_glyphs_count',
- which appears in the condition of the `for' loop
+ N.B.: Here we change |new_glyphs_count|,
+ which appears in the condition of the |for| loop
*/
}
(void) put_ushort(glyph_tab[idx].newindex);
if (flags & ARG_1_AND_2_ARE_WORDS)
- ttf_ncopy(2 * TTF_SHORT_SIZE);
+ ttf_ncopy(pdf, 2 * TTF_SHORT_SIZE);
else
- ttf_ncopy(TTF_USHORT_SIZE);
+ ttf_ncopy(pdf, TTF_USHORT_SIZE);
if (flags & WE_HAVE_A_SCALE)
- ttf_ncopy(TTF_F2DOT14_SIZE);
+ ttf_ncopy(pdf, TTF_F2DOT14_SIZE);
else if (flags & WE_HAVE_AN_X_AND_Y_SCALE)
- ttf_ncopy(2 * TTF_F2DOT14_SIZE);
+ ttf_ncopy(pdf, 2 * TTF_F2DOT14_SIZE);
else if (flags & WE_HAVE_A_TWO_BY_TWO)
- ttf_ncopy(4 * TTF_F2DOT14_SIZE);
+ ttf_ncopy(pdf, 4 * TTF_F2DOT14_SIZE);
} while (flags & MORE_COMPONENTS);
if (flags & WE_HAVE_INSTRUCTIONS)
- ttf_ncopy(copy_ushort());
+ ttf_ncopy(pdf, copy_ushort());
} else
- ttf_ncopy(glyph_tab[*id + 1].offset - glyph_tab[*id].offset -
- TTF_USHORT_SIZE - 4 * TTF_FWORD_SIZE);
+ ttf_ncopy(pdf, (int)
+ (glyph_tab[*id + 1].offset - glyph_tab[*id].offset -
+ TTF_USHORT_SIZE - 4 * TTF_FWORD_SIZE));
}
}
- last_glyf_offset = ttf_offset() - new_glyf_offset;
- ttf_set_chksm(tab);
+ last_glyf_offset = (TTF_ULONG) ttf_offset() - (TTF_ULONG) new_glyf_offset;
+ ttf_set_chksm(pdf, tab);
}
+@ Reindexing glyphs: we append index of used glyphs to |glyph_index|
+ while going through |ttfenc_tab|. After appending a new entry to
+ |glyph_index| we set field |newindex| of corresponding entries in both
+ |glyph_tab| and |ttfenc_tab| to the newly created index.
+
+@c
static void ttf_reindex_glyphs(void)
{
ttfenc_entry *e;
@@ -1025,12 +1346,6 @@ static void ttf_reindex_glyphs(void)
ttf_cmap_entry *cmap = NULL;
boolean cmap_not_found = false;
- /*
- * reindexing glyphs: we append index of used glyphs to `glyph_index'
- * while going through `ttfenc_tab'. After appending a new entry to
- * `glyph_index' we set field `newindex' of corresponding entries in both
- * `glyph_tab' and `ttfenc_tab' to the newly created index
- */
for (e = ttfenc_tab; e - ttfenc_tab < 256; e++) {
e->newindex = 0; /* index of ".notdef" glyph */
@@ -1118,60 +1433,88 @@ static void ttf_reindex_glyphs(void)
assert(glyph > glyph_tab && glyph - glyph_tab < glyphs_count);
if (glyph->newindex < 0) {
glyph_index[new_glyphs_count] = (short) (glyph - glyph_tab);
- glyph->newindex = new_glyphs_count;
+ glyph->newindex = (TTF_SHORT) new_glyphs_count;
new_glyphs_count++;
}
e->newindex = glyph->newindex;
}
}
-static void ttf_write_head(void)
+@ To calculate the checkSum for the 'head' table which itself includes the
+ checkSumAdjustment entry for the entire font, do the following:
+
+ \item Set the checkSumAdjustment to 0.
+ \item Calculate the checksum for all the tables including the 'head' table
+ and enter that value into the table directory.
+ \item Calculate the checksum for the entire font.
+ \item Subtract that value from the hex value B1B0AFBA.
+ \item Store the result in checkSumAdjustment.
+
+ The checkSum for the 'head table which includes the checkSumAdjustment
+ entry for the entire font is now incorrect. That is not a problem. Do not
+ change it. An application attempting to verify that the 'head' table has
+ not changed should calculate the checkSum for that table by not including
+ the checkSumAdjustment value, and compare the result with the entry in the
+ table directory.
+
+ The table directory also includes the offset of the associated tagged
+ table from the beginning of the font file and the length of that table.
+
+
+@c
+static void ttf_write_head(PDF pdf)
{
dirtab_entry *tab;
tab = ttf_seek_tab("head", 0);
- ttf_reset_chksm(tab);
- ttf_ncopy(2 * TTF_FIXED_SIZE);
- checkSumAdjustment_offset = ttf_offset();
+ ttf_reset_chksm(pdf, tab);
+ ttf_ncopy(pdf, 2 * TTF_FIXED_SIZE);
+ checkSumAdjustment_offset = (TTF_ULONG) ttf_offset();
put_ulong(0);
ttf_skip(TTF_ULONG_SIZE); /* skip checkSumAdjustment */
- ttf_ncopy(TTF_ULONG_SIZE + 2 * TTF_USHORT_SIZE + 16 +
+ ttf_ncopy(pdf, TTF_ULONG_SIZE + 2 * TTF_USHORT_SIZE + 16 +
4 * TTF_FWORD_SIZE + 2 * TTF_USHORT_SIZE + TTF_SHORT_SIZE);
if (is_subsetted(fd_cur->fm)) {
(void) put_short(loca_format);
(void) put_short(0);
} else
- ttf_ncopy(2 * TTF_SHORT_SIZE);
- ttf_set_chksm(tab);
+ ttf_ncopy(pdf, 2 * TTF_SHORT_SIZE);
+ ttf_set_chksm(pdf, tab);
}
-static void ttf_write_hhea(void)
+@
+@c
+static void ttf_write_hhea(PDF pdf)
{
dirtab_entry *tab;
tab = ttf_seek_tab("hhea", 0);
- ttf_reset_chksm(tab);
- ttf_ncopy(TTF_FIXED_SIZE + 3 * TTF_FWORD_SIZE + TTF_UFWORD_SIZE +
+ ttf_reset_chksm(pdf, tab);
+ ttf_ncopy(pdf, TTF_FIXED_SIZE + 3 * TTF_FWORD_SIZE + TTF_UFWORD_SIZE +
3 * TTF_FWORD_SIZE + 8 * TTF_SHORT_SIZE);
(void) put_ushort(new_glyphs_count);
- ttf_set_chksm(tab);
+ ttf_set_chksm(pdf, tab);
}
-static void ttf_write_htmx(void)
+@
+@c
+static void ttf_write_htmx(PDF pdf)
{
long *id;
dirtab_entry *tab = ttf_seek_tab("hmtx", 0);
- ttf_reset_chksm(tab);
+ ttf_reset_chksm(pdf, tab);
for (id = glyph_index; id - glyph_index < new_glyphs_count; id++) {
put_ufword(glyph_tab[*id].advWidth);
put_ufword(glyph_tab[*id].lsb);
}
- ttf_set_chksm(tab);
+ ttf_set_chksm(pdf, tab);
}
-static void ttf_write_loca(void)
+@
+@c
+static void ttf_write_loca(PDF pdf)
{
long *id;
dirtab_entry *tab = ttf_seek_tab("loca", 0);
- ttf_reset_chksm(tab);
+ ttf_reset_chksm(pdf, tab);
loca_format = 0;
if (last_glyf_offset >= 0x00020000 || (last_glyf_offset & 1))
loca_format = 1;
@@ -1184,51 +1527,58 @@ static void ttf_write_loca(void)
if (loca_format != 0) {
for (id = glyph_index; id - glyph_index < new_glyphs_count; id++)
put_ulong(glyph_tab[*id].newoffset);
- put_ulong(last_glyf_offset);
+ put_ulong((long) last_glyf_offset);
} else {
for (id = glyph_index; id - glyph_index < new_glyphs_count; id++)
(void) put_ushort(glyph_tab[*id].newoffset / 2);
- (void) put_ushort(last_glyf_offset / 2);
+ (void) put_ushort((long) (last_glyf_offset / 2));
}
- ttf_set_chksm(tab);
+ ttf_set_chksm(pdf, tab);
}
-static void ttf_write_mapx(void)
+@
+@c
+static void ttf_write_mapx(PDF pdf)
{
dirtab_entry *tab = ttf_seek_tab("maxp", TTF_FIXED_SIZE + TTF_USHORT_SIZE);
- ttf_reset_chksm(tab);
+ ttf_reset_chksm(pdf, tab);
put_fixed(0x00010000);
(void) put_ushort(new_glyphs_count);
- ttf_ncopy(13 * TTF_USHORT_SIZE);
- ttf_set_chksm(tab);
+ ttf_ncopy(pdf, 13 * TTF_USHORT_SIZE);
+ ttf_set_chksm(pdf, tab);
}
-static void ttf_write_OS2(void)
+@
+@c
+static void ttf_write_OS2(PDF pdf)
{
dirtab_entry *tab = ttf_seek_tab("OS/2", 0);
TTF_USHORT version;
- ttf_reset_chksm(tab);
+ ttf_reset_chksm(pdf, tab);
version = get_ushort();
if (version > 3)
pdftex_fail("unknown version of OS/2 table (%.4X)", version);
(void) put_ushort(0x0001); /* fix version to 1 */
- ttf_ncopy(2 * TTF_USHORT_SIZE + 13 * TTF_SHORT_SIZE + 10 * TTF_BYTE_SIZE);
+ ttf_ncopy(pdf,
+ 2 * TTF_USHORT_SIZE + 13 * TTF_SHORT_SIZE + 10 * TTF_BYTE_SIZE);
ttf_skip(4 * TTF_ULONG_SIZE); /* ulUnicodeRange 1--4 */
put_ulong(0x00000003); /* Basic Latin + Latin-1 Supplement (0x0000--0x00FF) */
put_ulong(0x10000000); /* Private Use (0xE000--0xF8FF) */
put_ulong(0x00000000);
put_ulong(0x00000000);
- ttf_ncopy(4 * TTF_CHAR_SIZE + TTF_USHORT_SIZE); /* achVendID + fsSelection */
+ ttf_ncopy(pdf, 4 * TTF_CHAR_SIZE + TTF_USHORT_SIZE); /* achVendID + fsSelection */
ttf_skip(2 * TTF_USHORT_SIZE);
(void) put_ushort(0x0000); /* usFirstCharIndex */
(void) put_ushort(0xF0FF); /* usLastCharIndex */
- ttf_ncopy(5 * TTF_USHORT_SIZE);
+ ttf_ncopy(pdf, 5 * TTF_USHORT_SIZE);
/* for version 0 the OS/2 table ends here, the rest is for version 1 */
put_ulong(0x80000000); /* Symbol Character Set---don't use any code page */
put_ulong(0x00000000);
- ttf_set_chksm(tab);
+ ttf_set_chksm(pdf, tab);
}
+@
+@c
static boolean unsafe_name(const char *s)
{
const char **p;
@@ -1238,43 +1588,47 @@ static boolean unsafe_name(const char *s)
return false;
}
-static void ttf_write_post(void)
+static void ttf_write_post(PDF pdf)
{
dirtab_entry *tab = ttf_seek_tab("post", TTF_FIXED_SIZE);
glyph_entry *glyph;
const char *s;
long *id;
- int l;
- ttf_reset_chksm(tab);
+ int k, l;
+ ttf_reset_chksm(pdf, tab);
if (!fd_cur->write_ttf_glyph_names || post_format == 0x00030000) {
put_fixed(0x00030000);
- ttf_ncopy(TTF_FIXED_SIZE + 2 * TTF_FWORD_SIZE + 5 * TTF_ULONG_SIZE);
+ ttf_ncopy(pdf,
+ TTF_FIXED_SIZE + 2 * TTF_FWORD_SIZE + 5 * TTF_ULONG_SIZE);
} else {
put_fixed(0x00020000);
- ttf_ncopy(TTF_FIXED_SIZE + 2 * TTF_FWORD_SIZE + 5 * TTF_ULONG_SIZE);
+ ttf_ncopy(pdf,
+ TTF_FIXED_SIZE + 2 * TTF_FWORD_SIZE + 5 * TTF_ULONG_SIZE);
(void) put_ushort(new_glyphs_count);
k = 0;
for (id = glyph_index; id - glyph_index < new_glyphs_count; id++) {
glyph = glyph_tab + *id;
if (glyph->name_index >= NMACGLYPHS || unsafe_name(glyph->name))
- glyph->name_index = NMACGLYPHS + k++;
+ glyph->name_index = (TTF_USHORT) (NMACGLYPHS + k++);
(void) put_ushort(glyph->name_index);
}
for (id = glyph_index; id - glyph_index < new_glyphs_count; id++) {
glyph = glyph_tab + *id;
if (glyph->name_index >= NMACGLYPHS) {
s = glyph->name;
- l = strlen(s);
+ l = (int) strlen(s);
put_byte(l);
while (l-- > 0)
put_char(*s++);
}
}
}
- ttf_set_chksm(tab);
+ ttf_set_chksm(pdf, tab);
}
-static void ttf_init_font(int n)
+@
+@c
+static void ttf_init_font(PDF pdf, int n)
{
int i, k;
for (i = 1, k = 0; i <= n; i <<= 1, k++);
@@ -1286,92 +1640,86 @@ static void ttf_init_font(int n)
ttf_seek_outbuf(TABDIR_OFF + n * 4 * TTF_ULONG_SIZE);
}
-static void ttf_subset_font(void)
+@
+@c
+static void ttf_subset_font(PDF pdf)
{
- ttf_init_font(new_ntabs);
+ ttf_init_font(pdf, new_ntabs);
if (ttf_name_lookup("PCLT", false) != NULL)
- ttf_copytab("PCLT");
+ ttf_copytab(pdf, "PCLT");
if (ttf_name_lookup("fpgm", false) != NULL)
- ttf_copytab("fpgm");
+ ttf_copytab(pdf, "fpgm");
if (ttf_name_lookup("cvt ", false) != NULL)
- ttf_copytab("cvt ");
+ ttf_copytab(pdf, "cvt ");
if (ttf_name_lookup("prep", false) != NULL)
- ttf_copytab("prep");
+ ttf_copytab(pdf, "prep");
ttf_reindex_glyphs();
- ttf_write_glyf();
- ttf_write_loca();
- ttf_write_OS2();
- ttf_write_head();
- ttf_write_hhea();
- ttf_write_htmx();
- ttf_write_mapx();
- ttf_write_name();
- ttf_write_post();
- ttf_write_cmap();
- ttf_write_dirtab();
+ ttf_write_glyf(pdf);
+ ttf_write_loca(pdf);
+ ttf_write_OS2(pdf);
+ ttf_write_head(pdf);
+ ttf_write_hhea(pdf);
+ ttf_write_htmx(pdf);
+ ttf_write_mapx(pdf);
+ ttf_write_name(pdf);
+ ttf_write_post(pdf);
+ ttf_write_cmap(pdf);
+ ttf_write_dirtab(pdf);
}
-static void ttf_copy_font(void)
+@
+@c
+static void ttf_copy_font(PDF pdf)
{
dirtab_entry *tab;
- ttf_init_font(ntabs);
+ ttf_init_font(pdf, ntabs);
for (tab = dir_tab; tab - dir_tab < ntabs; tab++) {
if (strncmp(tab->tag, "head", 4) == 0)
- ttf_write_head();
+ ttf_write_head(pdf);
else
- ttf_copytab(tab->tag);
+ ttf_copytab(pdf, tab->tag);
}
- ttf_write_dirtab();
+ ttf_write_dirtab(pdf);
}
-void writettf(fd_entry * fd)
+@
+@c
+void writettf(PDF pdf, fd_entry * fd)
{
int callback_id;
int file_opened = 0;
- char *ftemp = NULL;
- fd_cur = fd; /* fd_cur is global inside writettf.c */
+ fd_cur = fd; /* |fd_cur| is global inside \.{writettf.w} */
assert(fd_cur->fm != NULL);
assert(is_truetype(fd_cur->fm));
assert(is_included(fd_cur->fm));
- set_cur_file_name(fd_cur->fm->ff_name);
-
if (is_subsetted(fd_cur->fm) && (fd_cur->fe == NULL)
&& !is_subfont(fd_cur->fm)) {
pdftex_fail("Subset TrueType must be a reencoded or a subfont");
}
ttf_curbyte = 0;
ttf_size = 0;
- callback_id = callback_defined(find_truetype_file_callback);
- if (callback_id > 0) {
- if (run_callback
- (callback_id, "S->S", (char *) (nameoffile + 1), &ftemp)) {
- if (ftemp != NULL && strlen(ftemp)) {
- free(nameoffile);
- namelength = strlen(ftemp);
- nameoffile = xmalloc(namelength + 2);
- strcpy((char *) (nameoffile + 1), ftemp);
- free(ftemp);
- }
- }
- }
+ cur_file_name =
+ luatex_find_file(fd_cur->fm->ff_name, find_truetype_file_callback);
+ if (cur_file_name == NULL) {
+ pdftex_fail("cannot find TrueType font file for reading");
+ }
callback_id = callback_defined(read_truetype_file_callback);
if (callback_id > 0) {
- if (run_callback(callback_id, "S->bSd", (char *) (nameoffile + 1),
+ if (run_callback(callback_id, "S->bSd", cur_file_name,
&file_opened, &ttf_buffer, &ttf_size) &&
file_opened && ttf_size > 0) {
} else {
pdftex_fail("cannot open TrueType font file for reading");
}
} else {
- if (!ttf_open()) {
+ if (!ttf_open(cur_file_name)) {
pdftex_fail("cannot open TrueType font file for reading");
}
ttf_read_file();
ttf_close();
}
- cur_file_name = (char *) nameoffile + 1;
if (tracefilenames) {
if (is_subsetted(fd_cur->fm))
tex_printf("<%s", cur_file_name);
@@ -1389,14 +1737,14 @@ void writettf(fd_entry * fd)
name_buf = NULL;
ttf_read_font();
- pdf_save_offset = pdfoffset();
- pdf_flush();
+ pdf_save_offset(pdf);
+ pdf_flush(pdf);
if (is_subsetted(fd_cur->fm)) {
ttf_copy_encoding();
- ttf_subset_font();
+ ttf_subset_font(pdf);
} else
- ttf_copy_font();
+ ttf_copy_font(pdf);
ttf_length = ttf_offset();
xfree(dir_tab);
@@ -1415,7 +1763,7 @@ void writettf(fd_entry * fd)
cur_file_name = NULL;
}
-static void do_writeotf(fd_entry * fd)
+void do_writeotf(PDF pdf, fd_entry * fd)
{
long i;
dirtab_entry *tab;
@@ -1436,83 +1784,51 @@ static void do_writeotf(fd_entry * fd)
ttf_read_post();
/* copy font file */
tab = ttf_seek_tab("CFF ", 0);
- for (i = tab->length; i > 0; i--)
+ for (i = (long) tab->length; i > 0; i--)
copy_char();
xfree(dir_tab);
- /* ttf_close (); */
if (tracefilenames)
tex_printf(">>");
}
-void writeotf(fd_entry * fd)
+@
+@c
+void writeotf(PDF pdf, fd_entry * fd)
{
int callback_id;
int file_opened = 0;
- char *ftemp = NULL;
-
- fd_cur = fd; /* fd_cur is global inside writettf.c */
+ fd_cur = fd;
assert(fd_cur->fm != NULL);
assert(is_opentype(fd_cur->fm));
assert(is_included(fd_cur->fm));
- set_cur_file_name(fd_cur->fm->ff_name);
ttf_curbyte = 0;
ttf_size = 0;
- callback_id = callback_defined(find_opentype_file_callback);
- if (callback_id > 0) {
- if (run_callback
- (callback_id, "S->S", (char *) (nameoffile + 1), &ftemp)) {
- if (ftemp != NULL && strlen(ftemp)) {
- free(nameoffile);
- namelength = strlen(ftemp);
- nameoffile = xmalloc(namelength + 2);
- strcpy((char *) (nameoffile + 1), ftemp);
- free(ftemp);
- }
- }
+ cur_file_name =
+ luatex_find_file(fd_cur->fm->ff_name, find_opentype_file_callback);
+ if (cur_file_name == NULL) {
+ pdftex_fail("cannot find OpenType font file for reading");
}
callback_id = callback_defined(read_opentype_file_callback);
if (callback_id > 0) {
- if (run_callback(callback_id, "S->bSd", (char *) (nameoffile + 1),
+ if (run_callback(callback_id, "S->bSd", cur_file_name,
&file_opened, &ttf_buffer, &ttf_size) &&
file_opened && ttf_size > 0) {
} else {
pdftex_fail("cannot open OpenType font file for reading");
}
} else {
- if (!otf_open()) {
+ if (!otf_open(cur_file_name)) {
pdftex_fail("cannot open OpenType font file for reading");
}
ttf_read_file();
ttf_close();
}
- cur_file_name = (char *) nameoffile + 1;
fd_cur->ff_found = true;
- do_writeotf(fd);
+ do_writeotf(pdf, fd);
xfree(ttf_buffer);
cur_file_name = NULL;
}
-/*
- To calculate the checkSum for the 'head' table which itself includes the
- checkSumAdjustment entry for the entire font, do the following:
-
- * Set the checkSumAdjustment to 0.
- * Calculate the checksum for all the tables including the 'head' table
- and enter that value into the table directory.
- * Calculate the checksum for the entire font.
- * Subtract that value from the hex value B1B0AFBA.
- * Store the result in checkSumAdjustment.
-
- The checkSum for the 'head table which includes the checkSumAdjustment
- entry for the entire font is now incorrect. That is not a problem. Do not
- change it. An application attempting to verify that the 'head' table has
- not changed should calculate the checkSum for that table by not including
- the checkSumAdjustment value, and compare the result with the entry in the
- table directory.
-
- The table directory also includes the offset of the associated tagged
- table from the beginning of the font file and the length of that table.
- */
diff --git a/Build/source/texk/web2c/luatexdir/font/writetype0.c b/Build/source/texk/web2c/luatexdir/font/writetype0.c
deleted file mode 100644
index 796c6e5aa37..00000000000
--- a/Build/source/texk/web2c/luatexdir/font/writetype0.c
+++ /dev/null
@@ -1,125 +0,0 @@
-/* writetype0.c
-
- Copyright 2006-2008 Taco Hoekwater <taco@luatex.org>
-
- This file is part of LuaTeX.
-
- LuaTeX 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 2 of the License, or (at your
- option) any later version.
-
- LuaTeX 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 Lesser General Public
- License for more details.
-
- You should have received a copy of the GNU General Public License along
- with LuaTeX; if not, see <http://www.gnu.org/licenses/>. */
-
-#include "ptexlib.h"
-#include "writettf.h"
-#include "writecff.h"
-
-static const char _svn_version[] =
- "$Id: writetype0.c 2271 2009-04-12 23:42:21Z oneiros $ $URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.40.6/source/texk/web2c/luatexdir/font/writetype0.c $";
-
-void writetype0(fd_entry * fd)
-{
- int callback_id;
- int file_opened = 0;
- char *ftemp = NULL;
- long i;
- dirtab_entry *tab;
- cff_font *cff;
-
- dir_tab = NULL;
- glyph_tab = NULL;
-
- fd_cur = fd; /* fd_cur is global inside writettf.c */
- assert(fd_cur->fm != NULL);
- assert(is_opentype(fd_cur->fm));
- assert(is_included(fd_cur->fm));
-
- set_cur_file_name(fd_cur->fm->ff_name);
- ttf_curbyte = 0;
- ttf_size = 0;
- callback_id = callback_defined(find_opentype_file_callback);
- if (callback_id > 0) {
- if (run_callback
- (callback_id, "S->S", (char *) (nameoffile + 1), &ftemp)) {
- if (ftemp != NULL && strlen(ftemp)) {
- free(nameoffile);
- namelength = strlen(ftemp);
- nameoffile = xmalloc(namelength + 2);
- strcpy((char *) (nameoffile + 1), ftemp);
- free(ftemp);
- }
- }
- }
- callback_id = callback_defined(read_opentype_file_callback);
- if (callback_id > 0) {
- if (run_callback(callback_id, "S->bSd", (char *) (nameoffile + 1),
- &file_opened, &ttf_buffer, &ttf_size) &&
- file_opened && ttf_size > 0) {
- } else {
- pdftex_fail("cannot open OpenType font file for reading");
- }
- } else {
- if (!otf_open()) {
- pdftex_fail("cannot open OpenType font file for reading");
- }
- ttf_read_file();
- ttf_close();
- }
-
- cur_file_name = (char *) nameoffile + 1;
- fd_cur->ff_found = true;
-
- if (tracefilenames) {
- if (is_subsetted(fd_cur->fm))
- tex_printf("<%s", cur_file_name);
- else
- tex_printf("<<%s", cur_file_name);
- }
- ttf_read_tabdir();
- /* read font parameters */
- if (ttf_name_lookup("head", false) != NULL)
- ttf_read_head();
- if (ttf_name_lookup("hhea", false) != NULL)
- ttf_read_hhea();
- if (ttf_name_lookup("PCLT", false) != NULL)
- ttf_read_pclt();
- if (ttf_name_lookup("post", false) != NULL)
- ttf_read_post();
-
- /* copy font file */
- tab = ttf_seek_tab("CFF ", 0);
-
- /* TODO the next 0 is a subfont index */
- cff = read_cff(ttf_buffer + ttf_curbyte, tab->length, 0);
- if (cff != NULL) {
- if (cff_is_cidfont(cff)) {
- write_cid_cff(cff, fd_cur);
- /*
- for (i = tab->length; i > 0; i--)
- fb_putchar (ttf_getnum(1));
- */
- } else {
- write_cff(cff, fd_cur);
- }
- } else {
- /* not understood, just do a copy */
- for (i = tab->length; i > 0; i--)
- fb_putchar(ttf_getnum(1));
- }
- xfree(dir_tab);
- xfree(ttf_buffer);
- if (tracefilenames) {
- if (is_subsetted(fd_cur->fm))
- tex_printf(">");
- else
- tex_printf(">>");
- }
- cur_file_name = NULL;
-}
diff --git a/Build/source/texk/web2c/luatexdir/font/writetype0.w b/Build/source/texk/web2c/luatexdir/font/writetype0.w
new file mode 100644
index 00000000000..f902ad89a2a
--- /dev/null
+++ b/Build/source/texk/web2c/luatexdir/font/writetype0.w
@@ -0,0 +1,123 @@
+% writetype0.w
+%
+% Copyright 2006-2008 Taco Hoekwater <taco@@luatex.org>
+
+% This file is part of LuaTeX.
+
+% LuaTeX 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 2 of the License, or (at your
+% option) any later version.
+
+% LuaTeX 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 Lesser General Public
+% License for more details.
+
+% You should have received a copy of the GNU General Public License along
+% with LuaTeX; if not, see <http://www.gnu.org/licenses/>.
+
+@ @c
+#include "ptexlib.h"
+#include "font/writettf.h"
+#include "font/writecff.h"
+
+static const char _svn_version[] =
+ "$Id: writetype0.w 3584 2010-04-02 17:45:55Z hhenkel $ "
+"$URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.60.0/source/texk/web2c/luatexdir/font/writetype0.w $";
+
+@ @c
+void writetype0(PDF pdf, fd_entry * fd)
+{
+ int callback_id;
+ int file_opened = 0;
+ long i;
+ dirtab_entry *tab;
+ cff_font *cff;
+
+ dir_tab = NULL;
+ glyph_tab = NULL;
+
+ fd_cur = fd; /* |fd_cur| is global inside \.{writettf.w} */
+ assert(fd_cur->fm != NULL);
+ assert(is_opentype(fd_cur->fm));
+ assert(is_included(fd_cur->fm));
+
+ ttf_curbyte = 0;
+ ttf_size = 0;
+ cur_file_name =
+ luatex_find_file(fd_cur->fm->ff_name, find_opentype_file_callback);
+ if (cur_file_name == NULL) {
+ pdftex_fail("cannot find OpenType font file for reading");
+ }
+ callback_id = callback_defined(read_opentype_file_callback);
+ if (callback_id > 0) {
+ if (run_callback(callback_id, "S->bSd", cur_file_name,
+ &file_opened, &ttf_buffer, &ttf_size) &&
+ file_opened && ttf_size > 0) {
+ } else {
+ pdftex_fail("cannot open OpenType font file for reading");
+ }
+ } else {
+ if (!otf_open(cur_file_name)) {
+ pdftex_fail("cannot open OpenType font file for reading");
+ }
+ ttf_read_file();
+ ttf_close();
+ }
+
+ fd_cur->ff_found = true;
+
+ if (tracefilenames) {
+ if (is_subsetted(fd_cur->fm))
+ tex_printf("<%s", cur_file_name);
+ else
+ tex_printf("<<%s", cur_file_name);
+ }
+ ttf_read_tabdir();
+ /* read font parameters */
+ if (ttf_name_lookup("head", false) != NULL)
+ ttf_read_head();
+ if (ttf_name_lookup("hhea", false) != NULL)
+ ttf_read_hhea();
+ if (ttf_name_lookup("PCLT", false) != NULL)
+ ttf_read_pclt();
+ if (ttf_name_lookup("post", false) != NULL)
+ ttf_read_post();
+
+ /* copy font file */
+ tab = ttf_seek_tab("CFF ", 0);
+
+ /* TODO the next 0 is a subfont index */
+ cff = read_cff(ttf_buffer + ttf_curbyte, (long) tab->length, 0);
+ if (!is_subsetted(fd_cur->fm)) {
+ /* not subsetted, just do a copy */
+ for (i = (long) tab->length; i > 0; i--)
+ fb_putchar(pdf, (eight_bits) ttf_getnum(1));
+ } else {
+ if (cff != NULL) {
+ if (cff_is_cidfont(cff)) {
+ write_cid_cff(pdf, cff, fd_cur);
+#if 0
+ for (i = tab->length; i > 0; i--)
+ fb_putchar (ttf_getnum(1));
+#endif
+ } else {
+ write_cff(pdf, cff, fd_cur);
+ }
+ } else {
+ /* not understood, just do a copy */
+ for (i = (long) tab->length; i > 0; i--)
+ fb_putchar(pdf, (eight_bits) ttf_getnum(1));
+ }
+ }
+ xfree(dir_tab);
+ xfree(ttf_buffer);
+ if (tracefilenames) {
+ if (is_subsetted(fd_cur->fm))
+ tex_printf(">");
+ else
+ tex_printf(">>");
+ }
+ cur_file_name = NULL;
+}
diff --git a/Build/source/texk/web2c/luatexdir/font/writetype2.c b/Build/source/texk/web2c/luatexdir/font/writetype2.w
index 4d187b59a83..5081d9f0986 100644
--- a/Build/source/texk/web2c/luatexdir/font/writetype2.c
+++ b/Build/source/texk/web2c/luatexdir/font/writetype2.w
@@ -1,39 +1,43 @@
-/* writetype0.c
-
- Copyright 2006-2008 Taco Hoekwater <taco@luatex.org>
-
- This file is part of LuaTeX.
-
- LuaTeX 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 2 of the License, or (at your
- option) any later version.
-
- LuaTeX 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 Lesser General Public
- License for more details.
-
- You should have received a copy of the GNU General Public License along
- with LuaTeX; if not, see <http://www.gnu.org/licenses/>. */
-
+% writetype0.w
+%
+% Copyright 2006-2010 Taco Hoekwater <taco@@luatex.org>
+%
+% This file is part of LuaTeX.
+%
+% LuaTeX 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 2 of the License, or (at your
+% option) any later version.
+%
+% LuaTeX 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 Lesser General Public
+% License for more details.
+%
+% You should have received a copy of the GNU General Public License along
+% with LuaTeX; if not, see <http://www.gnu.org/licenses/>.
+
+@ @c
#include "ptexlib.h"
-#include "writettf.h"
-#include "writecff.h"
+#include "font/writettf.h"
+#include "font/writecff.h"
+#include "lua/luatex-api.h"
-#include "sfnt.h"
-#include "tt_glyf.h"
+#include "font/sfnt.h"
+#include "font/tt_glyf.h"
static const char _svn_version[] =
- "$Id: writetype2.c 2271 2009-04-12 23:42:21Z oneiros $ $URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.40.6/source/texk/web2c/luatexdir/font/writetype2.c $";
+ "$Id: writetype2.w 3584 2010-04-02 17:45:55Z hhenkel $ $URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.60.0/source/texk/web2c/luatexdir/font/writetype2.w $";
-/* forward*/
-void make_tt_subset(fd_entry * fd, unsigned char *buffer, integer buflen);
+@ forward declaration
+@c
+void make_tt_subset(PDF pdf, fd_entry * fd, unsigned char *buffer, int buflen);
+@ @c
unsigned long cidtogid_obj = 0;
-/* low-level helpers */
-
+@ low-level helpers
+@c
#define test_loc(l) \
if ((f->loc+l)>f->buflen) { \
fprintf (stderr,"File ended prematurely\n"); \
@@ -45,22 +49,22 @@ BYTE get_unsigned_byte(sfnt * f)
{
test_loc(1);
return (BYTE) f->buffer[(f->loc++)];
-};
+}
ICHAR get_signed_byte(sfnt * f)
{
test_loc(1);
return (ICHAR) f->buffer[(f->loc++)];
-};
+}
USHORT get_unsigned_pair(sfnt * f)
{
USHORT l;
test_loc(2);
l = f->buffer[(f->loc++)];
- l = l * 0x100 + f->buffer[(f->loc++)];
+ l = (USHORT) (l * 0x100 + f->buffer[(f->loc++)]);
return l;
-};
+}
SHORT get_signed_pair(sfnt * f)
{
@@ -70,8 +74,8 @@ SHORT get_signed_pair(sfnt * f)
if (l > 0x80)
l -= 0x100;
l = l * 0x100 + f->buffer[(f->loc++)];
- return l;
-};
+ return (SHORT) l;
+}
ULONG get_unsigned_quad(sfnt * f)
{
@@ -82,7 +86,7 @@ ULONG get_unsigned_quad(sfnt * f)
l = l * 0x100 + f->buffer[(f->loc++)];
l = l * 0x100 + f->buffer[(f->loc++)];
return l;
-};
+}
int do_sfnt_read(unsigned char *dest, int len, sfnt * f)
{
@@ -93,7 +97,7 @@ int do_sfnt_read(unsigned char *dest, int len, sfnt * f)
}
f->loc += len;
return len;
-};
+}
pdf_obj *pdf_new_stream(void)
{
@@ -101,22 +105,23 @@ pdf_obj *pdf_new_stream(void)
stream->length = 0;
stream->data = NULL;
return stream;
-};
+}
void pdf_add_stream(pdf_obj * stream, unsigned char *buf, long len)
{
int i;
assert(stream != NULL);
if (stream->data == NULL) {
- stream->data = xmalloc(len);
+ stream->data = xmalloc((unsigned) len);
} else {
- stream->data = xrealloc(stream->data, len + stream->length);
+ stream->data =
+ xrealloc(stream->data, (unsigned) len + (unsigned) stream->length);
}
for (i = 0; i < len; i++) {
*(stream->data + stream->length + i) = *(buf + i);
}
- stream->length += len;
-};
+ stream->length += (unsigned) len;
+}
void pdf_release_obj(pdf_obj * stream)
{
@@ -126,61 +131,45 @@ void pdf_release_obj(pdf_obj * stream)
}
xfree(stream);
}
-};
-
+}
-void writetype2(fd_entry * fd)
+@ The main function.
+@c
+void writetype2(PDF pdf, fd_entry * fd)
{
int callback_id;
int file_opened = 0;
- char *ftemp = NULL;
glyph_tab = NULL;
- fd_cur = fd; /* fd_cur is global inside writettf.c */
+ fd_cur = fd; /* |fd_cur| is global inside \.{writettf.w} */
assert(fd_cur->fm != NULL);
assert(is_truetype(fd_cur->fm));
-
- if (!is_subsetted(fd_cur->fm)) {
- writettf(fd);
- return;
- }
-
assert(is_included(fd_cur->fm));
- set_cur_file_name(fd_cur->fm->ff_name);
ttf_curbyte = 0;
ttf_size = 0;
- callback_id = callback_defined(find_opentype_file_callback);
- if (callback_id > 0) {
- if (run_callback
- (callback_id, "S->S", (char *) (nameoffile + 1), &ftemp)) {
- if (ftemp != NULL && strlen(ftemp)) {
- free(nameoffile);
- namelength = strlen(ftemp);
- nameoffile = xmalloc(namelength + 2);
- strcpy((char *) (nameoffile + 1), ftemp);
- free(ftemp);
- }
- }
+ cur_file_name =
+ luatex_find_file(fd_cur->fm->ff_name, find_opentype_file_callback);
+ if (cur_file_name == NULL) {
+ pdftex_fail("cannot find OpenType font file for reading");
}
callback_id = callback_defined(read_opentype_file_callback);
if (callback_id > 0) {
- if (run_callback(callback_id, "S->bSd", (char *) (nameoffile + 1),
+ if (run_callback(callback_id, "S->bSd", cur_file_name,
&file_opened, &ttf_buffer, &ttf_size) &&
file_opened && ttf_size > 0) {
} else {
pdftex_fail("cannot open OpenType font file for reading");
}
} else {
- if (!otf_open()) {
+ if (!otf_open(cur_file_name)) {
pdftex_fail("cannot open OpenType font file for reading");
}
ttf_read_file();
ttf_close();
}
- cur_file_name = (char *) nameoffile + 1;
fd_cur->ff_found = true;
if (tracefilenames) {
@@ -192,9 +181,10 @@ void writetype2(fd_entry * fd)
/* here is the real work */
- make_tt_subset(fd, ttf_buffer, ttf_size);
-
- /*xfree (dir_tab); */
+ make_tt_subset(pdf, fd, ttf_buffer, ttf_size);
+#if 0
+ xfree (dir_tab);
+#endif
xfree(ttf_buffer);
if (tracefilenames) {
if (is_subsetted(fd_cur->fm))
@@ -205,28 +195,27 @@ void writetype2(fd_entry * fd)
cur_file_name = NULL;
}
-/*
- * PDF viewer applications use following tables (CIDFontType 2)
- *
- * head, hhea, loca, maxp, glyf, hmtx, fpgm, cvt_, prep
- *
- * - from PDF Ref. v.1.3, 2nd ed.
- *
- * The fpgm, cvt_, and prep tables appears only when TrueType instructions
- * requires them. Those tables must be preserved if they exist.
- * We use must_exist flag to indicate `preserve it if present'
- * and to make sure not to cause an error when it does not exist.
- *
- * post and name table must exist in ordinary TrueType font file,
- * but when a TrueType font is converted to CIDFontType 2 font, those tables
- * are no longer required.
- *
- * The OS/2 table (required for TrueType font for Windows and OS/2) contains
- * liscencing information, but PDF viewers seems not using them.
- *
- * The 'name' table added. See comments in ttf.c.
- */
-
+@ PDF viewer applications use following tables (CIDFontType 2)
+
+\.{head, hhea, loca, maxp, glyf, hmtx, fpgm, cvt\_, prep}
+
+\rightline{from PDF Ref. v.1.3, 2nd ed.}
+
+ The \.{fpgm}, \.{cvt\_} and \.{prep} tables appears only when TrueType instructions
+ requires them. Those tables must be preserved if they exist.
+ We use |must_exist| flag to indicate `preserve it if present'
+ and to make sure not to cause an error when it does not exist.
+
+ \.{post} and \.{name} table must exist in ordinary TrueType font file,
+ but when a TrueType font is converted to CIDFontType 2 font, those tables
+ are no longer required.
+
+ The OS/2 table (required for TrueType font for Windows and OS/2) contains
+ liscencing information, but PDF viewers seems not using them.
+
+ The \.{name} table added. See comments in \.{writettf.w}.
+
+@c
static struct {
const char *name;
int must_exist;
@@ -237,7 +226,7 @@ static struct {
"head", 1}, {
"hhea", 1}, {
"loca", 1}, {
- "maxp", 1}, {
+ "maxp", 0}, {
"name", 1}, {
"glyf", 1}, {
"hmtx", 1}, {
@@ -248,9 +237,9 @@ static struct {
};
-static unsigned long ttc_read_offset(sfnt * sfont, int ttc_idx)
+unsigned long ttc_read_offset(sfnt * sfont, int ttc_idx)
{
- long version;
+ ULONG version;
unsigned long offset = 0;
unsigned long num_dirs = 0;
@@ -262,16 +251,15 @@ static unsigned long ttc_read_offset(sfnt * sfont, int ttc_idx)
fprintf(stderr, "Invalid TTC index number\n");
uexit(1);
}
-
sfnt_seek_set(sfont, 12 + ttc_idx * 4);
offset = sfnt_get_ulong(sfont);
return offset;
}
-#include <luafontloader/src/luafflib.h>
-
-void make_tt_subset(fd_entry * fd, unsigned char *buffer, integer buflen)
+@ Creating the subset.
+@c
+void make_tt_subset(PDF pdf, fd_entry * fd, unsigned char *buffer, int buflen)
{
long i, cid;
@@ -281,7 +269,7 @@ void make_tt_subset(fd_entry * fd, unsigned char *buffer, integer buflen)
unsigned char *cidtogidmap;
unsigned short num_glyphs, gid;
struct tt_glyphs *glyphs;
- char *used_chars;
+ char *used_chars = NULL;
sfnt *sfont;
pdf_obj *fontfile;
int verbose = 0, error = 0;
@@ -292,7 +280,9 @@ void make_tt_subset(fd_entry * fd, unsigned char *buffer, integer buflen)
if (sfont->type == SFNT_TYPE_TTC) {
i = ff_get_ttc_index(fd->fm->ff_name, fd->fm->ps_name);
- error = sfnt_read_table_directory(sfont, ttc_read_offset(sfont, i));
+ tex_printf("(%s:%ld)", (fd->fm->ps_name ? fd->fm->ps_name : ""), i);
+ error =
+ sfnt_read_table_directory(sfont, ttc_read_offset(sfont, (int) i));
} else {
error = sfnt_read_table_directory(sfont, 0);
}
@@ -301,72 +291,72 @@ void make_tt_subset(fd_entry * fd, unsigned char *buffer, integer buflen)
fprintf(stderr, "Could not parse the ttf directory.\n");
uexit(1);
}
+ if (is_subsetted(fd->fm)) {
+ /* rebuild the glyph tables and create a fresh cidmap */
+ glyphs = tt_build_init();
- glyphs = tt_build_init();
-
- last_cid = 0;
+ last_cid = 0;
- avl_t_init(&t, fd->gl_tree);
- for (found = (glw_entry *) avl_t_first(&t, fd->gl_tree);
- found != NULL; found = (glw_entry *) avl_t_next(&t)) {
- if (found->id > last_cid)
- last_cid = found->id;
- }
+ avl_t_init(&t, fd->gl_tree);
+ for (found = (glw_entry *) avl_t_first(&t, fd->gl_tree);
+ found != NULL; found = (glw_entry *) avl_t_next(&t)) {
+ if (found->id > last_cid)
+ last_cid = found->id;
+ }
#ifndef NO_GHOSTSCRIPT_BUG
- cidtogidmap = NULL;
+ cidtogidmap = NULL;
#else
- cidtogidmap = xmalloc(((last_cid + 1) * 2) * sizeof(unsigned char));
- memset(cidtogidmap, 0, (last_cid + 1) * 2);
+ cidtogidmap = xmalloc(((last_cid + 1) * 2) * sizeof(unsigned char));
+ memset(cidtogidmap, 0, (last_cid + 1) * 2);
#endif
- /* fill used_chars */
- used_chars = xmalloc((last_cid + 1) * sizeof(char));
- memset(used_chars, 0, (last_cid + 1));
- avl_t_init(&t, fd->gl_tree);
- for (found = (glw_entry *) avl_t_first(&t, fd->gl_tree);
- found != NULL; found = (glw_entry *) avl_t_next(&t)) {
- used_chars[found->id] = 1;
- }
+ /* fill |used_chars| */
+ used_chars = xmalloc((last_cid + 1) * sizeof(char));
+ memset(used_chars, 0, (last_cid + 1));
+ avl_t_init(&t, fd->gl_tree);
+ for (found = (glw_entry *) avl_t_first(&t, fd->gl_tree);
+ found != NULL; found = (glw_entry *) avl_t_next(&t)) {
+ used_chars[found->id] = 1;
+ }
- /*
- * Map CIDs to GIDs.
- */
+ /* Map CIDs to GIDs. */
- num_glyphs = 1; /* .notdef */
- for (cid = 1; cid <= (long) last_cid; cid++) {
- if (used_chars[cid] == 0)
- continue;
- gid = cid;
+ num_glyphs = 1; /* \.{.notdef} */
+ for (cid = 1; cid <= (long) last_cid; cid++) {
+ if (used_chars[cid] == 0)
+ continue;
+ gid = (short unsigned) cid;
#ifndef NO_GHOSTSCRIPT_BUG
- gid = tt_add_glyph(glyphs, gid, cid);
+ gid = tt_add_glyph(glyphs, (USHORT) gid, (USHORT) cid);
#else
- gid = tt_add_glyph(glyphs, gid, num_glyphs);
- cidtogidmap[2 * cid] = gid >> 8;
- cidtogidmap[2 * cid + 1] = gid & 0xff;
-#endif /* !NO_GHOSTSCRIPT_BUG */
+ gid = tt_add_glyph(glyphs, (USHORT) gid, (USHORT) num_glyphs);
+ cidtogidmap[2 * cid] = gid >> 8;
+ cidtogidmap[2 * cid + 1] = gid & 0xff;
+#endif /* |!NO_GHOSTSCRIPT_BUG| */
- num_glyphs++;
- }
+ num_glyphs++;
+ }
- if (num_glyphs == 1) {
- fprintf(stderr, "No glyphs in subset?.\n");
- uexit(1);
- }
+ if (num_glyphs == 1) {
+ fprintf(stderr, "No glyphs in subset?.\n");
+ uexit(1);
+ }
- if (tt_build_tables(sfont, glyphs) < 0) {
- fprintf(stderr, "Could not parse the ttf buffer.\n");
- uexit(1);
- }
+ if (tt_build_tables(sfont, glyphs) < 0) {
+ fprintf(stderr, "Could not parse the ttf buffer.\n");
+ uexit(1);
+ }
- if (verbose > 1) {
- fprintf(stdout, "[%u glyphs (Max CID: %u)]", glyphs->num_glyphs,
- last_cid);
- }
+ if (verbose > 1) {
+ fprintf(stdout, "[%u glyphs (Max CID: %u)]", glyphs->num_glyphs,
+ last_cid);
+ }
- tt_build_finish(glyphs);
+ tt_build_finish(glyphs);
+ }
/* Create font file */
@@ -387,30 +377,28 @@ void make_tt_subset(fd_entry * fd, unsigned char *buffer, integer buflen)
/* squeeze in the cidgidmap */
if (cidtogidmap != NULL) {
- cidtogid_obj = pdf_new_objnum();
- pdf_begin_dict(cidtogid_obj, 0);
- pdf_printf("/Length %i\n", ((last_cid + 1) * 2));
- pdf_end_dict();
- pdf_printf("stream\n");
- pdfroom((last_cid + 1) * 2);
+ cidtogid_obj = (unsigned long) pdf_new_objnum(pdf);
+ pdf_begin_dict(pdf, (int) cidtogid_obj, 0);
+ pdf_printf(pdf, "/Length %i\n", ((last_cid + 1) * 2));
+ pdf_end_dict(pdf);
+ pdf_printf(pdf, "stream\n");
+ pdf_room(pdf, (int) ((last_cid + 1) * 2));
for (i = 0; i < ((int) (last_cid + 1) * 2); i++) {
- pdf_buf[pdf_ptr++] = cidtogidmap[i];
+ pdf_quick_out(pdf, cidtogidmap[i]);
}
- pdf_printf("\nendstream\n");
+ pdf_printf(pdf, "\nendstream\n");
}
/* the tff subset */
for (i = 0; i < (int) (fontfile->length); i++)
- fb_putchar(fontfile->data[i]);
+ fb_putchar(pdf, fontfile->data[i]);
pdf_release_obj(fontfile);
- /* other stuff that needs fixing: */
+ /* TODO other stuff that needs fixing: */
- /*
- * DW, W, DW2, and W2
- */
- /*
+ /* DW, W, DW2, and W2 */
+#if 0
if (opt_flags & CIDFONT_FORCE_FIXEDPITCH) {
pdf_add_dict(font->fontdict,
pdf_new_name("DW"), pdf_new_number(1000.0));
@@ -419,12 +407,9 @@ void make_tt_subset(fd_entry * fd, unsigned char *buffer, integer buflen)
if (v_used_chars)
add_TTCIDVMetrics(font->fontdict, glyphs, used_chars, cidtogidmap, last_cid);
}
- */
-
- /*
- * CIDSet
- */
- /*
+#endif
+ /* CIDSet */
+#if 0
{
pdf_obj *cidset;
@@ -435,7 +420,7 @@ void make_tt_subset(fd_entry * fd, unsigned char *buffer, integer buflen)
pdf_ref_obj(cidset));
pdf_release_obj(cidset);
}
- */
+#endif
xfree(used_chars);
sfnt_close(sfont);
return;