📄 node.cc
字号:
hunits amount; node *n1; node *n2;public: kern_pair_node(hunits n, node *first, node *second, node *x = 0); ~kern_pair_node(); node *copy(); node *merge_glyph_node(glyph_node *); node *add_self(node *, hyphen_list **); hyphen_list *get_hyphen_list(hyphen_list *ss = 0); node *add_discretionary_hyphen(); hunits width(); node *last_char_node(); hunits italic_correction(); hunits subscript_correction(); void tprint(troff_output_file *); hyphenation_type get_hyphenation_type(); int ends_sentence(); void ascii_print(ascii_output_file *); void asciify(macro *); int same(node *); const char *type();};class dbreak_node : public node { node *none; node *pre; node *post;public: dbreak_node(node *n, node *p, node *x = 0); ~dbreak_node(); node *copy(); node *merge_glyph_node(glyph_node *); node *add_discretionary_hyphen(); hunits width(); node *last_char_node(); hunits italic_correction(); hunits subscript_correction(); void tprint(troff_output_file *); breakpoint *get_breakpoints(hunits width, int ns, breakpoint *rest = 0, int is_inner = 0); int nbreaks(); int ends_sentence(); void split(int, node **, node **); hyphenation_type get_hyphenation_type(); void ascii_print(ascii_output_file *); void asciify(macro *); int same(node *); const char *type();};void *glyph_node::operator new(size_t n){ assert(n == sizeof(glyph_node)); if (!free_list) { const int BLOCK = 1024; free_list = (glyph_node *)new char[sizeof(glyph_node)*BLOCK]; for (int i = 0; i < BLOCK - 1; i++) free_list[i].next = free_list + i + 1; free_list[BLOCK-1].next = 0; } glyph_node *p = free_list; free_list = (glyph_node *)(free_list->next); p->next = 0; return p;}void *ligature_node::operator new(size_t n){ return new char[n];}void glyph_node::operator delete(void *p){ if (p) { ((glyph_node *)p)->next = free_list; free_list = (glyph_node *)p; }}void ligature_node::operator delete(void *p){ delete p;}glyph_node::glyph_node(charinfo *c, tfont *t, node *x) : ci(c), tf(t), node(x){#ifdef STORE_WIDTH wid = tf->get_width(ci);#endif}#ifdef STORE_WIDTHglyph_node::glyph_node(charinfo *c, tfont *t, hunits w, node *x) : ci(c), tf(t), wid(w), node(x){}#endifnode *glyph_node::copy(){#ifdef STORE_WIDTH return new glyph_node(ci, tf, wid);#else return new glyph_node(ci, tf);#endif}node *glyph_node::merge_self(node *nd){ return nd->merge_glyph_node(this);}int glyph_node::character_type(){ return tf->get_character_type(ci);}node *glyph_node::add_self(node *n, hyphen_list **p){ assert(ci->get_hyphenation_code() == (*p)->hyphenation_code); next = 0; node *nn; if (n == 0 || (nn = n->merge_glyph_node(this)) == 0) { next = n; nn = this; } if ((*p)->hyphen) nn = nn->add_discretionary_hyphen(); hyphen_list *pp = *p; *p = (*p)->next; delete pp; return nn;}int glyph_node::overlaps_horizontally(){ return ci->overlaps_horizontally();}int glyph_node::overlaps_vertically(){ return ci->overlaps_vertically();}units glyph_node::size(){ return tf->get_size().to_units();}hyphen_list *glyph_node::get_hyphen_list(hyphen_list *tail){ return new hyphen_list(ci->get_hyphenation_code(), tail);}tfont *node::get_tfont(){ return 0;}tfont *glyph_node::get_tfont(){ return tf;}node *node::merge_glyph_node(glyph_node * /*gn*/){ return 0;}node *glyph_node::merge_glyph_node(glyph_node *gn){ if (tf == gn->tf) { charinfo *lig; if ((lig = tf->get_lig(ci, gn->ci)) != 0) { node *next1 = next; next = 0; return new ligature_node(lig, tf, this, gn, next1); } hunits kern; if (tf->get_kern(ci, gn->ci, &kern)) { node *next1 = next; next = 0; return new kern_pair_node(kern, this, gn, next1); } } return 0;}#ifdef STORE_WIDTHinline#endifhunits glyph_node::width(){#ifdef STORE_WIDTH return wid;#else return tf->get_width(ci);#endif}node *glyph_node::last_char_node(){ return this;}void glyph_node::vertical_extent(vunits *min, vunits *max){ *min = -tf->get_char_height(ci); *max = tf->get_char_depth(ci);}hunits glyph_node::skew(){ return tf->get_char_skew(ci);}hunits glyph_node::subscript_correction(){ return tf->get_subscript_correction(ci);}hunits glyph_node::italic_correction(){ return tf->get_italic_correction(ci);}hunits glyph_node::left_italic_correction(){ return tf->get_left_italic_correction(ci);}hyphenation_type glyph_node::get_hyphenation_type(){ return HYPHEN_MIDDLE;}int glyph_node::ends_sentence(){ if (ci->ends_sentence()) return 1; else if (ci->transparent()) return 2; else return 0;}void glyph_node::ascii_print(ascii_output_file *ascii){ unsigned char c = ci->get_ascii_code(); if (c != 0) ascii->outc(c); else ascii->outs(ci->nm.contents());}ligature_node::ligature_node(charinfo *c, tfont *t, node *gn1, node *gn2, node *x) : glyph_node(c, t, x), n1(gn1), n2(gn2){}#ifdef STORE_WIDTHligature_node::ligature_node(charinfo *c, tfont *t, hunits w, node *gn1, node *gn2, node *x) : glyph_node(c, t, w, x), n1(gn1), n2(gn2){}#endifligature_node::~ligature_node(){ delete n1; delete n2;}node *ligature_node::copy(){#ifdef STORE_WIDTH return new ligature_node(ci, tf, wid, n1->copy(), n2->copy());#else return new ligature_node(ci, tf, n1->copy(), n2->copy());#endif}void ligature_node::ascii_print(ascii_output_file *ascii){ n1->ascii_print(ascii); n2->ascii_print(ascii);}hyphen_list *ligature_node::get_hyphen_list(hyphen_list *tail){ return n1->get_hyphen_list(n2->get_hyphen_list(tail));}node *ligature_node::add_self(node *n, hyphen_list **p){ n = n1->add_self(n, p); n = n2->add_self(n, p); n1 = n2 = 0; delete this; return n;}kern_pair_node::kern_pair_node(hunits n, node *first, node *second, node *x) : node(x), n1(first), n2(second), amount(n){}dbreak_node::dbreak_node(node *n, node *p, node *x) : node(x), none(n), pre(p), post(0){}node *dbreak_node::merge_glyph_node(glyph_node *gn){ glyph_node *gn2 = (glyph_node *)gn->copy(); node *new_none = none ? none->merge_glyph_node(gn) : 0; node *new_post = post ? post->merge_glyph_node(gn2) : 0; if (new_none == 0 && new_post == 0) { delete gn2; return 0; } if (new_none != 0) none = new_none; else { gn->next = none; none = gn; } if (new_post != 0) post = new_post; else { gn2->next = post; post = gn2; } return this;}node *kern_pair_node::merge_glyph_node(glyph_node *gn){ node *nd = n2->merge_glyph_node(gn); if (nd == 0) return 0; n2 = nd; nd = n2->merge_self(n1); if (nd) { nd->next = next; n1 = 0; n2 = 0; delete this; return nd; } return this;}hunits kern_pair_node::italic_correction(){ return n2->italic_correction();}hunits kern_pair_node::subscript_correction(){ return n2->subscript_correction();}node *kern_pair_node::add_discretionary_hyphen(){ tfont *tf = n2->get_tfont(); if (tf) { if (tf->contains(soft_hyphen_char)) { node *next1 = next; next = 0; node *n = copy(); glyph_node *gn = new glyph_node(soft_hyphen_char, tf); node *nn = n->merge_glyph_node(gn); if (nn == 0) { gn->next = n; nn = gn; } return new dbreak_node(this, nn, next1); } } return this;}kern_pair_node::~kern_pair_node(){ if (n1 != 0) delete n1; if (n2 != 0) delete n2;}dbreak_node::~dbreak_node(){ delete_node_list(pre); delete_node_list(post); delete_node_list(none);}node *kern_pair_node::copy(){ return new kern_pair_node(amount, n1->copy(), n2->copy());}node *copy_node_list(node *n){ node *p = 0; while (n != 0) { node *nn = n->copy(); nn->next = p; p = nn; n = n->next; } while (p != 0) { node *pp = p->next; p->next = n; n = p; p = pp; } return n;}void delete_node_list(node *n){ while (n != 0) { node *tem = n; n = n->next; delete tem; }}node *dbreak_node::copy(){ dbreak_node *p = new dbreak_node(copy_node_list(none), copy_node_list(pre)); p->post = copy_node_list(post); return p;}hyphen_list *node::get_hyphen_list(hyphen_list *tail){ return tail;}hyphen_list *kern_pair_node::get_hyphen_list(hyphen_list *tail){ return n1->get_hyphen_list(n2->get_hyphen_list(tail));}class hyphen_inhibitor_node : public node {public: hyphen_inhibitor_node(node *nd = 0); node *copy(); int same(node *); const char *type(); hyphenation_type get_hyphenation_type();};hyphen_inhibitor_node::hyphen_inhibitor_node(node *nd) : node(nd){}node *hyphen_inhibitor_node::copy(){ return new hyphen_inhibitor_node;}int hyphen_inhibitor_node::same(node *){ return 1;}const char *hyphen_inhibitor_node::type(){ return "hyphen_inhibitor_node";}hyphenation_type hyphen_inhibitor_node::get_hyphenation_type(){ return HYPHEN_INHIBIT;}/* add_discretionary_hyphen methods */node *dbreak_node::add_discretionary_hyphen(){ if (post) post = post->add_discretionary_hyphen(); if (none) none = none->add_discretionary_hyphen(); return this;}node *node::add_discretionary_hyphen(){ tfont *tf = get_tfont(); if (!tf) return new hyphen_inhibitor_node(this); if (tf->contains(soft_hyphen_char)) { node *next1 = next; next = 0; node *n = copy(); glyph_node *gn = new glyph_node(soft_hyphen_char, tf); node *n1 = n->merge_glyph_node(gn); if (n1 == 0) { gn->next = n; n1 = gn; } return new dbreak_node(this, n1, next1); } return this;}node *node::merge_self(node *){ return 0;}node *node::add_self(node *n, hyphen_list ** /*p*/){ next = n; return this;}node *kern_pair_node::add_self(node *n, hyphen_list **p){ n = n1->add_self(n, p); n = n2->add_self(n, p); n1 = n2 = 0; delete this; return n;}hunits node::width(){ return H0;}node *node::last_char_node(){ return 0;}hunits hmotion_node::width(){ return n;}units node::size(){ return points_to_units(10);}hunits kern_pair_node::width(){ return n1->width() + n2->width() + amount;}node *kern_pair_node::last_char_node(){ node *nd = n2->last_char_node(); if (nd) return nd; return n1->last_char_node();}hunits dbreak_node::width(){ hunits x = H0; for (node *n = none; n != 0; n = n->next) x += n->width(); return x;}node *dbreak_node::last_char_node(){ for (node *n = none; n; n = n->next) { node *last = n->last_char_node(); if (last) return last; } return 0;}hunits dbreak_node::italic_correction(){ return none ? none->italic_correction() : H0;}hunits dbreak_node::subscript_correction(){ return none ? none->subscript_correction() : H0;}class italic_corrected_node : public node { node *n; hunits x;public: italic_corrected_node(node *, hunits, node * = 0); ~italic_corrected_node(); node *copy(); void ascii_print(ascii_output_file *); void asciify(macro *m); hunits width(); node *last_char_node(); void vertical_extent(vunits *, vunits *); int ends_sentence(); int overlaps_horizontally(); int overlaps_vertically(); int same(node *); hyphenation_type get_hyphenation_type(); tfont *get_tfont(); hyphen_list *get_hyphen_list(hyphen_list *ss = 0); int character_type(); void tprint(troff_output_file *); hunits subscript_correction(); hunits skew(); node *add_self(node *, hyphen_list **); const char *type();};node *node::add_italic_correction(hunits *width){ hunits ic = italic_correction(); if (ic.is_zero()) return this; else { node *next1 = next; next = 0; *width += ic; return new italic_corrected_node(this, ic, next1); }}italic_corrected_node::italic_corrected_node(node *nn, hunits xx, node *p): n(nn), x(xx), node(p){ assert(n != 0);}italic_corrected_node::~italic_corrected_node(){ delete n;}node *italic_corrected_node::copy(){ return new italic_corrected_node(n->copy(), x);}hunits italic_corrected_node::width(){ return n->width() + x;}void italic_corrected_node::vertical_extent(vunits *min, vunits *max){ n->vertical_extent(min, max);}void italic_corrected_node::tprint(troff_output_file *out){ n->tprint(out); out->right(x);}hunits italic_corrected_node::skew(){ return n->skew() - x/2;}hunits italic_corrected_node::subscript_correction(){ return n->subscript_correction() - x;}void italic_corrected_node::ascii_print(ascii_output_file *out)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -