-
- // if we did not find a font entry, but if the font at hand
- // is the same as default, we just forget it
- if (font == patternfont) return;
-
- // ok, we did not find a font entry. But maybe there is exactly
- // the needed font entry one position left
- for(FontList::iterator it = fontlist.begin();
- it != fontlist.end(); ++it) {
- if (pos - 1 >= (*it).pos && pos - 1 <= (*it).pos_end
- && (*it).font == font) {
- (*it).pos_end++;
- return;
+ if (tmp == fontlist.end()) { // !found
+ // if we did not find a font entry, but if the font at hand
+ // is the same as default, we just forget it
+ if (font == patternfont) return;
+
+ // ok, we did not find a font entry. But maybe there is exactly
+ // the needed font ientry one position left
+ FontList::iterator tmp2 = fontlist.begin();
+ for (; tmp2 != fontlist.end(); ++tmp2) {
+ if (pos - 1 >= (*tmp2).pos
+ && pos - 1 <= (*tmp2).pos_end)
+ break;
+ }
+ if (tmp2 != fontlist.end()) {
+ // ok there is one, maybe it is exactly
+ // the needed font
+ if ((*tmp2).font == font) {
+ // put the position under the font
+ (*tmp2).pos_end++;
+ return;
+ }
+ }
+ // Add a new entry in the
+ // fontlist for the position
+ FontTable ft;
+ ft.pos = pos;
+ ft.pos_end = pos;
+ ft.font = font; // or patternfont
+ // It seems that using font instead of patternfont here
+ // fixes all the problems. This also surfaces a "bug" in
+ // the old code.
+ fontlist.insert(fontlist.begin(), ft);
+ } else if ((*tmp).pos != (*tmp).pos_end) { // we found a font entry. maybe we have to split it and create a new one.
+
+// more than one character
+ if (pos == (*tmp).pos) {
+ // maybe we should enlarge the left fonttable
+ FontList::iterator tmp2 = fontlist.begin();
+ for (; tmp2 != fontlist.end(); ++tmp2) {
+ if (pos - 1 >= (*tmp2).pos
+ && pos - 1 <= (*tmp2).pos_end)
+ break;
+ }
+ // Is there is one, and is it exactly
+ // the needed font?
+ if (tmp2 != fontlist.end() &&
+ (*tmp2).font == font) {
+ // Put the position under the font
+ (*tmp2).pos_end++;
+ (*tmp).pos++;
+ return;
+ }
+
+ // Add a new entry in the
+ // fontlist for the position
+ FontTable ft;
+ ft.pos = pos + 1;
+ ft.pos_end = (*tmp).pos_end;
+ ft.font = (*tmp).font;
+ (*tmp).pos_end = pos;
+ (*tmp).font = font;
+ fontlist.insert(fontlist.begin(), ft);
+ } else if (pos == (*tmp).pos_end) {
+ // Add a new entry in the
+ // fontlist for the position
+ FontTable ft;
+ ft.pos = (*tmp).pos;
+ ft.pos_end = (*tmp).pos_end - 1;
+ ft.font = (*tmp).font;
+ (*tmp).pos = (*tmp).pos_end;
+ (*tmp).font = font;
+ fontlist.insert(fontlist.begin(), ft);
+ } else {
+ // Add a new entry in the
+ // fontlist for the position
+ FontTable ft;
+ ft.pos = (*tmp).pos;
+ ft.pos_end = pos - 1;
+ ft.font = (*tmp).font;
+
+ FontTable ft2;
+ ft2.pos = pos + 1;
+ ft2.pos_end = (*tmp).pos_end;
+ ft2.font = (*tmp).font;
+
+ (*tmp).pos = pos;
+ (*tmp).pos_end = pos;
+ (*tmp).font = font;
+
+ fontlist.insert(fontlist.begin(), ft);
+ fontlist.insert(fontlist.begin(), ft2);