📄 format.c
字号:
Area *HorizontalRule::format(Area::size_type w, int /*halign*/ ) const{ static const char *marker = Formatting::getString("HR.marker", "="); static BlockFormat bf("HR"); Area *res = new Area(bf.effective_width(w), 1, *marker ? *marker : ' '); *res >>= bf.indent_left; res->prepend(bf.vspace_before); res->append(bf.vspace_after); return res;}/* ------------------------------------------------------------------------- */// Attributes: ALIGN (processed)Area *Heading::format(Area::size_type w, int halign) const{ halign = get_attribute( attributes.get(), "ALIGN", halign, "LEFT", Area::LEFT, "CENTER", Area::CENTER, "RIGHT", Area::RIGHT, 0 ); static char cell_attributes[7]; if (!cell_attributes[0]) { cell_attributes[0] = 1; cell_attributes[1] = Formatting::getAttributes("H1.attributes", Cell::BOLD); cell_attributes[2] = Formatting::getAttributes("H2.attributes", Cell::BOLD); cell_attributes[3] = Formatting::getAttributes("H3.attributes", Cell::BOLD); cell_attributes[4] = Formatting::getAttributes("H4.attributes", Cell::BOLD); cell_attributes[5] = Formatting::getAttributes("H5.attributes", Cell::BOLD); cell_attributes[6] = Formatting::getAttributes("H6.attributes", Cell::BOLD); } auto_ptr<Area> res; auto_ptr<Line> line(::line_format(content.get())); if (line.get()) { static const char *prefixes[7]; if (!prefixes[1]) { prefixes[1] = Formatting::getString("H1.prefix", "****** "); prefixes[2] = Formatting::getString("H2.prefix", "***** " ); prefixes[3] = Formatting::getString("H3.prefix", "**** " ); prefixes[4] = Formatting::getString("H4.prefix", "*** " ); prefixes[5] = Formatting::getString("H5.prefix", "** " ); prefixes[6] = Formatting::getString("H6.prefix", "* " ); } auto_ptr<Line> l(new Line(prefixes[level])); l->insert(*line, l->length()); static const char *suffixes[7]; if (!suffixes[1]) { suffixes[1] = Formatting::getString("H1.suffix", " ******"); suffixes[2] = Formatting::getString("H2.suffix", " *****" ); suffixes[3] = Formatting::getString("H3.suffix", " ****" ); suffixes[4] = Formatting::getString("H4.suffix", " ***" ); suffixes[6] = Formatting::getString("H5.suffix", " **" ); suffixes[6] = Formatting::getString("H6.suffix", " *" ); } l->append(suffixes[level]); l->add_attribute(cell_attributes[level]); res.reset(make_up(*l, w, halign)); if (!res.get()) return 0; } else { /* * Hm. Heading is not line-formattable... */ res.reset(::format(content.get(), w, halign)); if (!res.get()) return 0; res->add_attribute(cell_attributes[level]); } static int vspace_before[7]; if (vspace_before[0] == 0) { vspace_before[0] = 1; vspace_before[1] = Formatting::getInt("H1.vspace.before", 0); vspace_before[2] = Formatting::getInt("H2.vspace.before", 0); vspace_before[3] = Formatting::getInt("H3.vspace.before", 0); vspace_before[4] = Formatting::getInt("H4.vspace.before", 0); vspace_before[5] = Formatting::getInt("H5.vspace.before", 0); vspace_before[6] = Formatting::getInt("H6.vspace.before", 0); } res->prepend(vspace_before[level]); static int vspace_after[7]; if (vspace_after[0] == 0) { vspace_after[0] = 1; vspace_after[1] = Formatting::getInt("H1.vspace.after", 0); vspace_after[2] = Formatting::getInt("H2.vspace.after", 0); vspace_after[3] = Formatting::getInt("H3.vspace.after", 0); vspace_after[4] = Formatting::getInt("H4.vspace.after", 0); vspace_after[5] = Formatting::getInt("H5.vspace.after", 0); vspace_after[6] = Formatting::getInt("H6.vspace.after", 0); } res->append(vspace_after[level]); return res.release();}// Attributes: WIDTH (processed)Area *Preformatted::format(Area::size_type w, int halign) const{ w = get_attribute(attributes.get(), "WIDTH", w); static BlockFormat bf("PRE"); /* * Attempt to line-format the <PRE>. */ auto_ptr<Area> res; auto_ptr<Line> line(::line_format(texts.get())); if (line.get()) { res.reset(make_up(*line, bf.effective_width(w), halign)); } /* * Failed; block-format it. */ if (!res.get()) { res.reset(::format(texts.get(), bf.effective_width(w), halign)); if (!res.get()) return 0; } *res >>= bf.indent_left; res->prepend(bf.vspace_before); res->append(bf.vspace_after); return res.release();}// Attributes: ALIGN (processed)Area *Paragraph::format(Area::size_type w, int halign) const{ if (!texts.get()) return 0; halign = get_attribute( attributes.get(), "ALIGN", halign, "LEFT", Area::LEFT, "CENTER", Area::CENTER, "RIGHT", Area::RIGHT, 0 ); static BlockFormat bf("P"); Area *res = ::format(texts.get(), bf.effective_width(w), halign); if (!res) return 0; *res >>= bf.indent_left; res->prepend(bf.vspace_before); res->append(bf.vspace_after); return res;}// Attributes: SRC ALT (processed) ALIGN HEIGHT WIDTH BORDER HSPACE VSPACE// USEMAP ISMAP (ignored)Line *Image::line_format() const{ { string alt(get_attribute(attributes.get(), "ALT", "")); replace_sgml_entities(&alt); if (!alt.empty()) return new Line('[' + alt + ']'); } { string src(get_attribute(attributes.get(), "SRC", "")); if (!src.empty()) return new Line('[' + src + ']'); } return new Line("[Image]");}// Attributes: CODEBASE CODE (ignored) ALT (processed) NAME WIDTH HEIGHT// (ignored) ALIGN (processed) HSPACE VSPACE (ignored)Area *Applet::format(Area::size_type w, int /*halign*/ ) const{ if (content.get()) { int halign = get_attribute( attributes.get(), "ALIGN", Area::CENTER, "LEFT", Area::LEFT, "MIDDLE", Area::CENTER, "RIGHT", Area::RIGHT, 0 ); Area *a = ::format(content.get(), w, halign); if (a) return a; } { string alt(get_attribute(attributes.get(), "ALT", "")); if (!alt.empty()) return new Area("[Java Applet: " + alt + ']'); } { string code(get_attribute(attributes.get(), "CODE", "")); if (!code.empty()) return new Area("[Java Applet " + code + ']'); } return new Area("[Java Applet]");}Line *Applet::line_format() const{ if (content.get()) { Line *l = ::line_format(content.get()); if (l) return l; } { string alt(get_attribute(attributes.get(), "ALT", "")); if (!alt.empty()) return new Line("[Java Applet: " + alt + ']'); } { string code(get_attribute(attributes.get(), "CODE", "")); if (!code.empty()) return new Line("[Java Applet " + code + ']'); } return new Line("[Java Applet]");}// Attributes: NAME HREF REL REV TITLE (ignored)// Attributes: ALIGN (processed)Area *Division::format(Area::size_type w, int halign) const{ return ::format(body_content.get(), w, get_attribute( attributes.get(), "ALIGN", halign, "LEFT", Area::LEFT, "CENTER", Area::CENTER, "RIGHT", Area::RIGHT, 0 ));}Area *Center::format(Area::size_type w, int /*halign*/ ) const{ return ::format(body_content.get(), w, Area::CENTER);}Area *BlockQuote::format(Area::size_type w, int halign) const{ static BlockFormat bf("BLOCKQUOTE", 0, 0, 5, 5); auto_ptr<Area> res(::format( content.get(), bf.effective_width(w), halign )); if (!res.get()) return 0; *res >>= bf.indent_left; res->prepend(bf.vspace_before); res->append(bf.vspace_after); return res.release();}Area *Address::format(Area::size_type w, int halign) const{ static BlockFormat bf("ADDRESS", 0, 0, 5, 5); auto_ptr<Area> res(::format( content.get(), bf.effective_width(w), halign )); if (!res.get()) return 0; *res >>= bf.indent_left; res->prepend(bf.vspace_before); res->append(bf.vspace_after); return res.release();}/* ------------------------------------------------------------------------- */// Attributes: ACTION METHOD ENCTYPE (ignored)Area *Form::format(Area::size_type w, int halign) const{ return content.get() ? ::format(content.get(), w, halign) : 0;}// Attributes: TYPE (processed) NAME (ignored) VALUE CHECKED SIZE (processed)// MAXLENGTH (ignored) SRC (processed) ALIGN (ignored)Line *Input::line_format() const{ string type = get_attribute(attributes.get(), "TYPE", "TEXT"); string name = get_attribute(attributes.get(), "NAME", ""); string value = get_attribute(attributes.get(), "VALUE", ""); bool checked = get_attribute(attributes.get(), "CHECKED", "0") != "0"; int size = get_attribute(attributes.get(), "SIZE", -1); string src = get_attribute(attributes.get(), "SRC", ""); string res; if (cmp_nocase(type, "TEXT") == 0) { if (size == -1) size = 20; if (value.empty()) value = name;// if ((int) value.length() > size) { value.erase(size); } else if ((int) value.length() < size) value.append(size - value.length(), ' '); res = '[' + value + ']'; } else if (cmp_nocase(type, "PASSWORD") == 0) { if (size == -1) size = 20; res = '[' + string(size, '*') + ']'; } else if (cmp_nocase(type, "CHECKBOX") == 0) { res = checked ? '*' : LATIN1_ordm; // "ordm" looks like a superscript zero. } else if (cmp_nocase(type, "RADIO") == 0) { res = checked ? '#' : 'o'; } else if (cmp_nocase(type, "SUBMIT") == 0) { res = value.empty() ? string("[Submit]") : '[' + value + ']'; } else if (cmp_nocase(type, "IMAGE") == 0) { res = "[Submit " + src + ']'; } else if (cmp_nocase(type, "RESET") == 0) { res = value.empty() ? string("[Reset]") : '[' + value + ']'; } else if (cmp_nocase(type, "FILE") == 0) { res = "[File]"; } else if (cmp_nocase(type, "HIDDEN") == 0) { return 0; } else { res = "[Unknown INPUT type]"; } return new Line(res);}// Attributes: NAME SIZE (ignored) MULTIPLE (processed)Line *Select::line_format() const{ if (!content.get() || content->empty()) return new Line("[Empty selection]"); bool multiple = get_attribute(attributes.get(), "MULTIPLE", "0") != "0"; auto_ptr<Line> res(new Line(multiple ? "[One or more of " : "[One of: ")); const list<auto_ptr<Option> > &c(*content); list<auto_ptr<Option> >::const_iterator i; for (i = c.begin(); i != c.end(); ++i) { if (!(*i).get()) continue; if (i != c.begin()) *res += '/'; auto_ptr<Line> l((*i)->pcdata->line_format()); *res += *l; } *res += ']'; return res.release();}// Attributes: NAME ROWS COLSArea *TextArea::format(Area::size_type w, int halign) const{ auto_ptr<Line> line(pcdata->line_format()); return line.get() ? make_up(*line, w, halign) : 0;}/* ------------------------------------------------------------------------- */Line *PCData::line_format() const{ return new Line(text);}// Item: Default cell attribute:// <TT> <I> => NONE// <B> => BOLD// <U> => UNDERLINE// <STRIKE> => STRIKETHROUGH// <BIG> <SMALL> <SUB> <SUP> => NONEstatic charget_font_cell_attributes(int attribute){ if (attribute == HTMLParser::TT) { static char a = Formatting::getAttributes("TT.attributes", Cell::NONE); return a; } else if (attribute == HTMLParser::I) { static char a = Formatting::getAttributes("I.attributes", Cell::NONE); return a; } else if (attribute == HTMLParser::B) { static char a = Formatting::getAttributes("B.attributes", Cell::BOLD); return a; } else if (attribute == HTMLParser::U) { static char a = Formatting::getAttributes("U.attributes", Cell::UNDERLINE); return a; } else if (attribute == HTMLParser::STRIKE) { static char a = Formatting::getAttributes("STRIKE.attributes", Cell::STRIKETHROUGH); return a; } else if (attribute == HTMLParser::BIG) { static char a = Formatting::getAttributes("BIG.attributes", Cell::NONE); return a; } else if (attribute == HTMLParser::SMALL) { static char a = Formatting::getAttributes("SMALL.attributes", Cell::NONE); return a; } else if (attribute == HTMLParser::SUB) { static char a = Formatting::getAttributes("SUB.attributes", Cell::NONE); return a; } else if (attribute == HTMLParser::SUP) { static char a = Formatting::getAttributes("SUP.attributes", Cell::NONE); return a; } return Cell::NONE;}Line *Font::line_format() const{ auto_ptr<Line> res(::line_format(texts.get())); if (!res.get()) return 0; char a = get_font_cell_attributes(attribute); if (a != Cell::NONE) res->add_attribute(a); return res.release();}// Item: Default cell attribute:Area *Font::format(Area::size_type w, int halign) const{ auto_ptr<Area> res(::format(texts.get(), w, halign)); if (!res.get()) return 0; char a = get_font_cell_attributes(attribute); if (a != Cell::NONE) res->add_attribute(a); return res.release();}// Item: Default cell attribute:// <EM> <STRONG> => BOLD// <DFN> <CODE> <SAMP> <KBD> <VAR> <CITE> => NONEstatic charget_phrase_cell_attributes(int attribute){ if (attribute == HTMLParser::EM) { static char a = Formatting::getAttributes("EM.attributes", Cell::BOLD); return a; } else if (attribute == HTMLParser::STRONG) { static char a = Formatting::getAttributes("STRONG.attributes", Cell::BOLD); return a; } else if (attribute == HTMLParser::DFN) { static char a = Formatting::getAttributes("DFN.attributes", Cell::NONE); return a; } else if (attribute == HTMLParser::CODE) { static char a = Formatting::getAttributes("CODE.attributes", Cell::NONE); return a; } else if (attribute == HTMLParser::SAMP) { static char a = Formatting::getAttributes("SAMP.attributes", Cell::NONE); return a; } else if (attribute == HTMLParser::KBD) { static char a = Formatting::getAttributes("KBD.attributes", Cell::NONE); return a; } else if (attribute == HTMLParser::VAR) { static char a = Formatting::getAttributes("VAR.attributes", Cell::NONE); return a; } else if (attribute == HTMLParser::CITE) { static char a = Formatting::getAttributes("CITE.attributes", Cell::NONE); return a; } return Cell::NONE;}Line *Phrase::line_format() const{ auto_ptr<Line> res(::line_format(texts.get())); if (!res.get()) return 0; char a = get_phrase_cell_attributes(attribute); if (a != Cell::NONE) res->add_attribute(a); return res.release();}// EM STRONG => BOLD// DFN CODE SAMP KBD VAR CITE => (nothing)Area *Phrase::format(Area::size_type w, int halign) const{ auto_ptr<Area> res(::format(texts.get(), w, halign)); if (!res.get()) return 0; char a = get_phrase_cell_attributes(attribute); if (a != Cell::NONE) res->add_attribute(a); return res.release();}// Attributes: SIZE COLOR (ignored)Area *Font2::format(Area::size_type w, int halign) const{ return ::format(elements.get(), w, halign);}// Attributes: SIZE COLOR (ignored)Line *Font2::line_format() const{ return ::line_format(elements.get());
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -