Calculates the width of the specified text.
192574
def textwidth(self, text, config):
        
        surface = cairo.SVGSurface(None, 1280, 200)
        ctx = cairo.Context(surface)
        ctx.select_font_face(config['font_face'],
                             cairo.FONT_SLANT_NORMAL,
                             cairo.FONT_WEIGHT_BOLD)
        ctx.set_font_size(int(config['font_size']))
        return ctx.text_extents(text)[2] + 2
1371948
function getTextWidth( $size, $text )
    {
        // this function should not change any of the settings, though it will need to
        // track any directives which change during calculation, so copy them at the start
        // and put them back at the end.
        $this->pushTextState( $this->currentTextState );

        if (!$this->numFonts)
        {
            $this->selectFont('./fonts/Helvetica');
        }

        // converts a number or a float to a string so it can get the width
        $text = "$text";
        // hmm, this is where it all starts to get tricky - use the font information to
        // calculate the width of each character, add them up and convert to user units
        $w = 0;
        $len = strlen( $text );
        $cf = $this->currentFont;
        for ( $i = 0; $i < $len; $i++ )
        {
            $f = 1;
            $directiveArray = $this->PRVTcheckTextDirective( $text, $i, $f );
            $directive = $directiveArray['directive'];
            if ( $directive )
            {
                if ($f)
                {
                    $this->setCurrentFont();
                    $cf = $this->currentFont;
                }
                $i = $i + $directive-1;
            }
            else
            {
                $char = ord( $text[$i] );
                if ( isset($this->fonts[$cf]['differences'][$char] ) )
                {
                    // then this character is being replaced by another
                    $name = $this->fonts[$cf]['differences'][$char];
                    if ( isset($this->fonts[$cf]['C'][$name]['WX'] ) )
                    {
                        $w += $this->fonts[$cf]['C'][$name]['WX'];
                    }
                }
                else if ( isset($this->fonts[$cf]['C'][$char]['WX'] ) )
                {
                    $w += $this->fonts[$cf]['C'][$char]['WX'];
                }
                else
                {
                    $w += 700;
                }
            }
        }

        $this->popTextState();
        $this->setCurrentFont();

        return $w*$size/1000;
    }
1009080
public int getWidth(String text) {
        int total = 0;
        if (fastWinansi) {
            int len = text.length();
            for (int k = 0; k < len; ++k) {
                char char1 = text.charAt(k);
                if (char1 < 128 || (char1 >= 160 && char1 <= 255))
                    total += widths[char1];
                else
                    total += widths[PdfEncodings.winansi.get(char1)];
            }
            return total;
        }
        else {
            byte mbytes[] = convertToBytes(text);
            for (int k = 0; k < mbytes.length; ++k)
                total += widths[0xff & mbytes[k]];
        }
        return total;
    }
1092876
private static float getAutofitTextSize(CharSequence text, TextPaint paint,
            float targetWidth, int maxLines, float low, float high, float precision,
            DisplayMetrics displayMetrics) {
        float mid = (low + high) / 2.0f;
        int lineCount = 1;
        StaticLayout layout = null;

        paint.setTextSize(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PX, mid,
                displayMetrics));

        if (maxLines != 1) {
            layout = new StaticLayout(text, paint, (int)targetWidth, Layout.Alignment.ALIGN_NORMAL,
                    1.0f, 0.0f, true);
            lineCount = layout.getLineCount();
        }

        if (SPEW) Log.d(TAG, "low=" + low + " high=" + high + " mid=" + mid +
                " target=" + targetWidth + " maxLines=" + maxLines + " lineCount=" + lineCount);

        if (lineCount > maxLines) {
            // For the case that `text` has more newline characters than `maxLines`.
            if ((high - low) < precision) {
                return low;
            }
            return getAutofitTextSize(text, paint, targetWidth, maxLines, low, mid, precision,
                    displayMetrics);
        }
        else if (lineCount < maxLines) {
            return getAutofitTextSize(text, paint, targetWidth, maxLines, mid, high, precision,
                    displayMetrics);
        }
        else {
            float maxLineWidth = 0;
            if (maxLines == 1) {
                maxLineWidth = paint.measureText(text, 0, text.length());
            } else {
                for (int i = 0; i < lineCount; i++) {
                    if (layout.getLineWidth(i) > maxLineWidth) {
                        maxLineWidth = layout.getLineWidth(i);
                    }
                }
            }

            if ((high - low) < precision) {
                return low;
            } else if (maxLineWidth > targetWidth) {
                return getAutofitTextSize(text, paint, targetWidth, maxLines, low, mid, precision,
                        displayMetrics);
            } else if (maxLineWidth < targetWidth) {
                return getAutofitTextSize(text, paint, targetWidth, maxLines, mid, high, precision,
                        displayMetrics);
            } else {
                return mid;
            }
        }
    }
