A formula for determining font sizes.
436109
def fontsize(count,maxsize,minsize,maxcount):
    ''''''
    size = int(maxsize - (maxsize)*((float(maxcount-count)/maxcount)))
    if size < minsize:
        size = minsize
    return size
1129576
function (text, color, x, y, width) {
                        ctx.fillStyle = color;
                        var metric = ctx.measureText(text);
                        if (metric.width > width) {
                            while (text !== "") {
                                metric = ctx.measureText(text + "...");
                                if (metric.width <= width) {
                                    text += "...";
                                    break;
                                }
                                text = text.substr(0, text.length - 1);
                            }
                        }
                        ctx.fillText(text, x, y, width);
                    }
64651
private static int getFontSize() {
        if (Toolkit.getDefaultToolkit().getScreenResolution() >= 110) {
            // Rely on DPI if it is a high value.
            return Toolkit.getDefaultToolkit().getScreenResolution() / 7 + 1;
        } else {
            // Otherwise try to guess it from the monitor size:
            // If the width is wider than Full HD (1080p, or 1920x1080), then assume it's high-DPI.
            GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
            if (ge.getMaximumWindowBounds().getWidth() > 4096) {
                return 56;
            } else if (ge.getMaximumWindowBounds().getWidth() > 2048) {
                return 28;
            } else {
                return 14;
            }
        }
    }
925404
function (fontSpans) {
        var detected = false
        for (var i = 0; i < baseFonts.length; i++) {
          detected = (fontSpans[i].offsetWidth !== defaultWidth[baseFonts[i]] || fontSpans[i].offsetHeight !== defaultHeight[baseFonts[i]])
          if (detected) {
            return detected
          }
        }
        return detected
      }
1236818
@Override protected void resizeDynamicText() {
        double maxWidth = width - size * 0.1;
        double fontSize = size * 0.24;
        valueText.setFont(Fonts.latoRegular(fontSize));
        if (valueText.getLayoutBounds().getWidth() > maxWidth) { Helper.adjustTextSize(valueText, maxWidth, fontSize); }

        maxWidth = width - size * 0.55;
        fontSize = size * 0.06;

        changeText.setFont(Fonts.latoRegular(fontSize));

        changePercentageText.setFont(Fonts.latoRegular(fontSize));
        if (changePercentageText.getLayoutBounds().getWidth() > maxWidth) { Helper.adjustTextSize(changePercentageText, maxWidth, fontSize); }

        maxWidth = width - size * 0.7;
        fontSize = size * 0.06;

        highText.setFont(Fonts.latoRegular(fontSize));
        if (highText.getLayoutBounds().getWidth() > maxWidth) { Helper.adjustTextSize(highText, maxWidth, fontSize); }
        highText.setY(graphBounds.getY() - size * 0.0125);

        lowText.setFont(Fonts.latoRegular(fontSize));
        if (lowText.getLayoutBounds().getWidth() > maxWidth) { Helper.adjustTextSize(lowText, maxWidth, fontSize); }
        lowText.setY(height - size * 0.1);

        maxWidth = width - size * 0.25;
        fontSize = size * 0.06;
        text.setFont(Fonts.latoRegular(fontSize));
        if (text.getLayoutBounds().getWidth() > maxWidth) { Helper.adjustTextSize(text, maxWidth, fontSize); }
        text.relocate(width - size * 0.05 - text.getLayoutBounds().getWidth(), height - size * 0.1);

        maxWidth = width - size * 0.25;
        fontSize = size * 0.06;
        timeSpanText.setFont(Fonts.latoRegular(fontSize));
        if (timeSpanText.getLayoutBounds().getWidth() > maxWidth) { Helper.adjustTextSize(timeSpanText, maxWidth, fontSize); }
        timeSpanText.relocate((width - timeSpanText.getLayoutBounds().getWidth()) * 0.5, height - size * 0.1);
    }
610381
def set_font_size(self, size):
        ""
        if(self.font_size_pt==size):
            return
        self.font_size_pt=size
        self.font_size=size/self.k
        if(self.page>0):
            self._out(sprintf('BT /F%d %.2f Tf ET',self.current_font['i'],self.font_size_pt))
471819
def get_text_style(text):
    """"""
    style = {}
    style['alpha'] = text.get_alpha()
    if style['alpha'] is None:
        style['alpha'] = 1
    style['fontsize'] = text.get_size()
    style['color'] = color_to_hex(text.get_color())
    style['halign'] = text.get_horizontalalignment()  # left, center, right
    style['valign'] = text.get_verticalalignment()  # baseline, center, top
    style['malign'] = text._multialignment  # text alignment when '\n' in text
    style['rotation'] = text.get_rotation()
    style['zorder'] = text.get_zorder()
    return style
279757
def font(self, prefix, size):
        """"""
        font = QFont(self.fontname[prefix])
        font.setPixelSize(size)
        if prefix[-1] == 's':  # solid style
            font.setStyleName('Solid')
        return font
324845
function measureTextHeight(font) {
       return font.fontData.capHeight * font.lineHeight * font.fontScale.y;
     }
809911
def _fontsize(self, key, label='fontsize', common=True):
        
        size = super(BokehPlot, self)._fontsize(key, label, common)
        return {k: v if isinstance(v, basestring) else '%spt' % v
                for k, v in size.items()}
