//MeasureTextWidth : measure Width of text (use current font)
768578
func (gp *GoPdf) MeasureTextWidth(text string) (float64, error) {

	err := gp.curr.Font_ISubset.AddChars(text) //AddChars for create CharacterToGlyphIndex
	if err != nil {
		return 0, err
	}

	_, _, textWidthPdfUnit, err := createContent(gp.curr.Font_ISubset, text, gp.curr.Font_Size, nil)
	if err != nil {
		return 0, err
	}
	return PointsToUnits(gp.config.Unit, textWidthPdfUnit), nil
}
702084
func GetTTYWidth() int {
	var tty *os.File
	var err error
	if tty, err = os.OpenFile("/dev/tty", os.O_RDWR, 0600); err != nil {
		tty = os.Stdout
	} else {
		defer tty.Close()
	}
	if width, _, err := terminal.GetSize(int(tty.Fd())); err != nil {
		return 80
	} else {
		return width
	}
}
422016
func (c *Cell) LineWidth() uint {
	width := 0
	for _, s := range strings.Split(c.String(), "\n") {
		w := runewidth.StringWidth(s)
		if w > width {
			width = w
		}
	}
	return uint(width)
}
1231236
func IsVariableWidth(str string) bool {
	if IsNull(str) {
		return true
	}
	return rxHalfWidth.MatchString(str) && rxFullWidth.MatchString(str)
}
786073
func (vr *vectorRenderer) MeasureText(body string) (box Box) {
	if vr.s.GetFont() != nil {
		vr.fc = &font.Drawer{
			Face: truetype.NewFace(vr.s.GetFont(), &truetype.Options{
				DPI:  vr.dpi,
				Size: vr.s.FontSize,
			}),
		}
		w := vr.fc.MeasureString(body).Ceil()

		box.Right = w
		box.Bottom = int(drawing.PointsToPixels(vr.dpi, vr.s.FontSize))
		if vr.c.textTheta == nil {
			return
		}
		box = box.Corners().Rotate(util.Math.RadiansToDegrees(*vr.c.textTheta)).Box()
	}
	return
}
407179
func (i *ASCIIArt) GetWidth() int {
	// Find the longest line
	var ret int
	for j := range i.contents {
		if len(i.contents[j]) > ret {
			ret = len(i.contents[j])
		}
	}
	return ret
}
1263177
func (t *Text) SetText(s string) {
	t.width = 0
	t.text = []rune(s)
	if len(t.widths) < len(t.text) {
		t.widths = make([]int, len(t.text))
	} else {
		t.widths = t.widths[0:len(t.text)]
	}
	if len(t.styles) < len(t.text) {
		t.styles = make([]tcell.Style, len(t.text))
	} else {
		t.styles = t.styles[0:len(t.text)]
	}
	t.lengths = []int{}
	length := 0
	for i, r := range t.text {
		t.widths[i] = runewidth.RuneWidth(r)
		t.styles[i] = t.style
		if r == '\n' {
			t.lengths = append(t.lengths, length)
			if length > t.width {
				t.width = length
				length = 0
			}

		} else if t.widths[i] == 0 && length == 0 {
			// If first character on line is combining, inject
			// a leading space.  (Shame on the caller!)
			t.widths = append(t.widths, 0)
			copy(t.widths[i+1:], t.widths[i:])
			t.widths[i] = 1

			t.text = append(t.text, ' ')
			copy(t.text[i+1:], t.text[i:])
			t.text[i] = ' '

			t.styles = append(t.styles, t.style)
			copy(t.styles[i+1:], t.styles[i:])
			t.styles[i] = t.style
			length++
		} else {
			length += t.widths[i]
		}
	}
	if length > 0 {
		t.lengths = append(t.lengths, length)
		if length > t.width {
			t.width = length
		}
	}
	t.height = len(t.lengths)
	t.PostEventWidgetContent(t)
}
407139
func GenericTextLen(mg MinimalGraphics, t string, font Font) (width int) {
	// TODO: how handle newlines?  same way like Text does
	fw, _, mono := mg.FontMetrics(font)
	if mono {
		for _ = range t {
			width++
		}
		width = int(float32(width)*fw + 0.5)
	} else {
		var length float32
		for _, r := range t {
			if w, ok := CharacterWidth[int(r)]; ok {
				length += w
			} else {
				length += 20 // save above average
			}
		}
		length /= averageCharacterWidth
		length *= fw
		width = int(length + 0.5)
	}
	return
}
127804
func (s *Resolution) SetWidth(v int64) *Resolution {
	s.Width = &v
	return s
}
1112355
func (d *DFT) BinWidth() int {
	if d == nil {
		return 0
	}
	if d._binWidth > 0 {
		return d._binWidth
	}
	d._binWidth = (d.SampleRate / 2) / len(d.Coefs)
	return d._binWidth
}
273335
func (pb *Bar) SetWidth(width int) *Bar {
	pb.Width = width
	pb.ForceWidth = true
	return pb
}
988880
func (t *Text) calcX(width, line int) int {
	if t.align&HAlignCenter != 0 {
		return (width - t.lengths[line]) / 2
	}
	if t.align&HAlignRight != 0 {
		return width - t.lengths[line]
	}
	return 0
}
870244
func Width() int {
	ws, err := getWinsize()

	if err != nil {
		return -1
	}

	return int(ws.Col)
}
309861
func (gp *GoPdf) SetLineWidth(width float64) {
	gp.curr.lineWidth = gp.UnitsToPoints(width)
	gp.getContent().AppendStreamSetLineWidth(gp.UnitsToPoints(width))
}
1251446
func (s Style) GetStrokeWidth(defaults ...float64) float64 {
	if s.StrokeWidth == 0 {
		if len(defaults) > 0 {
			return defaults[0]
		}
		return DefaultStrokeWidth
	}
	return s.StrokeWidth
}
585736
func (p *JSONProgress) width() int {
	if p.winSize != 0 {
		return p.winSize
	}
	ws, err := term.GetWinsize(p.terminalFd)
	if err == nil {
		return int(ws.Width)
	}
	return 200
}
994292
func Width() (uint, error) {
	output, err := size()
	if err != nil {
		return 0, err
	}
	_, width, err := parse(output)
	return width, err
}