Initializes the text lengths and stores them into an array.
()
| 562 | * Initializes the text lengths and stores them into an array. |
| 563 | */ |
| 564 | private void initLen() { |
| 565 | final Data data = gui.context.data(); |
| 566 | if(textLen != null || gui.gopts.get(GUIOptions.MAPWEIGHT) == 0) return; |
| 567 | |
| 568 | final int size = data.meta.size; |
| 569 | textLen = new int[size]; |
| 570 | |
| 571 | final IntList pars = new IntList(); |
| 572 | int l = 0; |
| 573 | |
| 574 | for(int pre = 0; pre < size; ++pre) { |
| 575 | final int kind = data.kind(pre); |
| 576 | final int par = data.parent(pre, kind); |
| 577 | |
| 578 | final int ll = l; |
| 579 | while(l > 0 && pars.get(l - 1) > par) { |
| 580 | textLen[pars.get(l - 1)] += textLen[pars.get(l)]; |
| 581 | --l; |
| 582 | } |
| 583 | if(l > 0 && ll != l) textLen[pars.get(l - 1)] += textLen[pars.get(l)]; |
| 584 | pars.set(l, pre); |
| 585 | |
| 586 | if(kind == Data.DOC || kind == Data.ELEM) { |
| 587 | pars.set(++l, 0); |
| 588 | } else { |
| 589 | textLen[pre] = data.textLen(pre, kind != Data.ATTR); |
| 590 | } |
| 591 | } |
| 592 | while(--l >= 0) textLen[pars.get(l)] += textLen[pars.get(l + 1)]; |
| 593 | } |
| 594 | } |