// GlyphMetrics returns the desired glyph metrics of the UNICODE char given in ch from the loaded font.
// (https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf_38.html)
178474
func (f *Font) GlyphMetrics(ch rune) (*GlyphMetrics, error) {
	_ch := C.Uint16(ch)
	var minX, maxX, minY, maxY, adv C.int
	result := C.TTF_GlyphMetrics(f.f, _ch, &minX, &maxX, &minY, &maxY, &adv)
	if result == 0 {
		return &GlyphMetrics{int(minX), int(maxX), int(minY), int(maxY), int(adv)}, nil
	}
	return nil, GetError()
}
1068640
func (scaledFont *ScaledFont) GetScaleMatrix(scaleMatrix *Matrix) {
	C.cairo_scaled_font_get_scale_matrix(scaledFont.Ptr, (*C.cairo_matrix_t)(unsafe.Pointer(scaleMatrix)))
	if err := scaledFont.status(); err != nil {
		panic(err)
	}
}
611080
func (c *canvas) styleAsSVG(s Style) string {
	sw := s.StrokeWidth
	sc := s.StrokeColor
	fc := s.FillColor
	fs := s.FontSize
	fnc := s.FontColor

	if s.ClassName != "" {
		var classes []string
		classes = append(classes, s.ClassName)
		if !sc.IsZero() {
			classes = append(classes, "stroke")
		}
		if !fc.IsZero() {
			classes = append(classes, "fill")
		}
		if fs != 0 || s.Font != nil {
			classes = append(classes, "text")
		}

		return fmt.Sprintf("class=\"%s\"", strings.Join(classes, " "))
	}

	var pieces []string

	if sw != 0 {
		pieces = append(pieces, "stroke-width:"+fmt.Sprintf("%d", int(sw)))
	} else {
		pieces = append(pieces, "stroke-width:0")
	}

	if !sc.IsZero() {
		pieces = append(pieces, "stroke:"+sc.String())
	} else {
		pieces = append(pieces, "stroke:none")
	}

	if !fnc.IsZero() {
		pieces = append(pieces, "fill:"+fnc.String())
	} else if !fc.IsZero() {
		pieces = append(pieces, "fill:"+fc.String())
	} else {
		pieces = append(pieces, "fill:none")
	}

	if fs != 0 {
		pieces = append(pieces, "font-size:"+fmt.Sprintf("%.1fpx", drawing.PointsToPixels(c.dpi, fs)))
	}

	if s.Font != nil {
		pieces = append(pieces, c.getFontFace(s))
	}
	return fmt.Sprintf("style=\"%s\"", strings.Join(pieces, ";"))
}
306782
func formatMetricTagsAsString(metricTags map[string]string) string {
	var tags string
	for tag, value := range metricTags {
		tags += fmt.Sprintf("%s:%s; ", tag, value)
	}
	// trim the last semicolon
	tags = strings.TrimSuffix(tags, "; ")

	return "tags[" + tags + "]"
}
1031260
func (p *PdfDictionaryObj) GetOffset(glyph int) int {
	ttfp := p.PtrToSubsetFontObj.GetTTFParser()
	glyf := ttfp.GetTables()["glyf"]
	offset := int(glyf.Offset + ttfp.LocaTable[glyph])
	return offset
}
101703
func NewMetricConverter() *MetricConverter {
	return &MetricConverter{
		scheme: scheme.Scheme,
		codecs: serializer.NewCodecFactory(scheme.Scheme),
		internalVersioner: runtime.NewMultiGroupVersioner(
			scheme.SchemeGroupVersion,
			schema.GroupKind{Group: cmint.GroupName, Kind: ""},
			schema.GroupKind{Group: cmv1beta1.GroupName, Kind: ""},
			schema.GroupKind{Group: cmv1beta2.GroupName, Kind: ""},
		),
	}
}
127073
func (c *CSS) GetPlatformFontsForNodeWithParams(v *CSSGetPlatformFontsForNodeParams) ([]*CSSPlatformFontUsage, error) {
	resp, err := gcdmessage.SendCustomReturn(c.target, c.target.GetSendCh(), &gcdmessage.ParamRequest{Id: c.target.GetId(), Method: "CSS.getPlatformFontsForNode", Params: v})
	if err != nil {
		return nil, err
	}

	var chromeData struct {
		Result struct {
			Fonts []*CSSPlatformFontUsage
		}
	}

	if resp == nil {
		return nil, &gcdmessage.ChromeEmptyResponseErr{}
	}

	// test if error first
	cerr := &gcdmessage.ChromeErrorResponse{}
	json.Unmarshal(resp.Data, cerr)
	if cerr != nil && cerr.Error != nil {
		return nil, &gcdmessage.ChromeRequestErr{Resp: cerr}
	}

	if err := json.Unmarshal(resp.Data, &chromeData); err != nil {
		return nil, err
	}

	return chromeData.Result.Fonts, nil
}
445329
func (s *SubsetFontObj) CharIndex(r rune) (uint, error) {
	/*
		if index, ok := s.CharacterToGlyphIndex[r]; ok {
			return index, nil
		}
		return 0, ErrCharNotFound
	*/
	glyIndex, ok := s.CharacterToGlyphIndex.Val(r)
	if ok {
		return glyIndex, nil
	}
	return 0, ErrCharNotFound
}
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
}
363567
func (key Key) Layout(bg BasicGraphics, m [][]*KeyEntry, font Font) (w, h int, colwidth, rowheight []int) {
	fontwidth, fontheight, _ := bg.FontMetrics(font)
	cols, rows := len(m), len(m[0])

	// Find total width and height
	totalh := 0
	rowheight = make([]int, rows)
	for r := 0; r < rows; r++ {
		rh := 0
		for c := 0; c < cols; c++ {
			e := m[c][r]
			if e == nil {
				continue
			}
			// fmt.Printf("Layout1 (%d,%d): %s\n", c,r,e.Text)
			_, h := textDim(e.Text)
			if h > rh {
				rh = h
			}
		}
		rowheight[r] = rh
		totalh += rh
	}

	totalw := 0
	colwidth = make([]int, cols)
	// fmt.Printf("Making totalw for %d cols\n", cols)
	for c := 0; c < cols; c++ {
		var rw float32
		for r := 0; r < rows; r++ {
			e := m[c][r]
			if e == nil {
				continue
			}
			// fmt.Printf("Layout2 (%d,%d): %s\n", c,r,e.Text)

			w, _ := textDim(e.Text)
			if w > rw {
				rw = w
			}
		}
		irw := int(rw + 0.75)
		colwidth[c] = irw
		totalw += irw
		// fmt.Printf("Width of col %d: %d.  Total now: %d\n", c, irw, totalw)
	}

	if fontwidth == 1 && fontheight == 1 {
		// totalw/h are characters only and still in character-units
		totalw += int(KeyColSep) * (cols - 1)                 // add space between columns
		totalw += int(2*KeyHorSep + 0.5)                      // add space for left/right border
		totalw += int(KeySymbolWidth+KeySymbolSep+0.5) * cols // place for symbol and symbol-text sep

		totalh += int(KeyRowSep) * (rows - 1) // add space between rows
		vsep := KeyVertSep
		if vsep < 1 {
			vsep = 1
		} // make sure there _is_ room (as KeyVertSep < 1)
		totalh += int(2 * vsep) // add border at top/bottom
	} else {
		// totalw/h are characters only and still in character-units
		totalw = int(float32(totalw) * fontwidth)                     // scale to pixels
		totalw += int(KeyColSep * (float32(cols-1) * fontwidth))      // add space between columns
		totalw += int(2 * KeyHorSep * fontwidth)                      // add space for left/right border
		totalw += int((KeySymbolWidth+KeySymbolSep)*fontwidth) * cols // place for symbol and symbol-text sep

		totalh *= fontheight
		totalh += int(KeyRowSep * float32((rows-1)*fontheight)) // add space between rows
		vsep := KeyVertSep * float32(fontheight)
		if vsep < 1 {
			vsep = 1
		} // make sure there _is_ room (as KeyVertSep < 1)
		totalh += int(2 * vsep) // add border at top/bottom
	}
	return totalw, totalh, colwidth, rowheight
}
914155
func NewCharacteristics(context hap.Context, c hap.CharacteristicsHandler, mutex *sync.Mutex) *Characteristics {
	handler := Characteristics{
		controller: c,
		mutex:      mutex,
		context:    context,
	}

	return &handler
}
203838
func (c Chart) GetFont() *truetype.Font {
	if c.Font == nil {
		return c.defaultFont
	}
	return c.Font
}
513773
func (m *metricMap) getOrCreateMetricWithLabels(
	hash uint64, labels Labels, curry []curriedLabelValue,
) Metric {
	m.mtx.RLock()
	metric, ok := m.getMetricWithHashAndLabels(hash, labels, curry)
	m.mtx.RUnlock()
	if ok {
		return metric
	}

	m.mtx.Lock()
	defer m.mtx.Unlock()
	metric, ok = m.getMetricWithHashAndLabels(hash, labels, curry)
	if !ok {
		lvs := extractLabelValues(m.desc, labels, curry)
		metric = m.newMetric(lvs...)
		m.metrics[hash] = append(m.metrics[hash], metricWithLabelValues{values: lvs, metric: metric})
	}
	return metric
}
1170357
func (h *HTTPReporter) GetMetrics() *vegeta.Metrics {
	h.Lock()
	defer h.Unlock()
	return h.metrics
}
1051626
func (c *Client) DebugEnableMetrics() (string, error) {
	result := ""
	err := c.call("DebugEnableMetrics", empty, &result)
	if err != nil {
		return "", err
	}
	return result, nil
}
578096
func (options *FontOptions) SetHintMetrics(hintMetrics HintMetrics) {
	C.cairo_font_options_set_hint_metrics(options.Ptr, C.cairo_hint_metrics_t(hintMetrics))
	if err := options.status(); err != nil {
		panic(err)
	}
}
1063929
func (a *HistoricalApi) namespaceMetrics(request *restful.Request, response *restful.Response) {
	key := core.HistoricalKey{
		ObjectType:    core.MetricSetTypeNamespace,
		NamespaceName: request.PathParameter("namespace-name"),
	}
	a.processMetricRequest(key, request, response)
}