Skip to content
Repos

DevPlaceApp

C++ 1.7 KB39 lines Opens in site

Directory Raw Download

#pragma once
// Spec: SPEC.md UX-FONT-01. SwiftUI text styles mapped to bundled Inter (SF Pro substitute, DIFF-01).
#include <string>

namespace dp::ui {

enum class Weight { Regular = 400, Medium = 500, Semibold = 600, Bold = 700 };

struct FontSpec {
  float size = 17;
  Weight weight = Weight::Regular;
  bool italic = false;
  bool mono = false;

  bool operator==(const FontSpec&) const = default;
  FontSpec with(Weight w) const { FontSpec f = *this; f.weight = w; return f; }
  FontSpec sized(float s) const { FontSpec f = *this; f.size = s; return f; }
  FontSpec italicized() const { FontSpec f = *this; f.italic = true; return f; }
  FontSpec monospaced() const { FontSpec f = *this; f.mono = true; return f; }
  // Line height in points: SF Pro metrics table (UIFont.preferredFont heights).
  float lineHeight() const;
  std::string key() const;

  // SwiftUI semantic styles at the default content size.
  static FontSpec largeTitle() { return {34, Weight::Regular}; }
  static FontSpec title() { return {28, Weight::Regular}; }
  static FontSpec title2() { return {22, Weight::Regular}; }
  static FontSpec title3() { return {20, Weight::Regular}; }
  static FontSpec headline() { return {17, Weight::Semibold}; }
  static FontSpec body() { return {17, Weight::Regular}; }
  static FontSpec callout() { return {16, Weight::Regular}; }
  static FontSpec subheadline() { return {15, Weight::Regular}; }
  static FontSpec footnote() { return {13, Weight::Regular}; }
  static FontSpec caption() { return {12, Weight::Regular}; }
  static FontSpec caption2() { return {11, Weight::Regular}; }
  static FontSpec system(float size, Weight w = Weight::Regular) { return {size, w}; }
};

}  // namespace dp::ui
29.2ms