File: font_mojom_traits.h

package info (click to toggle)
chromium 139.0.7258.127-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,122,156 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (109 lines) | stat: -rw-r--r-- 4,473 bytes parent folder | download | duplicates (6)
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_REMOTE_COCOA_COMMON_FONT_MOJOM_TRAITS_H_
#define COMPONENTS_REMOTE_COCOA_COMMON_FONT_MOJOM_TRAITS_H_

#include "base/numerics/safe_conversions.h"
#include "components/remote_cocoa/common/font.mojom.h"
#include "ui/gfx/font.h"
#include "ui/gfx/platform_font_mac.h"

namespace mojo {

template <>
struct EnumTraits<remote_cocoa::mojom::SystemFont,
                  gfx::PlatformFontMac::SystemFontType> {
  static remote_cocoa::mojom::SystemFont ToMojom(
      gfx::PlatformFontMac::SystemFontType input) {
    switch (input) {
      case gfx::PlatformFontMac::SystemFontType::kGeneral:
        return remote_cocoa::mojom::SystemFont::kGeneral;
      case gfx::PlatformFontMac::SystemFontType::kMenu:
        return remote_cocoa::mojom::SystemFont::kMenu;
      case gfx::PlatformFontMac::SystemFontType::kToolTip:
        return remote_cocoa::mojom::SystemFont::kToolTip;
    }
    NOTREACHED();
  }

  static bool FromMojom(remote_cocoa::mojom::SystemFont input,
                        gfx::PlatformFontMac::SystemFontType* out) {
    switch (input) {
      case remote_cocoa::mojom::SystemFont::kGeneral:
        *out = gfx::PlatformFontMac::SystemFontType::kGeneral;
        return true;
      case remote_cocoa::mojom::SystemFont::kMenu:
        *out = gfx::PlatformFontMac::SystemFontType::kMenu;
        return true;
      case remote_cocoa::mojom::SystemFont::kToolTip:
        *out = gfx::PlatformFontMac::SystemFontType::kToolTip;
        return true;
    }
    return false;
  }
};

template <>
struct EnumTraits<remote_cocoa::mojom::FontWeight, gfx::Font::Weight> {
  static remote_cocoa::mojom::FontWeight ToMojom(gfx::Font::Weight input) {
    return static_cast<remote_cocoa::mojom::FontWeight>(input);
  }

  static bool FromMojom(remote_cocoa::mojom::FontWeight input,
                        gfx::Font::Weight* out) {
    switch (input) {
      case remote_cocoa::mojom::FontWeight::kThin:
      case remote_cocoa::mojom::FontWeight::kExtraLight:
      case remote_cocoa::mojom::FontWeight::kLight:
      case remote_cocoa::mojom::FontWeight::kNormal:
      case remote_cocoa::mojom::FontWeight::kMedium:
      case remote_cocoa::mojom::FontWeight::kSemibold:
      case remote_cocoa::mojom::FontWeight::kBold:
      case remote_cocoa::mojom::FontWeight::kExtraBold:
      case remote_cocoa::mojom::FontWeight::kBlack:
        *out = static_cast<gfx::Font::Weight>(input);
        return true;
    }
    return false;
  }
};

static_assert(static_cast<int>(remote_cocoa::mojom::FontWeight::kThin) ==
              static_cast<int>(gfx::Font::Weight::THIN));
static_assert(static_cast<int>(remote_cocoa::mojom::FontWeight::kExtraLight) ==
              static_cast<int>(gfx::Font::Weight::EXTRA_LIGHT));
static_assert(static_cast<int>(remote_cocoa::mojom::FontWeight::kLight) ==
              static_cast<int>(gfx::Font::Weight::LIGHT));
static_assert(static_cast<int>(remote_cocoa::mojom::FontWeight::kNormal) ==
              static_cast<int>(gfx::Font::Weight::NORMAL));
static_assert(static_cast<int>(remote_cocoa::mojom::FontWeight::kMedium) ==
              static_cast<int>(gfx::Font::Weight::MEDIUM));
static_assert(static_cast<int>(remote_cocoa::mojom::FontWeight::kSemibold) ==
              static_cast<int>(gfx::Font::Weight::SEMIBOLD));
static_assert(static_cast<int>(remote_cocoa::mojom::FontWeight::kBold) ==
              static_cast<int>(gfx::Font::Weight::BOLD));
static_assert(static_cast<int>(remote_cocoa::mojom::FontWeight::kExtraBold) ==
              static_cast<int>(gfx::Font::Weight::EXTRA_BOLD));
static_assert(static_cast<int>(remote_cocoa::mojom::FontWeight::kBlack) ==
              static_cast<int>(gfx::Font::Weight::BLACK));

template <>
struct StructTraits<remote_cocoa::mojom::FontDataView, gfx::Font> {
  static remote_cocoa::mojom::FontNamePtr name(const gfx::Font& font);
  static uint32_t size(const gfx::Font& font) {
    return base::checked_cast<uint32_t>(font.GetFontSize());
  }
  static uint32_t style(const gfx::Font& font) {
    return base::checked_cast<uint32_t>(font.GetStyle());
  }
  static gfx::Font::Weight weight(const gfx::Font& font) {
    return font.GetWeight();
  }
  static bool Read(remote_cocoa::mojom::FontDataView data, gfx::Font* out);
};

}  // namespace mojo

#endif  //  COMPONENTS_REMOTE_COCOA_COMMON_FONT_MOJOM_TRAITS_H_