Enrico Forestieri wrote:
On Wed, Oct 10, 2007 at 12:07:51AM -0500, Bo Peng wrote:
The first patch implements the ideas above (without ranges) and
works perfectly. You can even mark as greek the chars and get the
same behaviour as before.
I just tested this patch and it works as expected.

Please, try the attached. It should be fully working with ranges
and font attribute changes.


+int Paragraph::Pimpl::greekChars(odocstream & os, value_type c,
+                                Encoding const & encoding, pos_type & i)
+{
+       // The latex command is "\textgreek{x}" and we have to retain
+       // "\textgreek{x" for the first char but only "x" for all subsequent
+       // chars (this also works when we are passed untranslated unicode).
+       docstring const latex1 = rtrim(encoding.latexChar(c), "}");
+       int length = latex1.length();
+       os << latex1;
+       while (i < size() - 1) {
+               char_type next = getChar(i + 1);
+               if (Encodings::isGreekChar(next)) {

I'd prefer:
                if (Encodings::isGreekChar(next))
+                       break;

And then de-indent the rest.

+                       Font prev_font;
+                       bool found = false;
+                       FontList::const_iterator cit = fontlist.begin();
+                       FontList::const_iterator end = fontlist.end();
+                       for (; cit != end; ++cit) {
+                               if (cit->pos() >= i && !found) {
+                                       prev_font = cit->font();
+                                       found = true;
+                               }
+                               if (cit->pos() >= i + 1)
+                                       break;
+                       }
+                       if (found && cit != end && prev_font != cit->font())


AFAICS if 'found' is true than you cannot have 'cit == end'.


+                               break;
+                       docstring const latex = encoding.latexChar(next);
+                       docstring::size_type const j =
+                               latex.find_first_of(from_ascii("{"));
+                       if (j == docstring::npos)
+                               os << latex.substr(0, 1);
+                       else
+                               os << latex.substr(j + 1, 1);
+                       ++length;
+                       ++i;
+               } else
+                       break;
+       }

Reply via email to