summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/font.c93
-rw-r--r--lib/font.h2
-rw-r--r--lib/fontfile.c7
-rw-r--r--lib/lib.h13
-rw-r--r--lib/new.c4
-rw-r--r--lib/ptable.h6
-rw-r--r--lib/string.c8
-rw-r--r--lib/tmpfile.c2
8 files changed, 104 insertions, 31 deletions
diff --git a/lib/font.c b/lib/font.c
index b6ec8a7f4..c23432779 100644
--- a/lib/font.c
+++ b/lib/font.c
@@ -52,6 +52,15 @@ struct font_kern_list {
font_kern_list(int, int, int, font_kern_list * = 0);
};
+struct font_widths_cache {
+ font_widths_cache *next;
+ int point_size;
+ int *width;
+
+ font_widths_cache(int, int, font_widths_cache *);
+ ~font_widths_cache();
+};
+
/* text_file */
struct text_file {
@@ -77,8 +86,8 @@ text_file::text_file(FILE *p, char *s)
text_file::~text_file()
{
- delete buf;
- delete path;
+ a_delete buf;
+ a_delete path;
if (fp)
fclose(fp);
}
@@ -105,7 +114,7 @@ int text_file::next()
char *old_buf = buf;
buf = new char[size*2];
memcpy(buf, old_buf, size);
- delete old_buf;
+ a_delete old_buf;
size *= 2;
}
buf[i++] = c;
@@ -139,7 +148,7 @@ void text_file::error(const char *format,
font::font(const char *s)
: special(0), ligatures(0), kern_hash_table(0), space_width(0),
- ch(0), ch_used(0), ch_size(0), ch_index(0), nindices(0)
+ ch(0), ch_used(0), ch_size(0), ch_index(0), nindices(0), widths_cache(0)
{
name = new char[strlen(s) + 1];
strcpy(name, s);
@@ -150,8 +159,8 @@ font::font(const char *s)
font::~font()
{
- delete ch;
- delete ch_index;
+ a_delete ch;
+ a_delete ch_index;
if (kern_hash_table) {
for (int i = 0; i < KERN_HASH_TABLE_SIZE; i++) {
font_kern_list *kerns = kern_hash_table[i];
@@ -161,10 +170,15 @@ font::~font()
delete tem;
}
}
- delete kern_hash_table;
+ a_delete kern_hash_table;
+ }
+ a_delete name;
+ a_delete internalname;
+ while (widths_cache) {
+ font_widths_cache *tem = widths_cache;
+ widths_cache = widths_cache->next;
+ delete tem;
}
- delete name;
- delete internalname;
}
static int scale_round(int n, int x, int y)
@@ -176,12 +190,13 @@ static int scale_round(int n, int x, int y)
if (n >= 0) {
if (n <= (INT_MAX - y2)/x)
return (n*x + y2)/y;
+ return int(n*double(x)/double(y) + .5);
}
else {
if (-(unsigned)n <= (-(unsigned)INT_MIN - y2)/x)
return (n*x - y2)/y;
+ return int(n*double(x)/double(y) - .5);
}
- return int(n*double(x)/double(y) + .5);
}
inline int font::scale(int w, int sz)
@@ -205,10 +220,48 @@ int font::is_special()
return special;
}
+font_widths_cache::font_widths_cache(int ps, int ch_size,
+ font_widths_cache *p = 0)
+: next(p), point_size(ps)
+{
+ width = new int[ch_size];
+ for (int i = 0; i < ch_size; i++)
+ width[i] = -1;
+}
+
+font_widths_cache::~font_widths_cache()
+{
+ a_delete width;
+}
+
int font::get_width(int c, int point_size)
{
- assert(c >= 0 && c < nindices && ch_index[c] >= 0);
- return scale(ch[ch_index[c]].width, point_size);
+ assert(c >= 0 && c < nindices);
+ int i = ch_index[c];
+ assert(i >= 0);
+
+ if (point_size == unitwidth)
+ return ch[i].width;
+
+ if (!widths_cache)
+ widths_cache = new font_widths_cache(point_size, ch_size);
+ else if (widths_cache->point_size != point_size) {
+ for (font_widths_cache **p = &widths_cache; *p; p = &(*p)->next)
+ if ((*p)->point_size == point_size)
+ break;
+ if (*p) {
+ font_widths_cache *tem = *p;
+ *p = (*p)->next;
+ tem->next = widths_cache;
+ widths_cache = tem;
+ }
+ else
+ widths_cache = new font_widths_cache(point_size, ch_size, widths_cache);
+ }
+ int &w = widths_cache->width[i];
+ if (w < 0)
+ w = scale(ch[i].width, point_size);
+ return w;
}
int font::get_height(int c, int point_size)
@@ -325,7 +378,7 @@ void font::alloc_ch_index(int index)
memcpy(ch_index, old_ch_index, sizeof(short)*old_nindices);
for (int i = old_nindices; i < nindices; i++)
ch_index[i] = -1;
- delete old_ch_index;
+ a_delete old_ch_index;
}
}
@@ -339,7 +392,7 @@ void font::extend_ch()
font_char_metric *old_ch = ch;
ch = new font_char_metric[ch_size];
memcpy(ch, old_ch, old_ch_size*sizeof(font_char_metric));
- delete old_ch;
+ a_delete old_ch;
}
}
@@ -353,14 +406,14 @@ void font::compact()
short *old_ch_index = ch_index;
ch_index = new short[i];
memcpy(ch_index, old_ch_index, i*sizeof(short));
- delete old_ch_index;
+ a_delete old_ch_index;
nindices = i;
}
if (ch_used < ch_size) {
font_char_metric *old_ch = ch;
ch = new font_char_metric[ch_used];
memcpy(ch, old_ch, ch_used*sizeof(font_char_metric));
- delete old_ch;
+ a_delete old_ch;
ch_size = ch_used;
}
}
@@ -477,13 +530,13 @@ int font::load()
nargv *= 2;
argv = new char *[nargv];
memcpy(argv, old_argv, sizeof(char*)*old_nargv);
- delete old_argv;
+ a_delete old_argv;
}
argv[argc++] = p;
p = strtok(0, WS);
} while (p != 0);
handle_unknown_font_command(argc, argv);
- delete argv;
+ a_delete argv;
}
else
break;
@@ -757,7 +810,7 @@ int font::load_desc()
sizes = new int[n*2];
memcpy(sizes, old_sizes, n*sizeof(int));
n *= 2;
- delete old_sizes;
+ a_delete old_sizes;
}
sizes[i++] = lower;
if (lower == 0)
@@ -788,7 +841,7 @@ int font::load_desc()
style_table[j] = old_style_table[j];
for (; j < style_table_size; j++)
style_table[j] = 0;
- delete old_style_table;
+ a_delete old_style_table;
}
char *tem = new char[strlen(p) + 1];
strcpy(tem, p);
diff --git a/lib/font.h b/lib/font.h
index a8b7ffb5b..482b140cc 100644
--- a/lib/font.h
+++ b/lib/font.h
@@ -21,6 +21,7 @@ Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
struct font_kern_list;
struct font_char_metric;
+struct font_widths_cache;
class font {
public:
@@ -88,6 +89,7 @@ private:
char *name;
char *internalname;
double slant;
+ font_widths_cache *widths_cache;
static char *dev_name;
static char *cl_font_dirs;
diff --git a/lib/fontfile.c b/lib/fontfile.c
index 780368065..77c57c797 100644
--- a/lib/fontfile.c
+++ b/lib/fontfile.c
@@ -22,6 +22,7 @@ Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#include <string.h>
#include <assert.h>
#include <stdlib.h>
+#include <errno.h>
#include "font.h"
#include "lib.h"
#include "fontpath.h"
@@ -62,13 +63,13 @@ void font::command_line_font_dir(const char *dir)
if (need_colon)
strcat(cl_font_dirs, ":");
strcat(cl_font_dirs, dir);
- delete old_dirs;
+ a_delete old_dirs;
}
}
void font::forget_command_line_font_dirs()
{
- delete cl_font_dirs;
+ a_delete cl_font_dirs;
cl_font_dirs = 0;
}
@@ -107,7 +108,7 @@ FILE *font::open_file(const char *name, char **pathp)
*pathp = path;
return fp;
}
- delete path;
+ a_delete path;
if (*p == '\0')
break;
}
diff --git a/lib/lib.h b/lib/lib.h
index 14e0b6567..9e4350011 100644
--- a/lib/lib.h
+++ b/lib/lib.h
@@ -68,3 +68,16 @@ inline int illegal_input_char(int c)
(not including the -). */
#define INT_DIGITS 10
+
+/* ad_delete deletes an array of objects with destructors;
+a_delete deletes an array of objects without destructors */
+
+#ifdef ARRAY_DELETE_NEEDS_SIZE
+/* for 2.0 systems */
+#define ad_delete(size) delete [size]
+#define a_delete delete
+#else /* not ARRAY_DELETE_NEEDS_SIZE */
+/* for ARM systems */
+#define ad_delete(size) delete []
+#define a_delete delete []
+#endif /* not ARRAY_DELETE_NEEDS_SIZE */
diff --git a/lib/new.c b/lib/new.c
index 56fbe2a21..26ffe1974 100644
--- a/lib/new.c
+++ b/lib/new.c
@@ -29,7 +29,11 @@ static void ewrite(const char *s)
write(2, s, strlen(s));
}
+#ifdef __GNUG__
+void *__builtin_new(size_t size)
+#else
void *operator new(size_t size)
+#endif
{
char *p = (char *)malloc(unsigned(size));
if (p != 0)
diff --git a/lib/ptable.h b/lib/ptable.h
index 719fed74d..dd180da79 100644
--- a/lib/ptable.h
+++ b/lib/ptable.h
@@ -83,7 +83,7 @@ PTABLE(T)::PTABLE(T)() \
PTABLE(T)::~PTABLE(T)() \
{ \
for (unsigned i = 0; i < size; i++) { \
- delete v[i].key; \
+ a_delete v[i].key; \
delete v[i].val; \
} \
} \
@@ -110,7 +110,7 @@ void PTABLE(T)::define(const char *key, T *val) \
for (unsigned i = 0; i < old_size; i++) \
if (oldv[i].key != 0) { \
if (oldv[i].val == 0) \
- delete oldv[i].key; \
+ a_delete oldv[i].key; \
else { \
for (unsigned j = unsigned(hash_string(oldv[i].key) % size); \
v[j].key != 0; \
@@ -124,7 +124,7 @@ void PTABLE(T)::define(const char *key, T *val) \
v[n].key != 0; \
n = (n == 0 ? size - 1 : n - 1)) \
; \
- delete oldv; \
+ a_delete oldv; \
} \
char *temp = new char[strlen(key)+1]; \
strcpy(temp, key); \
diff --git a/lib/string.c b/lib/string.c
index d6a75684a..75325ee27 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -39,7 +39,7 @@ static char *salloc(int len, int *sizep)
static void sfree(char *ptr, int)
{
- delete ptr;
+ a_delete ptr;
}
static char *sfree_alloc(char *ptr, int oldsz, int len, int *sizep)
@@ -48,7 +48,7 @@ static char *sfree_alloc(char *ptr, int oldsz, int len, int *sizep)
*sizep = oldsz;
return ptr;
}
- delete ptr;
+ a_delete ptr;
if (len == 0) {
*sizep = 0;
return 0;
@@ -64,7 +64,7 @@ static char *srealloc(char *ptr, int oldsz, int oldlen, int newlen, int *sizep)
return ptr;
}
if (newlen == 0) {
- delete ptr;
+ a_delete ptr;
*sizep = 0;
return 0;
}
@@ -72,7 +72,7 @@ static char *srealloc(char *ptr, int oldsz, int oldlen, int newlen, int *sizep)
char *p = new char[*sizep = newlen*2];
if (oldlen < newlen && oldlen != 0)
memcpy(p, ptr, oldlen);
- delete ptr;
+ a_delete ptr;
return p;
}
}
diff --git a/lib/tmpfile.c b/lib/tmpfile.c
index c048b1832..b91893204 100644
--- a/lib/tmpfile.c
+++ b/lib/tmpfile.c
@@ -82,7 +82,7 @@ FILE *xtmpfile()
#endif /* not HAVE_MKSTEMP */
if (unlink(templ) < 0)
error("cannot unlink `%1': %2", templ, strerror(errno));
- delete templ;
+ a_delete templ;
return fp;
}