int InsetCommand::plaintext(odocstream & os, OutputParams const &) const { docstring const str = "[" + buffer().B_("LaTeX Command: ") + from_utf8(getCmdName()) + "]"; os << str; return str.size(); }
int InsetRef::plaintext(odocstringstream & os, OutputParams const &, size_t) const { docstring const str = getParam("reference"); os << '[' << str << ']'; return 2 + str.size(); }
void RowPainter::paintTopLevelLabel() const { BufferParams const & bparams = pi_.base.bv->buffer().params(); ParagraphParameters const & pparams = par_.params(); Layout const & layout = par_.layout(); FontInfo const font = labelFont(false); docstring const str = par_.labelString(); if (str.empty()) return; double spacing_val = 1.0; if (!pparams.spacing().isDefault()) spacing_val = pparams.spacing().getValue(); else spacing_val = bparams.spacing().getValue(); FontMetrics const & fm = theFontMetrics(font); int const labeladdon = int(fm.maxHeight() * layout.spacing.getValue() * spacing_val); int maxdesc = int(fm.maxDescent() * layout.spacing.getValue() * spacing_val + (layout.labelbottomsep * defaultRowHeight())); double x = x_; if (layout.labeltype == LABEL_CENTERED) { x += (tm_.width() - row_.left_margin - row_.right_margin) / 2; x -= fm.width(str) / 2; } else if (row_.isRTL()) { x = xo_ + tm_.width() - row_.right_margin - fm.width(str); } pi_.pain.text(int(x), yo_ - maxdesc - labeladdon, str, font); }
bool BranchList::add(docstring const & s) { bool added = false; size_t i = 0; while (true) { size_t const j = s.find_first_of(separator_, i); docstring name; if (j == docstring::npos) name = s.substr(i); else name = s.substr(i, j - i); // Is this name already in the list? bool const already = find_if(list.begin(), list.end(), BranchNamesEqual(name)) != list.end(); if (!already) { added = true; Branch br; br.setBranch(name); br.setSelected(false); br.setFileNameSuffix(false); list.push_back(br); } if (j == docstring::npos) break; i = j + 1; } return added; }
QValidator::State PathValidator::validate(QString & qtext, int &) const { if (!latex_doc_) return QValidator::Acceptable; docstring const text = support::trim(qstring_to_ucs4(qtext)); if (text.empty()) return acceptable_if_empty_ ? QValidator::Acceptable : QValidator::Intermediate; docstring invalid_chars = from_ascii("#$%{}()[]\"^"); if (!tex_allows_spaces_) invalid_chars += ' '; if (text.find_first_of(invalid_chars) != docstring::npos) { static int counter = 0; if (counter == 0) { Alert::error(_("Invalid filename"), _("LyX does not provide LaTeX support for file names containing any of these characters:\n") + printable_list(invalid_chars)); } ++counter; return QValidator::Intermediate; } return QValidator::Acceptable; }
int InsetText::plaintext(odocstringstream & os, OutputParams const & runparams, size_t max_length) const { ParagraphList::const_iterator beg = paragraphs().begin(); ParagraphList::const_iterator end = paragraphs().end(); ParagraphList::const_iterator it = beg; bool ref_printed = false; int len = 0; for (; it != end; ++it) { if (it != beg) { os << '\n'; if (runparams.linelen > 0) os << '\n'; } odocstringstream oss; writePlaintextParagraph(buffer(), *it, oss, runparams, ref_printed, max_length); docstring const str = oss.str(); os << str; // FIXME: len is not computed fully correctly; in principle, // we have to count the characters after the last '\n' len = str.size(); if (os.str().size() >= max_length) break; } return len; }
docstring InsetCitation::toolTip(BufferView const & bv, int, int) const { Buffer const & buf = bv.buffer(); // Only after the buffer is loaded from file... if (!buf.isFullyLoaded()) return docstring(); BiblioInfo const & bi = buf.masterBibInfo(); if (bi.empty()) return _("No bibliography defined!"); docstring const & key = getParam("key"); if (key.empty()) return _("No citations selected!"); vector<docstring> keys = getVectorFromString(key); vector<docstring>::const_iterator it = keys.begin(); vector<docstring>::const_iterator en = keys.end(); docstring tip; for (; it != en; ++it) { docstring const key_info = bi.getInfo(*it, buffer()); if (key_info.empty()) continue; if (!tip.empty()) tip += "\n"; tip += wrap(key_info, -4); } return tip; }
// FIXME XHTML // There are cases where we may need to close open fonts and such // and then re-open them when we are done. This would be the case, e.g., // if we were otherwise about to write: // <em>word <div class='foot'>footnote text.</div> emph</em> // The problem isn't so much that the footnote text will get emphasized: // we can handle that with CSS. The problem is that this is invalid XHTML. // One solution would be to make the footnote <span>, but the problem is // completely general, and so we'd have to make absolutely everything into // span. What I think will work is to check if we're about to write "div" and, // if so, try to close fonts, etc. // There are probably limits to how well we can do here, though, and we will // have to rely upon users not putting footnotes inside noun-type insets. docstring InsetText::insetAsXHTML(XHTMLStream & xs, OutputParams const & rp, XHTMLOptions opts) const { // we will always want to output all our paragraphs when we are // called this way. OutputParams runparams = rp; runparams.par_begin = 0; runparams.par_end = text().paragraphs().size(); if (undefined()) { xs.startDivision(false); xhtmlParagraphs(text_, buffer(), xs, runparams); xs.endDivision(); return docstring(); } InsetLayout const & il = getLayout(); if (opts & WriteOuterTag) xs << html::StartTag(il.htmltag(), il.htmlattr()); if ((opts & WriteLabel) && !il.counter().empty()) { BufferParams const & bp = buffer().masterBuffer()->params(); Counters & cntrs = bp.documentClass().counters(); cntrs.step(il.counter(), OutputUpdate); // FIXME: translate to paragraph language if (!il.htmllabel().empty()) { docstring const lbl = cntrs.counterLabel(from_utf8(il.htmllabel()), bp.language->code()); // FIXME is this check necessary? if (!lbl.empty()) { xs << html::StartTag(il.htmllabeltag(), il.htmllabelattr()); xs << lbl; xs << html::EndTag(il.htmllabeltag()); } } } if (opts & WriteInnerTag) xs << html::StartTag(il.htmlinnertag(), il.htmlinnerattr()); // we will eventually lose information about the containing inset if (!allowMultiPar() || opts == JustText) runparams.html_make_pars = false; if (il.isPassThru()) runparams.pass_thru = true; xs.startDivision(false); xhtmlParagraphs(text_, buffer(), xs, runparams); xs.endDivision(); if (opts & WriteInnerTag) xs << html::EndTag(il.htmlinnertag()); if (opts & WriteOuterTag) xs << html::EndTag(il.htmltag()); return docstring(); }
docstring sgml::escapeString(docstring const & raw) { docstring bin; bin.reserve(raw.size() * 2); // crude approximation is sufficient for (size_t i = 0; i != raw.size(); ++i) bin += sgml::escapeChar(raw[i]); return bin; }
void InsetLayout::makeDefaultCSS() const { if (!htmldefaultstyle_.empty()) return; docstring const mainfontCSS = font_.asCSS(); if (!mainfontCSS.empty()) htmldefaultstyle_ = from_ascii(htmltag() + "." + defaultCSSClass() + " {\n") + mainfontCSS + from_ascii("\n}\n"); }
void add_known_environment(string const & environment, string const & o1, bool o2, docstring const & beg, docstring const &end) { vector<ArgumentType> arguments; convertArgs(o1, o2, arguments); known_environments[environment] = arguments; if (!beg.empty() || ! end.empty()) possible_textclass_environments[environment] = FullEnvironment(arguments, beg, end); }
void InsetMath::write(WriteStream & os) const { MathEnsurer ensurer(os); docstring const s = name(); os << "\\" << s; // We need an extra ' ' unless this is a single-char-non-ASCII name // or anything non-ASCII follows if (s.size() != 1 || isAlphaASCII(s[0])) os.pendingSpace(true); }
int InsetFormulaMacro::plaintext(odocstream & os, OutputParams const & runparams) const { odocstringstream oss; WriteStream wi(oss, false, true, WriteStream::wsDefault, runparams.encoding); tmpl()->write(wi); docstring const str = oss.str(); os << str; return str.size(); }
int GuiFontMetrics::signedWidth(docstring const & s) const { if (s.empty()) return 0; if (s[0] == '-') return -width(s.substr(1, s.size() - 1)); else return width(s); }
pit_type InsetText::openAddToTocForParagraph(pit_type pit, DocIterator const & dit, bool output_active, TocBackend & backend) const { Paragraph const & par = paragraphs()[pit]; TocBuilder & b = backend.builder(par.layout().tocType()); docstring const label = par.labelString(); b.pushItem(dit, label + (label.empty() ? "" : " "), output_active); return text().lastInSequence(pit); }
int InsetCitation::plaintext(odocstringstream & os, OutputParams const &, size_t) const { string const & cmd = getCmdName(); if (cmd == "nocite") return 0; docstring const label = generateLabel(false); os << label; return label.size(); }
docstring cleanAttr(docstring const & str) { docstring newname; docstring::const_iterator it = str.begin(); docstring::const_iterator en = str.end(); for (; it != en; ++it) { char_type const c = *it; newname += isAlnumASCII(c) ? c : char_type('_'); } return newname; }
void BufferEncodings::validate(char_type c, LaTeXFeatures & features, bool for_mathed) { CharInfo const & ci = Encodings::unicodeCharInfo(c); if (ci.isUnicodeSymbol()) { // In mathed, c could be used both in textmode and mathmode docstring const textcommand = ci.textcommand(); bool const math_mode = for_mathed && isMathCmd(c); bool const use_math = math_mode || (!for_mathed && textcommand.empty()); bool const use_text = (for_mathed && isTextCmd(c)) || (!for_mathed && !textcommand.empty()); bool const plain_utf8 = (features.runparams().encoding->name() == "utf8-plain"); bool const unicode_math = (features.isRequired("unicode-math") && features.isAvailable("unicode-math")); // with utf8-plain, we only load packages when in mathed (see #7766) // and if we do not use unicode-math if ((math_mode && !unicode_math) || (use_math && !plain_utf8)) { string const mathpreamble = ci.mathpreamble(); if (!mathpreamble.empty()) { if (ci.mathfeature()) { string feats = mathpreamble; while (!feats.empty()) { string feat; feats = split(feats, feat, ','); features.require(feat); } } else features.addPreambleSnippet(mathpreamble); } } // with utf8-plain, we do not load packages (see #7766) if (use_text && !plain_utf8) { string const textpreamble = ci.textpreamble(); if (!textpreamble.empty()) { if (ci.textfeature()) { string feats = textpreamble; while (!feats.empty()) { string feat; feats = split(feats, feat, ','); features.require(feat); } } else features.addPreambleSnippet(textpreamble); } } } if (for_mathed && isMathSym(c)) { features.require("amstext"); features.require("lyxmathsym"); } }
int InsetHyperlink::plaintext(odocstream & os, OutputParams const &) const { odocstringstream oss; oss << '[' << getParam("target"); if (getParam("name").empty()) oss << ']'; else oss << "||" << getParam("name") << ']'; docstring const str = oss.str(); os << str; return str.size(); }
static docstring const cleanupWhitespace(docstring const & citelist) { docstring::const_iterator it = citelist.begin(); docstring::const_iterator end = citelist.end(); // Paranoia check: make sure that there is no whitespace in here // -- at least not behind commas or at the beginning docstring result; char_type last = ','; for (; it != end; ++it) { if (*it != ' ') last = *it; if (*it != ' ' || last != ',') result += *it; } return result; }
void InsetText::setText(docstring const & data, Font const & font, bool trackChanges) { clear(); Paragraph & first = paragraphs().front(); for (unsigned int i = 0; i < data.length(); ++i) first.insertChar(i, data[i], font, trackChanges); }
FileFilterList::FileFilterList(docstring const & qt_style_filter) { // FIXME UNICODE string const filter = to_utf8(qt_style_filter) + (qt_style_filter.empty() ? string() : ";;") + to_utf8(_("All Files ")) #if defined(_WIN32) + ("(*.*)"); #else + ("(*)"); #endif // Split data such as "TeX documents (*.tex);;LyX Documents (*.lyx)" // into individual filters. static lyx::regex const separator_re(";;"); string::const_iterator it = filter.begin(); string::const_iterator const end = filter.end(); while (true) { match_results<string::const_iterator> what; if (!lyx::regex_search(it, end, what, separator_re)) { parse_filter(string(it, end)); break; } // Everything from the start of the input to // the start of the match. parse_filter(string(what[-1].first, what[-1].second)); // Increment the iterator to the end of the match. it += distance(it, what[0].second); } }
bool TextClass::hasLayout(docstring const & n) const { docstring const name = n.empty() ? defaultLayoutName() : n; return find_if(layoutlist_.begin(), layoutlist_.end(), LayoutNamesEqual(name)) != layoutlist_.end(); }
docstring::size_type common_path(docstring const & p1, docstring const & p2) { docstring::size_type i = 0; docstring::size_type const p1_len = p1.length(); docstring::size_type const p2_len = p2.length(); while (i < p1_len && i < p2_len && uppercase(p1[i]) == uppercase(p2[i])) ++i; if ((i < p1_len && i < p2_len) || (i < p1_len && p1[i] != '/' && i == p2_len) || (i < p2_len && p2[i] != '/' && i == p1_len)) { if (i) --i; // here was the last match while (i && p1[i] != '/') --i; } return i; }
void InsetCaption::setCustomLabel(docstring const & label) { if (!isAscii(label) || label.empty()) // This must be a user defined layout. We cannot translate // this, since gettext accepts only ascii keys. custom_label_ = label; else custom_label_ = _(to_ascii(label)); }
static docstring const printable_list(docstring const & invalid_chars) { docstring s; docstring::const_iterator const begin = invalid_chars.begin(); docstring::const_iterator const end = invalid_chars.end(); docstring::const_iterator it = begin; for (; it != end; ++it) { if (it != begin) s += ", "; if (*it == ' ') s += _("space"); else s += *it; } return s; }
vector<docstring> GuiCitation::searchKeys(BiblioInfo const & bi, vector<docstring> const & keys_to_search, bool only_keys, docstring const & search_expression, docstring field, bool case_sensitive, bool regex) { vector<docstring> foundKeys; docstring expr = trim(search_expression); if (expr.empty()) return foundKeys; if (!regex) // We must escape special chars in the search_expr so that // it is treated as a simple string by lyx::regex. expr = escape_special_chars(expr); lyx::regex reg_exp; try { reg_exp.assign(to_utf8(expr), case_sensitive ? lyx::regex_constants::ECMAScript : lyx::regex_constants::icase); } catch (lyx::regex_error const & e) { // lyx::regex throws an exception if the regular expression is not // valid. LYXERR(Debug::GUI, e.what()); return vector<docstring>(); } vector<docstring>::const_iterator it = keys_to_search.begin(); vector<docstring>::const_iterator end = keys_to_search.end(); for (; it != end; ++it ) { BiblioInfo::const_iterator info = bi.find(*it); if (info == bi.end()) continue; BibTeXInfo const & kvm = info->second; string data; if (only_keys) data = to_utf8(*it); else if (field.empty()) data = to_utf8(*it) + ' ' + to_utf8(kvm.allData()); else data = to_utf8(kvm[field]); if (data.empty()) continue; try { if (lyx::regex_search(data, reg_exp)) foundKeys.push_back(*it); } catch (lyx::regex_error const & e) { LYXERR(Debug::GUI, e.what()); return vector<docstring>(); } } return foundKeys; }
void utf8_to_ucs4(string const & utf8, docstring & ucs4) { size_t n = utf8.size(); // as utf8 is a multi-byte encoding, there would be at most // n characters: ucs4.resize(n); if (n == 0) return; int maxoutsize = n * 4; // basic_string::data() is not recognized by some old gcc version // so we use &(ucs4[0]) instead. char * outbuf = (char *)(&(ucs4[0])); int bytes = utf8ToUcs4().convert(utf8.c_str(), n, outbuf, maxoutsize); // adjust to the real converted size ucs4.resize(bytes/4); }
string const to_local8bit(docstring const & s) { // This conversion can fail, depending on input. if (s.empty()) return string(); QByteArray const local = toqstr(s).toLocal8Bit(); if (local.isEmpty()) throw to_local8bit_failure(); return string(local.begin(), local.end()); }
void add_known_command(string const & command, string const & o1, bool o2, docstring const & definition) { vector<ArgumentType> arguments; convertArgs(o1, o2, arguments); known_commands[command] = arguments; if (!definition.empty()) possible_textclass_commands[command] = FullCommand(arguments, definition); }