add: if (W_VIEW_REALIZED(tPtr->view) && W_VIEW_MAPPED(tPtr->view)) paintText(tPtr);
context: layOutDocument(Text *tPtr) {    TextBlock *tb;    myLineItems *items = NULL;    unsigned int itemsSize=0, nitems=0, begin, end;    WMFont *font;    unsigned int x, y=0, lw = 0, width=0, bmargin;    char *start=NULL, *mark=NULL;    if ( tPtr->flags.frozen || (!(tb = tPtr->firstTextBlock)) )        return;    assert(tPtr->visible.w > 20);        tPtr->docWidth = tPtr->visible.w;    x = tPtr->margins[tb->marginN].first;     bmargin = tPtr->margins[tb->marginN].body;    /* only partial layOut needed: re-Lay only affected textblocks  */    if (tPtr->flags.laidOut) {        tb = tPtr->currentTextBlock;        /* search backwards for textblocks on same line */        while (tb->prior) {            if (!tb->sections || tb->nsections<1) {                tb = tPtr->firstTextBlock;                tPtr->flags.laidOut = False;                y = 0;                goto _layOut;            }            if(!tb->prior->sections || tb->prior->nsections<1) {                 tb = tPtr->firstTextBlock;                tPtr->flags.laidOut = False;                y = 0;                goto _layOut;            }            if (tb->sections[0]._y !=                 tb->prior->sections[tb->prior->nsections-1]._y) {                break;            }            tb = tb->prior;        }        if(tb->prior && tb->prior->sections && tb->prior->nsections>0) {            y = tb->prior->sections[tb->prior->nsections-1]._y +                 tb->prior->sections[tb->prior->nsections-1].h -                 tb->prior->sections[tb->prior->nsections-1].max_d;        } else {            y = 0;        }    }_layOut:    while (tb) {        if (tb->sections && tb->nsections>0) {            wfree(tb->sections);            tb->sections = NULL;            tb->nsections = 0;        }         if (tb->blank && tb->next && !tb->next->first) {            TextBlock *next = tb->next;            tPtr->currentTextBlock = tb;            WMDestroyTextBlock(tPtr, WMRemoveTextBlock(tPtr));            tb = next;            tb->first = True;            continue;        }        if (tb->first && tb != tPtr->firstTextBlock) {            y += layOutLine(tPtr, items, nitems, x, y);            x = tPtr->margins[tb->marginN].first;            bmargin = tPtr->margins[tb->marginN].body;            nitems = 0;            lw = 0;        }                    if (tb->graphic) {             if (!tPtr->flags.monoFont) {                 if(tb->object)                    width = WMWidgetWidth(tb->d.widget);                else                    width = tb->d.pixmap->width;                if (width > tPtr->docWidth)                     tPtr->docWidth = width;                lw += width;                if (lw >= tPtr->visible.w - x ) {                     y += layOutLine(tPtr, items, nitems, x, y);                    nitems = 0;                    x = bmargin;                    lw = width;                }                if(nitems + 1> itemsSize) {                    items = wrealloc(items,                         (++itemsSize)*sizeof(myLineItems));                }                                    items[nitems].tb = tb;                items[nitems].begin = 0;                items[nitems].end = 0;                nitems++;            }        } else if ((start = tb->text)) {            begin = end = 0;            font = tPtr->flags.monoFont?tPtr->dFont:tb->d.font;            while (start) {                mark = strchr(start, ' ');                if (mark) {                    end += (int)(mark-start)+1;                    start = mark+1;                } else {                    end += strlen(start);                    start = mark;                }                if (end > tb->used)                    end = tb->used;                if (end-begin > 0) {                                        width = WMWidthOfString(font,                         &tb->text[begin], end-begin);                    /* if it won't fit, char wrap it */                    if (width >= tPtr->visible.w) {                         char *t = &tb->text[begin];                        int l=end-begin, i=0;                        do {                             width = WMWidthOfString(font, t, ++i);                        } while (width < tPtr->visible.w && i < l);                          if(i>2) i--;                        end = begin+i;                        start = &tb->text[end];                    }                    lw += width;                }                if (lw >= tPtr->visible.w - x) {                    y += layOutLine(tPtr, items, nitems, x, y);                     lw = width;                    x = bmargin;                    nitems = 0;                }                if(nitems + 1 > itemsSize) {                    items = wrealloc(items,                         (++itemsSize)*sizeof(myLineItems));                }                                    items[nitems].tb = tb;                items[nitems].begin = begin;                items[nitems].end = end;                nitems++;                begin = end;            }        }        /* not yet fully ready. but is already VERY FAST for a 3Mbyte file ;-) */        if(0&&tPtr->flags.laidOut             && tb->next && tb->next->sections && tb->next->nsections>0            && (tPtr->vpos + tPtr->visible.h                 < tb->next->sections[0]._y)) {            if(tPtr->lastTextBlock->sections                 && tPtr->lastTextBlock->nsections > 0 ) {                   TextBlock *ltb = tPtr->lastTextBlock;                   int ly = ltb->sections[ltb->nsections-1]._y;                   int lh = ltb->sections[ltb->nsections-1].h;                   int ss, sd;lh += 1 + tPtr->visible.y + ltb->sections[ltb->nsections-1].max_d;printf("it's %d\n", tPtr->visible.y + ltb->sections[ltb->nsections-1].max_d);                   y += layOutLine(tPtr, items, nitems, x, y);               ss= ly+lh-y;sd = tPtr->docHeight-y;printf("dif %d-%d: %d\n", ss, sd, ss-sd);y += tb->next->sections[0]._y-y;                    nitems = 0;printf("nitems%d\n", nitems);if(ss-sd!=0) y = tPtr->docHeight+ss-sd;                    break;            } else {                 tPtr->flags.laidOut = False;           }       }           tb = tb->next;    }    if (nitems > 0)         y += layOutLine(tPtr, items, nitems, x, y);                   if (tPtr->docHeight != y+10) {        tPtr->docHeight = y+10;        updateScrollers(tPtr);    }    if(tPtr->docWidth > tPtr->visible.w && !tPtr->hS) {        XEvent event;                    tPtr->flags.horizOnDemand = True;        WMSetTextHasHorizontalScroller((WMText*)tPtr, True);        event.type = Expose;        handleEvents(&event, (void *)tPtr);    } else if(tPtr->docWidth <= tPtr->visible.w         && tPtr->hS && tPtr->flags.horizOnDemand ) {        tPtr->flags.horizOnDemand = False;        WMSetTextHasHorizontalScroller((WMText*)tPtr, False);    }    tPtr->flags.laidOut = True;        if(items && itemsSize > 0)        wfree(items);}