note: adding print / log statements to following when inside gide will cause an infinite loop because the console redirection uses this very same code! SetHTMLPre sets preformatted HTML-styled text by decoding all standard inline HTML text style formatting tags in the string and sets the per-charact
(str []byte, font *styles.FontRender, txtSty *styles.Text, ctxt *units.Context, cssAgg map[string]any)
| 592 | // (including class names) are decoded. Whitespace is decoded as-is, |
| 593 | // including LF \n etc, except in WhiteSpacePreLine case which only preserves LF's |
| 594 | func (tr *Text) SetHTMLPre(str []byte, font *styles.FontRender, txtSty *styles.Text, ctxt *units.Context, cssAgg map[string]any) { |
| 595 | // errstr := "core.Text SetHTMLPre" |
| 596 | |
| 597 | sz := len(str) |
| 598 | tr.Spans = make([]Span, 1) |
| 599 | tr.Links = nil |
| 600 | if sz == 0 { |
| 601 | return |
| 602 | } |
| 603 | curSp := &(tr.Spans[0]) |
| 604 | initsz := min(sz, 1020) |
| 605 | curSp.Init(initsz) |
| 606 | |
| 607 | font.Font = OpenFont(font, ctxt) |
| 608 | |
| 609 | nextIsParaStart := false |
| 610 | curLinkIndex := -1 // if currently processing an <a> link element |
| 611 | |
| 612 | fstack := make([]*styles.FontRender, 1, 10) |
| 613 | fstack[0] = font |
| 614 | |
| 615 | tagstack := make([]string, 0, 10) |
| 616 | |
| 617 | tmpbuf := make([]byte, 0, 1020) |
| 618 | |
| 619 | bidx := 0 |
| 620 | curTag := "" |
| 621 | for bidx < sz { |
| 622 | cb := str[bidx] |
| 623 | ftag := "" |
| 624 | if cb == '<' && sz > bidx+1 { |
| 625 | eidx := bytes.Index(str[bidx+1:], []byte(">")) |
| 626 | if eidx > 0 { |
| 627 | ftag = string(str[bidx+1 : bidx+1+eidx]) |
| 628 | bidx += eidx + 2 |
| 629 | } else { // get past < |
| 630 | curf := fstack[len(fstack)-1] |
| 631 | curSp.AppendString(string(str[bidx:bidx+1]), curf.Face.Face, curf.Color, curf.Background, curf.Decoration, font, ctxt) |
| 632 | bidx++ |
| 633 | } |
| 634 | } |
| 635 | if ftag != "" { |
| 636 | if ftag[0] == '/' { |
| 637 | etag := strings.ToLower(ftag[1:]) |
| 638 | // fmt.Printf("%v etag: %v\n", bidx, etag) |
| 639 | if etag == "pre" { |
| 640 | continue // ignore |
| 641 | } |
| 642 | if etag != curTag { |
| 643 | // log.Printf("%v end tag: %v doesn't match current tag: %v for string\n%v\n", errstr, etag, curTag, string(str)) |
| 644 | } |
| 645 | switch etag { |
| 646 | // case "p": |
| 647 | // tr.Spans = append(tr.Spans, Span{}) |
| 648 | // curSp = &(tr.Spans[len(tr.Spans)-1]) |
| 649 | // nextIsParaStart = true |
| 650 | // case "br": |
| 651 | // tr.Spans = append(tr.Spans, Span{}) |
no test coverage detected