File: font_height.h

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (65 lines) | stat: -rw-r--r-- 2,399 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef THIRD_PARTY_BLINK_RENDERER_PLATFORM_FONTS_FONT_HEIGHT_H_
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_FONTS_FONT_HEIGHT_H_

#include "third_party/blink/renderer/platform/fonts/font_baseline.h"
#include "third_party/blink/renderer/platform/geometry/layout_unit.h"

namespace blink {

// Represents line-progression metrics for line boxes and inline boxes.
// Computed for inline boxes, then the metrics of inline boxes are united to
// compute metrics for line boxes.
// https://drafts.csswg.org/css2/visudet.html#line-height
struct PLATFORM_EXPORT FontHeight {
  FontHeight() = default;
  FontHeight(LayoutUnit ascent, LayoutUnit descent)
      : ascent(ascent), descent(descent) {}

  // "Empty" is for when zero is a valid non-empty value.
  static FontHeight Empty() {
    return FontHeight(LayoutUnit::Min(), LayoutUnit::Min());
  }
  bool IsEmpty() const {
    return ascent == LayoutUnit::Min() && descent == LayoutUnit::Min();
  }

  LayoutUnit LineHeight() const { return ascent + descent; }

  bool operator==(const FontHeight& other) const {
    return ascent == other.ascent && descent == other.descent;
  }
  bool operator!=(const FontHeight& other) const { return !operator==(other); }

  // True if `other`'s ascent and descent are both equal to or less than `this`.
  bool Contains(const FontHeight& other) const {
    return other.ascent <= ascent && other.descent <= descent;
  }

  // Add the leading space. `leading_space.ascent` will be added into ascent and
  // `leading_space.descent` will be added to descent.
  // https://drafts.csswg.org/css2/visudet.html#leading
  void AddLeading(const FontHeight& leading_space);

  // Move the metrics by the specified amount, in line progression direction.
  void Move(LayoutUnit);

  // Unite a metrics for an inline box to a metrics for a line box.
  void Unite(const FontHeight&);

  void operator+=(const FontHeight&);

  // Ascent and descent of glyphs, or synthesized for replaced elements.
  // Then united to compute 'text-top' and 'text-bottom' of line boxes.
  LayoutUnit ascent;
  LayoutUnit descent;
};

PLATFORM_EXPORT std::ostream& operator<<(std::ostream&, const FontHeight&);

}  // namespace blink

#endif  // THIRD_PARTY_BLINK_RENDERER_PLATFORM_FONTS_FONT_HEIGHT_H_