38642
def get_text_length(*args):
    
    """
    txt = Image.new('RGBA', (16, 16), (255, 255, 255, 0))
    d = ImageDraw.Draw(txt)
    font = ImageFont.truetype("DejaVuSans", 11)
    result = ()
    for value in args:
        result = result + (d.textsize(value, font=font)[0], )
    return result
485805
def _visible_width(s):
    
    if isinstance(s, _text_type) or isinstance(s, _binary_type):
        return len(_strip_invisible(s))
    else:
        return len(_text_type(s))
511034
def hint_width(self):
        """"""
        return sum((len(self.style.delimiter),
                    self.wide,
                    len(self.style.delimiter),
                    len(u' '),
                    UCS_PRINTLEN + 2,
                    len(u' '),
                    self.style.name_len,))
674901
public int getWidth(String text) {

        m_elem.setInnerText(text);
        return CmsDomUtil.getCurrentStyleInt(m_elem, CmsDomUtil.Style.width);
    }
331210
function width (val) {
  var cr = val.indexOf(EOL);
  if (cr !== -1) {
    val = val.substring(0, cr);
  }
  if (typeof val !== 'string') {
    val = val + '';
  }
  var h = val.match(/[ -~]/g);
  return val.length * 2 - (h ? h.length : 0);
}
1037729
def optwrap(self, text):
        """"""
        if not self.body_width:
            return text

        assert wrap, "Requires Python 2.3."
        result = ''
        newlines = 0
        for para in text.split("\n"):
            if len(para) > 0:
                if not skipwrap(para):
                    result += "\n".join(wrap(para, self.body_width))
                    if para.endswith('  '):
                        result += "  \n"
                        newlines = 1
                    else:
                        result += "\n\n"
                        newlines = 2
                else:
                    if not onlywhite(para):
                        result += para + "\n"
                        newlines = 1
            else:
                if newlines < 2:
                    result += "\n"
                    newlines += 1
        return result
209602
public float getStringWidth(String text, FontOptions options)
	{
		if (StringUtils.isEmpty(text))
			return 0;

		StringWalker walker = new StringWalker(text, options);
		walker.walkToEnd();
		return walker.width();
	}
596188
public float getWidthPointKerned(String text, float fontSize) {
        float size = getWidth(text) * 0.001f * fontSize;
        if (!hasKernPairs())
            return size;
        int len = text.length() - 1;
        int kern = 0;
        char c[] = text.toCharArray();
        for (int k = 0; k < len; ++k) {
            kern += getKerning(c[k], c[k + 1]);
        }
        return size + kern * 0.001f * fontSize;
    }
566670
def _LineWrap(text, width):
    
    return reduce(lambda line, word, width=width: '%s%s%s' %
                  (line,
                   ' \n'[(len(line) - line.rfind('\n') - 1 +
                         len(word.split('\n', 1)[0]) >= width)],
                   word),
                  text.split(' ')
                 )
351303
function computeFontWidthFactor (font) {
  var sum = 0;
  var digitsum = 0;
  var digits = 0;
  font.chars.map(function (ch) {
    sum += ch.xadvance;
    if (ch.id >= 48 && ch.id <= 57) {
      digits++;
      digitsum += ch.xadvance;
    }
  });
  return digits ? digitsum / digits : sum / font.chars.length;
}
1371498
def get_align(text):
    ""
    (x1, x2, h, v, a) = unaligned_get_dimension(text)
    return (h, v, a)
251625
def width(self):
        """"""
        if self._width is not None:
            return self._width
        self._width = sum(fs.width for fs in self.chunks)
        return self._width
138681
private int getCharWidth(String text, Align align)
    {
        final int width;
        if (align == Align.RIGHT)
        {
            width = getTextWidth(text);
        }
        else if (align == Align.CENTER)
        {
            width = getTextWidth(text) / 2;
        }
        else
        {
            width = 0;
        }
        return width;
    }