841967
private int stringWidth(FontMetrics fm, String text)
    {
        int w = fm.stringWidth(text);
        if (wordSpacing != null)
        {
            //count spaces and add
            float add = 0.0f;
            for (int i = 0; i < text.length(); i++)
            {
                if (text.charAt(i) == ' ')
                    add += wordSpacing;
            }
            w = Math.round(w + add);
        }
        return w;
    }
590759
public static double convertFontSize(double parent, CSSProperty.FontSize value)
    {
        double em = parent;
        double ret = em;
        if (value == CSSProperty.FontSize.MEDIUM)
            ret = medium_font;
        else if (value == CSSProperty.FontSize.SMALL)
            ret = medium_font / font_step;
        else if (value == CSSProperty.FontSize.X_SMALL)
            ret = medium_font / font_step / font_step;
        else if (value == CSSProperty.FontSize.XX_SMALL)
            ret = medium_font / font_step / font_step / font_step;
        else if (value == CSSProperty.FontSize.LARGE)
            ret = medium_font * font_step;
        else if (value == CSSProperty.FontSize.X_LARGE)
            ret = medium_font * font_step * font_step;
        else if (value == CSSProperty.FontSize.XX_LARGE)
            ret = medium_font * font_step * font_step * font_step;
        else if (value == CSSProperty.FontSize.SMALLER)
            ret = em / font_step;
        else if (value == CSSProperty.FontSize.LARGER)
            ret = em * font_step;
        return ret;
    }
907958
def best_fit_font_size(cls, text, extents, max_size, font_file):
        
        line_source = _LineSource(text)
        text_fitter = cls(line_source, extents, font_file)
        return text_fitter._best_fit_font_size(max_size)
797999
function sortFontSizes(fontSizes) {
        var r = {};
        var temp = [];
        var size = 0;
        var biggest = 0;

        for (var prop in fontSizes) {
            if (fontSizes.hasOwnProperty(prop)) {

                size++;

                var val = prop.replace(/[^0-9.\/]/g, '').replace(/\/[0-9]/g, '');

                if (prop.indexOf('%') > -1) {
                    val = 16 / 100 * val;
                }

                if (prop.indexOf('em') > -1
                    || prop.indexOf('rem') > -1
                    || prop.indexOf('vw') > -1
                    || prop.indexOf('vh') > -1) {
                    val = 16 * val;
                }

                if (val === '') {
                    val = prop;
                }

                biggest = val > biggest ? val : biggest;

                if (/[0-9.]/g.test(val)) {
                    temp.push({
                                  viewSizePx:  val,
                                  viewSizeStr: '',
                                  cssSize:     prop,
                                  amount:      fontSizes[prop]
                              });
                } else {
                    temp.push({
                                  viewSizePx:  0,
                                  viewSizeStr: val,
                                  cssSize:     prop,
                                  amount:      fontSizes[prop]
                              });
                }


            }
        }


        r = temp.sort(function (a, b) {
            return b.viewSizePx - a.viewSizePx;
        });

        return r;
    }
25438
public static Font getFont (Font font, Size size) {
		float s;
		switch (size) {
		case smallest:		s = (float) (font.getSize() * 0.5); break;
		case much_smaller:	s = (float) (font.getSize() * 0.7); break;
		case smaller:		s = (float) (font.getSize() * 0.8); break;
		case standard:		s = (float) font.getSize(); break;
		case larger:		s = (float) (font.getSize() * 1.5); break;
		case much_larger:	s = (float) (font.getSize() * 3); break;
		case huge:			s = (float) (font.getSize() * 4); break;
		default: 			s = (float) (font.getSize()); break;
		}
		return font.deriveFont(s);
	}
1181291
private void resizeDynamicText() {
        double maxWidth = unitText.isManaged() ? size * 0.725 : size * 0.9;
        double fontSize = size * 0.24;
        valueText.setFont(Fonts.latoRegular(fontSize));
        if (valueText.getLayoutBounds().getWidth() > maxWidth) { Helper.adjustTextSize(valueText, maxWidth, fontSize); }
        if (unitText.isVisible()) {
            valueText.relocate(size * 0.925 - valueText.getLayoutBounds().getWidth() - unitText.getLayoutBounds().getWidth(), size * 0.15);
        } else {
            valueText.relocate(size * 0.95 - valueText.getLayoutBounds().getWidth(), size * 0.15);
        }

        maxWidth = size * 0.3;
        fontSize = size * 0.05;
        averageText.setFont(Fonts.latoRegular(fontSize));
        if (averageText.getLayoutBounds().getWidth() > maxWidth) { Helper.adjustTextSize(averageText, maxWidth, fontSize); }
        if (averageLine.getStartY() < graphBounds.getY() + graphBounds.getHeight() * 0.5) {
            averageText.setY(averageLine.getStartY() + (size * 0.0425));
        } else {
            averageText.setY(averageLine.getStartY() - (size * 0.0075));
        }

        highText.setFont(Fonts.latoRegular(fontSize));
        if (highText.getLayoutBounds().getWidth() > maxWidth) { Helper.adjustTextSize(highText, maxWidth, fontSize); }
        highText.setY(graphBounds.getY() - size * 0.0125);

        lowText.setFont(Fonts.latoRegular(fontSize));
        if (lowText.getLayoutBounds().getWidth() > maxWidth) { Helper.adjustTextSize(lowText, maxWidth, fontSize); }
        lowText.setY(size * 0.9);
    }
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)