📄 node.cc
字号:
{ ascii->outc(' ');}/* asciify methods */void node::asciify(macro *m){ m->append(this);} void glyph_node::asciify(macro *m){ unsigned char c = ci->get_ascii_code(); if (c != 0) { m->append(c); delete this; } else m->append(this);}void kern_pair_node::asciify(macro *m){ n1->asciify(m); n2->asciify(m); n1 = n2 = 0; delete this;}static void asciify_reverse_node_list(macro *m, node *n){ if (n == 0) return; asciify_reverse_node_list(m, n->next); n->asciify(m);}void dbreak_node::asciify(macro *m){ asciify_reverse_node_list(m, none); none = 0; delete this;}void ligature_node::asciify(macro *m){ n1->asciify(m); n2->asciify(m); n1 = n2 = 0; delete this;}void break_char_node::asciify(macro *m){ ch->asciify(m); ch = 0; delete this;}void italic_corrected_node::asciify(macro *m){ n->asciify(m); n = 0; delete this;}void left_italic_corrected_node::asciify(macro *m){ if (n) { n->asciify(m); n = 0; } delete this;}space_char_hmotion_node::space_char_hmotion_node(hunits i, node *next): hmotion_node(i, next){}void space_char_hmotion_node::asciify(macro *m){ m->append(' '); delete this;}void line_start_node::asciify(macro *){ delete this;}void vertical_size_node::asciify(macro *){ delete this;}breakpoint *node::get_breakpoints(hunits /*width*/, int /*nspaces*/, breakpoint *rest, int /*is_inner*/){ return rest;}int node::nbreaks(){ return 0;}breakpoint *space_node::get_breakpoints(hunits width, int ns, breakpoint *rest, int is_inner){ if (next->discardable()) return rest; breakpoint *bp = new breakpoint; bp->next = rest; bp->width = width; bp->nspaces = ns; bp->hyphenated = 0; if (is_inner) { assert(rest != 0); bp->index = rest->index + 1; bp->nd = rest->nd; } else { bp->nd = this; bp->index = 0; } return bp;}int space_node::nbreaks(){ if (next->discardable()) return 0; else return 1;}static breakpoint *node_list_get_breakpoints(node *p, hunits *widthp, int ns, breakpoint *rest){ if (p != 0) { rest = p->get_breakpoints(*widthp, ns, node_list_get_breakpoints(p->next, widthp, ns, rest), 1); *widthp += p->width(); } return rest;}breakpoint *dbreak_node::get_breakpoints(hunits width, int ns, breakpoint *rest, int is_inner){ breakpoint *bp = new breakpoint; bp->next = rest; bp->width = width; for (node *tem = pre; tem != 0; tem = tem->next) bp->width += tem->width(); bp->nspaces = ns; bp->hyphenated = 1; if (is_inner) { assert(rest != 0); bp->index = rest->index + 1; bp->nd = rest->nd; } else { bp->nd = this; bp->index = 0; } return node_list_get_breakpoints(none, &width, ns, bp);}int dbreak_node::nbreaks(){ int i = 1; for (node *tem = none; tem != 0; tem = tem->next) i += tem->nbreaks(); return i;}void node::split(int /*where*/, node ** /*prep*/, node ** /*postp*/){ assert(0);}void space_node::split(int where, node **pre, node **post){ assert(where == 0); *pre = next; *post = 0; delete this;}static void node_list_split(node *p, int *wherep, node **prep, node **postp){ if (p == 0) return; int nb = p->nbreaks(); node_list_split(p->next, wherep, prep, postp); if (*wherep < 0) { p->next = *postp; *postp = p; } else if (*wherep < nb) { p->next = *prep; p->split(*wherep, prep, postp); } else { p->next = *prep; *prep = p; } *wherep -= nb;}void dbreak_node::split(int where, node **prep, node **postp){ assert(where >= 0); if (where == 0) { *postp = post; post = 0; if (pre == 0) *prep = next; else { for (node *tem = pre; tem->next != 0; tem = tem->next) ; tem->next = next; *prep = pre; } pre = 0; delete this; } else { *prep = next; where -= 1; node_list_split(none, &where, prep, postp); none = 0; delete this; }} hyphenation_type node::get_hyphenation_type(){ return HYPHEN_BOUNDARY;}hyphenation_type dbreak_node::get_hyphenation_type(){ return HYPHEN_INHIBIT;}hyphenation_type kern_pair_node::get_hyphenation_type(){ return HYPHEN_MIDDLE;}hyphenation_type dummy_node::get_hyphenation_type(){ return HYPHEN_MIDDLE;}hyphenation_type transparent_dummy_node::get_hyphenation_type(){ return HYPHEN_MIDDLE;}int node::interpret(macro *){ return 0;}special_node::special_node(const macro &m): mac(m){}int special_node::same(node *n){ return mac == ((special_node *)n)->mac;}const char *special_node::type(){ return "special_node";}node *special_node::copy(){ return new special_node(mac);}void special_node::tprint_start(troff_output_file *out){ out->start_special();}void special_node::tprint_char(troff_output_file *out, unsigned char c){ out->special_char(c);}void special_node::tprint_end(troff_output_file *out){ out->end_special();}/* composite_node */class composite_node : public node { charinfo *ci; node *n; tfont *tf;public: composite_node(node *, charinfo *, tfont *, node * = 0); ~composite_node(); node *copy(); hunits width(); node *last_char_node(); units size(); void tprint(troff_output_file *); hyphenation_type get_hyphenation_type(); int overlaps_horizontally(); int overlaps_vertically(); void ascii_print(ascii_output_file *); void asciify(macro *); hyphen_list *get_hyphen_list(hyphen_list *tail); node *add_self(node *, hyphen_list **); tfont *get_tfont(); int same(node *); const char *type(); void vertical_extent(vunits *, vunits *); vunits vertical_width();};composite_node::composite_node(node *p, charinfo *c, tfont *t, node *x): node(x), n(p), ci(c), tf(t){}composite_node::~composite_node(){ delete_node_list(n);}node *composite_node::copy(){ return new composite_node(copy_node_list(n), ci, tf);}hunits composite_node::width(){ hunits x; if (tf->get_constant_space(&x)) return x; x = H0; for (node *tem = n; tem; tem = tem->next) x += tem->width(); hunits offset; if (tf->get_bold(&offset)) x += offset; x += tf->get_track_kern(); return x;}node *composite_node::last_char_node(){ return this;}vunits composite_node::vertical_width(){ vunits v = V0; for (node *tem = n; tem; tem = tem->next) v += tem->vertical_width(); return v;}units composite_node::size(){ return tf->get_size().to_units();}hyphenation_type composite_node::get_hyphenation_type(){ return HYPHEN_MIDDLE;}int composite_node::overlaps_horizontally(){ return ci->overlaps_horizontally();}int composite_node::overlaps_vertically(){ return ci->overlaps_vertically();}void composite_node::asciify(macro *m){ unsigned char c = ci->get_ascii_code(); if (c != 0) { m->append(c); delete this; } else m->append(this);}void composite_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());}hyphen_list *composite_node::get_hyphen_list(hyphen_list *tail){ return new hyphen_list(ci->get_hyphenation_code(), tail);}node *composite_node::add_self(node *nn, hyphen_list **p){ assert(ci->get_hyphenation_code() == (*p)->hyphenation_code); next = nn; nn = this; if ((*p)->hyphen) nn = nn->add_discretionary_hyphen(); hyphen_list *pp = *p; *p = (*p)->next; delete pp; return nn;}tfont *composite_node::get_tfont(){ return tf;}node *reverse_node_list(node *n){ node *r = 0; while (n) { node *tem = n; n = n->next; tem->next = r; r = tem; } return r;}void composite_node::vertical_extent(vunits *min, vunits *max){ n = reverse_node_list(n); node_list_vertical_extent(n, min, max); n = reverse_node_list(n);}word_space_node::word_space_node(hunits d, node *x) : space_node(d, x){}word_space_node::word_space_node(hunits d, int s, node *x): space_node(d, s, x){}node *word_space_node::copy(){ return new word_space_node(n, set);}void word_space_node::tprint(troff_output_file *out){ out->word_marker(); space_node::tprint(out);}unbreakable_space_node::unbreakable_space_node(hunits d, node *x): word_space_node(d, x){}unbreakable_space_node::unbreakable_space_node(hunits d, int s, node *x): word_space_node(d, s, x){}node *unbreakable_space_node::copy(){ return new unbreakable_space_node(n, set);}breakpoint *unbreakable_space_node::get_breakpoints(hunits, int, breakpoint *rest, int){ return rest;}int unbreakable_space_node::nbreaks(){ return 0;}void unbreakable_space_node::split(int, node **, node **){ assert(0);}int unbreakable_space_node::merge_space(hunits){ return 0;}hvpair::hvpair(){}draw_node::draw_node(char c, hvpair *p, int np, font_size s) : code(c), npoints(np), sz(s){ point = new hvpair[npoints]; for (int i = 0; i < npoints; i++) point[i] = p[i];}int draw_node::same(node *n){ draw_node *nd = (draw_node *)n; if (code != nd->code || npoints != nd->npoints || sz != nd->sz) return 0; for (int i = 0; i < npoints; i++) if (point[i].h != nd->point[i].h || point[i].v != nd->point[i].v) return 0; return 1;}const char *draw_node::type(){ return "draw_node";}draw_node::~draw_node(){ if (point) a_delete point;}hunits draw_node::width(){ hunits x = H0; for (int i = 0; i < npoints; i++) x += point[i].h; return x;}vunits draw_node::vertical_width(){ if (code == 'e') return V0; vunits x = V0; for (int i = 0; i < npoints; i++) x += point[i].v; return x;}node *draw_node::copy(){ return new draw_node(code, point, npoints, sz);}void draw_node::tprint(troff_output_file *out){ out->draw(code, point, npoints, sz);} /* tprint methods */void glyph_node::tprint(troff_output_file *out){ tfont *ptf = tf->get_plain(); if (ptf == tf) out->put_char_width(ci, ptf, width(), H0); else { hunits offset; int bold = tf->get_bold(&offset); hunits w = ptf->get_width(ci); hunits k = H0; hunits x; int cs = tf->get_constant_space(&x); if (cs) { x -= w; if (bold) x -= offset; hunits x2 = x/2; out->right(x2); k = x - x2; } else k = tf->get_track_kern(); if (bold) { out->put_char(ci, ptf); out->right(offset); } out->put_char_width(ci, ptf, w, k); }}void glyph_node::zero_width_tprint(troff_output_file *out){ tfont *ptf = tf->get_plain(); hunits offset; int bold = tf->get_bold(&offset); hunits x; int cs = tf->get_constant_space(&x); if (cs) { x -= ptf->get_width(ci); if (bold) x -= offset; x = x/2; out->right(x); } out->put_char(ci, ptf); if (bold) { out->right(offset); out->put_char(ci, ptf); out->right(-offset); } if (cs) out->right(-x);}void break_char_node::tprint(troff_output_file *t){ ch->tprint(t);}void break_char_node::zero_width_tprint(troff_output_file *t){ ch->zero_width_tprint(t);}void hline_node::tprint(troff_output_file *out){ if (x < H0) { out->right(x); x = -x; } if (n == 0) { out->right(x); return; } hunits w = n->width(); if (w <= H0) { error("horizontal line drawing character must have positive width"); out->right(x); return; } int i = int(x/w); if (i == 0) { hunits xx = x - w; hunits xx2 = xx/2; out->right(xx2); n->tprint(out); out->right(xx - xx2); } else { hunits rem = x - w*i; if (rem > H0) if (n->overlaps_horizontally()) { n->tprint(out); out->right(rem - w); } else out->right(rem); while (--i >= 0) n->tpr
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -