-#ifdef NEW_FONTTABLE
- FontList::iterator tmp = fontlist.begin();
- for (; tmp != fontlist.end(); ++tmp) {
- if (pos >= (*tmp).pos && pos <= (*tmp).pos_end) {
- break;
- }
- }
- 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);
- }
- } else {
- (*tmp).font = font;
- }
-
-#else
- FontTable * tmp2;
-
- bool found = false;
- FontTable * tmp = fonttable;
- while (tmp && !found) {
- if (pos >= tmp->pos && pos <= tmp->pos_end)
- found = true;
- else
- tmp = tmp->next;
- }
-
- if (!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 entry one position left
- found = false;
- tmp2 = fonttable;
- while (tmp2 && !found) {
- if (pos - 1 >= tmp2->pos && pos - 1 <= tmp2->pos_end)
- found = true;
- else
- tmp2 = tmp2->next;
- }
- if (found) {
- // 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
- // fonttable for the position
- tmp = new FontTable;
- tmp->pos = pos;
- tmp->pos_end = pos;
- tmp->font = patternfont; // It seems that is actually totally
- // wrong to use patternfont here, the correct should be font
- // lockily at the end of this function we have
- // tmp->font = font, so this one setting it to patternfont
- // is negated.
- tmp->next = fonttable;
- fonttable = tmp;
- } else {
- // we found a font entry. maybe we have
- // to split it and create a new one
-
- if (tmp->pos != tmp->pos_end) { // more than one character
- if (pos == tmp->pos) {
- // maybe we could enlarge the left fonttable
- found = false;
- tmp2 = fonttable;
- while (tmp2 && !found) {
- if (pos - 1 >= tmp2->pos && pos - 1 <= tmp2->pos_end)
- found = true;
- else
- tmp2 = tmp2->next;
- }
-
- // Is there is one, and is it exactly
- // the needed font?
- if (found && tmp2->font == font) {
- // Put the position under the font
- tmp2->pos_end++;
- tmp->pos++;
- return;
- }
-
- // Add a new entry in the
- // fonttable for the position
- tmp2 = new FontTable;
- tmp2->pos = pos + 1;
- tmp2->pos_end = tmp->pos_end;
- tmp2->font = tmp->font;
- tmp->pos_end = pos;
- tmp2->next = fonttable;
- fonttable = tmp2;
- }
- else if (pos == tmp->pos_end) {
- // Add a new entry in the
- // fonttable for the position
- tmp2 = new FontTable;
- tmp2->pos = tmp->pos;
- tmp2->pos_end = tmp->pos_end - 1;
- tmp2->font = tmp->font;
- tmp->pos = tmp->pos_end;
- tmp2->next = fonttable;
- fonttable = tmp2;
- }
- else {
- // Add a new entry in the
- // fonttable for the position
- tmp2 = new FontTable;
- tmp2->pos = tmp->pos;
- tmp2->pos_end = pos - 1;
- tmp2->font = tmp->font;
- tmp2->next = fonttable;
- fonttable = tmp2;
-
- tmp2 = new FontTable;
- tmp2->pos = pos + 1;
- tmp2->pos_end = tmp->pos_end;
- tmp2->font = tmp->font;
- tmp2->next = fonttable;
- fonttable = tmp2;
-
- tmp->pos = pos;
- tmp->pos_end = pos;
- }
- }
- }
- tmp->font = font;
-#endif
-}