Compute default font width factor to use.
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;
}
295239
function get_text_width($text, $font, $size, $word_spacing = 0, $letter_spacing = 0) {
    $fh = $this->_load_font($font);

    // Determine the additional width due to extra spacing
    $num_spaces = mb_substr_count($text," ");
    $delta = $word_spacing * $num_spaces;
    
    if ( $letter_spacing ) {
      $num_chars = mb_strlen($text);
      $delta += ($num_chars - $num_spaces) * $letter_spacing;
    }
    
    return $this->_pdf->stringwidth($text, $fh, $size) + $delta;
  }
737088
public static FontUIResource getFont(PropertyOwner propertyOwner, Map<String,Object> properties, boolean returnDefaultIfNone)
    {
        String strFontName = ScreenUtil.getPropery(ScreenUtil.FONT_NAME, propertyOwner, properties, null);
        String strFontSize = ScreenUtil.getPropery(ScreenUtil.FONT_SIZE, propertyOwner, properties, null);
        String strFontStyle = ScreenUtil.getPropery(ScreenUtil.FONT_STYLE, propertyOwner, properties, null);

        if ((strFontName == null) || (strFontName.length() == 0))
        {
            if (!returnDefaultIfNone)
                return null;
            strFontName = Font.DIALOG;  // Default font
        }
        int iSize = 18; // Default size
        if ((strFontSize != null) && (strFontSize.length() > 0))
            iSize = Integer.parseInt(strFontSize);      
        int iStyle = Font.PLAIN;
        if ((strFontStyle != null) && (strFontStyle.length() > 0))
            iStyle = Integer.parseInt(strFontStyle);
        return new FontUIResource(strFontName, iStyle, iSize);
    }
135926
def stylesheet(self, fn=None, unit=CSS.rem, pt_per_em=None, decimals=2, font_factor=1/2., space_factor=1/20.):
        """"""
        styles = self.stylemap(definitions=True, all=True, cache=False)
        used_styles = self.stylemap(definitions=False, all=False, cache=False)
        css = CSS(fn=fn or (self.fn and self.fn.replace('.docx', '.css')) or None)
        if pt_per_em is None:
            # use the size of the "Normal" font as 1.0em by definition
            normal = [styles[k] for k in styles if styles[k].name=='Normal'][0]
            if normal.properties.get('sz') is not None:
                pt_per_em = float(normal.properties['sz'].val) * font_factor
            else:
                pt_per_em = 12.
        for styleName in used_styles:
            style = styles[styleName]
            sel = self.selector(style)
            css.styles[sel] = self.style_properties(styles, styleName, unit=unit, pt_per_em=pt_per_em, decimals=decimals, font_factor=font_factor, space_factor=space_factor)
            LOG.debug("%s %r" % (sel, css.styles[sel]))

        return css
115554
def stroke_width_attribute(styles={})
      return nil if styles.nil?
      return nil if styles[:stroke_width].nil?
      value = styles[:stroke_width]
      return 0 if [0, :default].include?(value)
      return nil unless value.respond_to?(:to_f)
      return value.to_f
    end
190903
float width(int character) {
        if (image == null)
            return font.getWidthPoint(character, size) * hScale;
        else
            return image.getScaledWidth();
    }
262888
def pys_width2xls_width(self, pys_width):
        """"""

        width_0 = get_default_text_extent("0")[0]
        # Scale relative to 12 point font instead of 10 point
        width_0_char = pys_width * 1.2 / width_0
        return int(width_0_char * 256.0)
970112
function recalculate_width()
    {
        $style = $this->get_style();
        $text = $this->get_text();
        $size = $style->font_size;
        $font = $style->font_family;
        $word_spacing = (float)$style->length_in_pt($style->word_spacing);
        $char_spacing = (float)$style->length_in_pt($style->letter_spacing);

        return $style->width = $this->_dompdf->getFontMetrics()->getTextWidth($text, $font, $size, $word_spacing, $char_spacing);
    }
109527
def font(self, name, properties):
        
        size, slant, weight = (properties)
        return (name, (self.ty(size), slant, weight))
793658
function (fontSize) {
		fontSize = pInt(fontSize || 11);

		// Empirical values found by comparing font size and bounding box height.
		// Applies to the default font family. http://jsfiddle.net/highcharts/7xvn7/
		var lineHeight = fontSize < 24 ? fontSize + 4 : mathRound(fontSize * 1.2),
			baseline = mathRound(lineHeight * 0.8);

		return {
			h: lineHeight,
			b: baseline
		};
	}
1187614
def com_google_fonts_check_family_tnum_horizontal_metrics(fonts):
  """"""
  from fontbakery.constants import RIBBI_STYLE_NAMES
  from fontTools.ttLib import TTFont
  RIBBI_ttFonts = [TTFont(f)
                   for f in fonts
                   if style(f) in RIBBI_STYLE_NAMES]
  tnum_widths = {}
  for ttFont in RIBBI_ttFonts:
    glyphs = ttFont.getGlyphSet()
    tnum_glyphs = [(glyph_id, glyphs[glyph_id])
                   for glyph_id in glyphs.keys()
                   if glyph_id.endswith(".tnum")]
    for glyph_id, glyph in tnum_glyphs:
      if glyph.width not in tnum_widths:
        tnum_widths[glyph.width] = [glyph_id]
      else:
        tnum_widths[glyph.width].append(glyph_id)

  if len(tnum_widths.keys()) > 1:
    max_num = 0
    most_common_width = None
    for width, glyphs in tnum_widths.items():
      if len(glyphs) > max_num:
        max_num = len(glyphs)
        most_common_width = width

    del tnum_widths[most_common_width]
    yield FAIL, (f"The most common tabular glyph width is {most_common_width}."
                  " But there are other tabular glyphs with different widths"
                 f" such as the following ones:\n\t{tnum_widths}.")
  else:
    yield PASS, "OK"
962869
private void setPreferredWidth() {
    Element root = component.getDocument().getDefaultRootElement();
    int lines = root.getElementCount();
    int digits = Math.max(String.valueOf(lines).length(), minimumDisplayDigits);

    // Update sizes when number of digits in the line number changes

    if (lastDigits != digits) {
      lastDigits = digits;
      FontMetrics fontMetrics = getFontMetrics(getFont());
      int width = fontMetrics.charWidth('0') * digits;
      Insets insets = getInsets();
      int preferredWidth = insets.left + insets.right + width;

      Dimension d = getPreferredSize();
      d.setSize(preferredWidth, HEIGHT);
      setPreferredSize(d);
      setSize(d);
    }
  }
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
943996
public static Font getFont (int style, Size size) {
		return getFont(getDefaultFont(), size).deriveFont(style);
	}
823843
def _create_font_size_combo(self):
        """"""

        self.std_font_sizes = config["font_default_sizes"]
        font_size = str(get_default_font().GetPointSize())
        self.font_size_combo = \
            wx.ComboBox(self, -1, value=font_size, size=(60, -1),
                        choices=map(unicode, self.std_font_sizes),
                        style=wx.CB_DROPDOWN | wx.TE_PROCESS_ENTER)

        self.font_size_combo.SetToolTipString(_(u"Text size\n(points)"))

        self.AddControl(self.font_size_combo)
        self.Bind(wx.EVT_COMBOBOX, self.OnTextSize, self.font_size_combo)
        self.Bind(wx.EVT_TEXT_ENTER, self.OnTextSize, self.font_size_combo)
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,))
775577
function reduceFontSize(e) {
    e.preventDefault();
    if (fontState.size <= MIN_SIZE) return;

    fontState.size--;
    saveFontSettings();
  }