[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Groff-commit] groff ./ChangeLog src/include/font.h src/libs/l...
From: |
Werner LEMBERG |
Subject: |
[Groff-commit] groff ./ChangeLog src/include/font.h src/libs/l... |
Date: |
Fri, 17 Feb 2006 16:23:21 +0000 |
CVSROOT: /cvsroot/groff
Module name: groff
Branch:
Changes by: Werner LEMBERG <address@hidden> 06/02/17 16:23:21
Modified files:
. : ChangeLog
src/include : font.h
src/libs/libgroff: nametoindex.cpp
src/roff/troff : charinfo.h input.cpp
Log message:
* src/include/font.h (struct glyphinfo): New class.
(struct glyph): Change internal representation.
Change constructor signature.
New method glyph::glyph_number().
(glyph::glyph, glyph glyph::undefined_glyph, glyph::glyph_index,
glyph::operator==, glyph::operator!=): Update.
(font::index_to_name, font::index_to_number): New functions.
* src/include/itable.h: New file, based on src/include/ptable.h.
* src/libs/libgroff/nametoindex.cpp: Include itable.h.
(class charinfo): New class.
(class character_indexer): Change table result type from `int' to
`class charinfo'.
Add table with integer key.
(character_indexer::character_indexer): Update.
(character_indexer::ascii_char_index): Update.
(character_indexer::numbered_char_index): Use NULL as name, not a
string starting with a space.
(character_indexer::named_char_index): Update.
(font::number_to_index, font::name_to_index): Remove no-op cast.
(glyph::glyph_name): New method.
* src/roff/troff/charinfo.h (class charinfo): Inherit from class
glyphinfo.
(NUMBERED): Remove flag bit.
(charinfo::numbered, charinfo::get_index): Update.
* src/roff/troff/input.cpp (charinfo::charinfo): Update.
(charinfo::set_number, charinfo::get_number): Update.
(glyph::glyph_name): New method.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/groff/groff/ChangeLog.diff?tr1=1.903&tr2=1.904&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/groff/groff/src/include/font.h.diff?tr1=1.12&tr2=1.13&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/groff/groff/src/libs/libgroff/nametoindex.cpp.diff?tr1=1.6&tr2=1.7&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/groff/groff/src/roff/troff/charinfo.h.diff?tr1=1.10&tr2=1.11&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/groff/groff/src/roff/troff/input.cpp.diff?tr1=1.30&tr2=1.31&r1=text&r2=text
Patches:
Index: groff/ChangeLog
diff -u groff/ChangeLog:1.903 groff/ChangeLog:1.904
--- groff/ChangeLog:1.903 Tue Feb 14 20:45:11 2006
+++ groff/ChangeLog Fri Feb 17 16:23:21 2006
@@ -1,3 +1,36 @@
+2006-02-15 Bruno Haible <address@hidden>
+
+ * src/include/font.h (struct glyphinfo): New class.
+ (struct glyph): Change internal representation.
+ Change constructor signature.
+ New method glyph::glyph_number().
+ (glyph::glyph, glyph glyph::undefined_glyph, glyph::glyph_index,
+ glyph::operator==, glyph::operator!=): Update.
+ (font::index_to_name, font::index_to_number): New functions.
+
+ * src/include/itable.h: New file, based on src/include/ptable.h.
+
+ * src/libs/libgroff/nametoindex.cpp: Include itable.h.
+ (class charinfo): New class.
+ (class character_indexer): Change table result type from `int' to
+ `class charinfo'.
+ Add table with integer key.
+ (character_indexer::character_indexer): Update.
+ (character_indexer::ascii_char_index): Update.
+ (character_indexer::numbered_char_index): Use NULL as name, not a
+ string starting with a space.
+ (character_indexer::named_char_index): Update.
+ (font::number_to_index, font::name_to_index): Remove no-op cast.
+ (glyph::glyph_name): New method.
+ * src/roff/troff/charinfo.h (class charinfo): Inherit from class
+ glyphinfo.
+ (NUMBERED): Remove flag bit.
+ (charinfo::numbered, charinfo::get_index): Update.
+
+ * src/roff/troff/input.cpp (charinfo::charinfo): Update.
+ (charinfo::set_number, charinfo::get_number): Update.
+ (glyph::glyph_name): New method.
+
2006-02-15 Werner LEMBERG <address@hidden>
* src/libs/libgroff/glyphuni.cpp (glyph_to_unicode_list): Fix
Index: groff/src/include/font.h
diff -u groff/src/include/font.h:1.12 groff/src/include/font.h:1.13
--- groff/src/include/font.h:1.12 Sat Feb 11 20:34:36 2006
+++ groff/src/include/font.h Fri Feb 17 16:23:21 2006
@@ -38,57 +38,70 @@
//
// - those with a number, referring to the the font-dependent glyph with
// the given number.
+
+// The statically allocated information about a glyph.
+//
+// This is an abstract class; only its subclass `charinfo' is instantiated.
+// `charinfo' exists in two versions: one in roff/troff/input.cpp for troff,
+// and one in libs/libgroff/nametoindex.cpp for the preprocessors and the
+// postprocessors.
+struct glyphinfo {
+ int index; // A font-independent integer value.
+ int number; // Glyph number or -1.
+ friend class character_indexer;
+};
+
struct glyph {
private:
- int index; // A font-independent integer value.
- const char *name; // Glyph name, statically allocated.
+ glyphinfo *ptr; // Pointer to the complete information.
friend class font;
friend class character_indexer;
friend class charinfo;
- glyph(int, const char *); // Glyph with given index and name.
+ glyph(glyphinfo *); // Glyph with given complete information.
public:
glyph(); // Uninitialized glyph.
static glyph undefined_glyph(); // Undefined glyph.
int glyph_index();
- const char *glyph_name();
+ const char *glyph_name(); // Return the glyph name or NULL.
+ int glyph_number(); // Return the glyph number or -1.
int operator==(const glyph &) const;
int operator!=(const glyph &) const;
};
-inline glyph::glyph(int idx, const char *nm)
-: index (idx), name (nm)
+inline glyph::glyph(glyphinfo *p)
+: ptr (p)
{
}
inline glyph::glyph()
-: index (0xdeadbeef), name (NULL)
+: ptr ((glyphinfo *) 0xdeadbeef)
{
}
inline glyph glyph::undefined_glyph()
{
- return glyph(-1, NULL);
+ return glyph(NULL);
}
#define UNDEFINED_GLYPH glyph::undefined_glyph()
inline int glyph::glyph_index()
{
- return index;
+ return ptr->index;
}
-inline const char *glyph::glyph_name()
+inline int glyph::glyph_number()
{
- return name;
+ return ptr->number;
}
inline int glyph::operator==(const glyph &other) const
{
- return index == other.index;
+ return ptr == other.ptr;
}
inline int glyph::operator!=(const glyph &other) const
{
- return index != other.index;
+ return ptr != other.ptr;
}
// Types used in non-public members of `class font'.
@@ -228,7 +241,7 @@
// info from there.
// The next two functions exist in two versions: one in
- // roff/troff/input.cpp for troff, and one for
+ // roff/troff/input.cpp for troff, and one in
// libs/libgroff/nametoindex.cpp for the preprocessors and the
// postprocessors.
static glyph name_to_index(const char *); // Convert the glyph with
@@ -241,6 +254,12 @@
// object. This has the same semantics as the groff
// escape sequence \N'number'. If such a `glyph'
// object does not yet exist, a new one is allocated.
+ static const char *index_to_name(glyph); // Convert the given glyph
+ // back to its name. Return NULL if the glyph
+ // doesn't have a name.
+ static int index_to_number(glyph); // Convert the given glyph back to
+ // its number. Return -1 if it does not designate
+ // a numbered character.
static FONT_COMMAND_HANDLER
set_unknown_desc_command_handler(FONT_COMMAND_HANDLER); // Register
@@ -355,4 +374,14 @@
// case of failure.
};
+inline const char *font::index_to_name(glyph g)
+{
+ return g.glyph_name();
+}
+
+inline int font::index_to_number(glyph g)
+{
+ return g.glyph_number();
+}
+
// end of font.h
Index: groff/src/libs/libgroff/nametoindex.cpp
diff -u groff/src/libs/libgroff/nametoindex.cpp:1.6
groff/src/libs/libgroff/nametoindex.cpp:1.7
--- groff/src/libs/libgroff/nametoindex.cpp:1.6 Sat Feb 11 20:34:37 2006
+++ groff/src/libs/libgroff/nametoindex.cpp Fri Feb 17 16:23:21 2006
@@ -28,9 +28,22 @@
#include "error.h"
#include "font.h"
#include "ptable.h"
+#include "itable.h"
-declare_ptable(int)
-implement_ptable(int)
+// Every glyphinfo is actually a charinfo.
+class charinfo : glyphinfo {
+private:
+ const char *name; // The glyph name, or NULL.
+public:
+ friend class character_indexer;
+ friend class glyph;
+};
+
+declare_ptable(charinfo)
+implement_ptable(charinfo)
+
+declare_itable(charinfo)
+implement_itable(charinfo)
class character_indexer {
public:
@@ -44,7 +57,8 @@
int next_index;
glyph ascii_index[256];
glyph small_number_index[NSMALL];
- PTABLE(int) table;
+ PTABLE(charinfo) table;
+ ITABLE(charinfo) ntable;
};
character_indexer::character_indexer()
@@ -52,9 +66,9 @@
{
int i;
for (i = 0; i < 256; i++)
- ascii_index[i] = glyph(-1, NULL);
+ ascii_index[i] = UNDEFINED_GLYPH;
for (i = 0; i < NSMALL; i++)
- small_number_index[i] = glyph(-1, NULL);
+ small_number_index[i] = UNDEFINED_GLYPH;
}
character_indexer::~character_indexer()
@@ -63,11 +77,15 @@
glyph character_indexer::ascii_char_index(unsigned char c)
{
- if (ascii_index[c].index < 0) {
+ if (ascii_index[c] == UNDEFINED_GLYPH) {
char buf[4+3+1];
memcpy(buf, "char", 4);
strcpy(buf + 4, i_to_a(c));
- ascii_index[c] = glyph(next_index++, strsave(buf));
+ charinfo *ci = new charinfo;
+ ci->index = next_index++;
+ ci->number = -1;
+ ci->name = strsave(buf);
+ ascii_index[c] = glyph(ci);
}
return ascii_index[c];
}
@@ -75,52 +93,62 @@
glyph character_indexer::numbered_char_index(int n)
{
if (n >= 0 && n < NSMALL) {
- if (small_number_index[n].index < 0)
- small_number_index[n] = glyph(next_index++, NULL);
+ if (small_number_index[n] == UNDEFINED_GLYPH) {
+ charinfo *ci = new charinfo;
+ ci->index = next_index++;
+ ci->number = n;
+ ci->name = NULL;
+ small_number_index[n] = glyph(ci);
+ }
return small_number_index[n];
}
- // Not the most efficient possible implementation.
- char buf[1 + 1 + INT_DIGITS + 1];
- buf[0] = ' ';
- strcpy(buf + 1, i_to_a(n));
- int *np = table.lookup(buf);
- if (!np) {
- np = new int[1];
- *np = next_index++;
- table.define(buf, np);
+ charinfo *ci = ntable.lookup(n);
+ if (ci == NULL) {
+ ci = new charinfo[1];
+ ci->index = next_index++;
+ ci->number = n;
+ ci->name = NULL;
+ ntable.define(n, ci);
}
- return glyph(*np, NULL);
+ return glyph(ci);
}
glyph character_indexer::named_char_index(const char *s)
{
- int *np = table.lookupassoc(&s);
- if (!np) {
- np = new int[1];
- *np = next_index++;
- s = table.define(s, np);
+ charinfo *ci = table.lookupassoc(&s);
+ if (ci == NULL) {
+ ci = new charinfo[1];
+ ci->index = next_index++;
+ ci->number = -1;
+ ci->name = table.define(s, ci);
}
- return glyph(*np, s);
+ return glyph(ci);
}
static character_indexer indexer;
glyph font::number_to_index(int n)
{
- return glyph(indexer.numbered_char_index(n));
+ return indexer.numbered_char_index(n);
}
glyph font::name_to_index(const char *s)
{
assert(s != 0 && s[0] != '\0' && s[0] != ' ');
if (s[1] == '\0')
- return glyph(indexer.ascii_char_index(s[0]));
+ return indexer.ascii_char_index(s[0]);
/* char128 and \200 are synonyms */
if (s[0] == 'c' && s[1] == 'h' && s[2] == 'a' && s[3] == 'r') {
char *val;
long n = strtol(s + 4, &val, 10);
if (val != s + 4 && *val == '\0' && n >= 0 && n < 256)
- return glyph(indexer.ascii_char_index((unsigned char)n));
+ return indexer.ascii_char_index((unsigned char)n);
}
- return glyph(indexer.named_char_index(s));
+ return indexer.named_char_index(s);
+}
+
+const char *glyph::glyph_name()
+{
+ charinfo *ci = (charinfo *)ptr; // Every glyphinfo is actually a charinfo.
+ return ci->name;
}
Index: groff/src/roff/troff/charinfo.h
diff -u groff/src/roff/troff/charinfo.h:1.10
groff/src/roff/troff/charinfo.h:1.11
--- groff/src/roff/troff/charinfo.h:1.10 Sat Feb 11 20:34:37 2006
+++ groff/src/roff/troff/charinfo.h Fri Feb 17 16:23:21 2006
@@ -21,11 +21,9 @@
class macro;
-class charinfo {
+class charinfo : glyphinfo {
static int next_index;
charinfo *translation;
- glyph index;
- int number;
macro *mac;
unsigned char special_translation;
unsigned char hyphenation_code;
@@ -39,14 +37,14 @@
// active for .asciify (set by .trin)
char_mode mode;
public:
- enum {
+ enum { // Values for the flags bitmask. See groff
+ // manual, description of the `.cflags' request.
ENDS_SENTENCE = 1,
BREAK_BEFORE = 2,
BREAK_AFTER = 4,
OVERLAPS_HORIZONTALLY = 8,
OVERLAPS_VERTICALLY = 16,
- TRANSPARENT = 32,
- NUMBERED = 64
+ TRANSPARENT = 32
};
enum {
TRANSLATE_NONE,
@@ -126,7 +124,7 @@
inline int charinfo::numbered()
{
- return flags & NUMBERED;
+ return number >= 0;
}
inline int charinfo::is_normal()
@@ -173,7 +171,7 @@
inline glyph charinfo::get_index()
{
- return index;
+ return glyph(this);
}
inline void charinfo::set_translation_input()
Index: groff/src/roff/troff/input.cpp
diff -u groff/src/roff/troff/input.cpp:1.30 groff/src/roff/troff/input.cpp:1.31
--- groff/src/roff/troff/input.cpp:1.30 Sat Feb 11 20:34:37 2006
+++ groff/src/roff/troff/input.cpp Fri Feb 17 16:23:21 2006
@@ -8094,7 +8094,8 @@
not_found(0), transparent_translate(1), translate_input(0),
mode(CHAR_NORMAL), nm(s)
{
- index = glyph(next_index++, s.contents());
+ index = next_index++;
+ number = -1;
}
void charinfo::set_hyphenation_code(unsigned char c)
@@ -8152,13 +8153,13 @@
void charinfo::set_number(int n)
{
+ assert(n >= 0);
number = n;
- flags |= NUMBERED;
}
int charinfo::get_number()
{
- assert(flags & NUMBERED);
+ assert(number >= 0);
return number;
}
@@ -8213,3 +8214,9 @@
{
return get_charinfo_by_number(n)->get_index();
}
+
+const char *glyph::glyph_name()
+{
+ charinfo *ci = (charinfo *)ptr; // Every glyphinfo is actually a charinfo.
+ return (ci->nm != UNNAMED_SYMBOL ? ci->nm.contents() : NULL);
+}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Groff-commit] groff ./ChangeLog src/include/font.h src/libs/l...,
Werner LEMBERG <=