Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Share native fonts

Neeraj Guptaaccded7a766d
diff --git a/android/apps/ensu/app/build.gradle.kts b/android/apps/ensu/app/build.gradle.kts
index bc90ab9328..9a5921ddc9 100644
--- a/android/apps/ensu/app/build.gradle.kts
+++ b/android/apps/ensu/app/build.gradle.kts
@@ -121,6 +121,7 @@ dependencies {
val composeBom = platform("androidx.compose:compose-bom:2025.02.00")
implementation(project(":ensu:rust"))
+ implementation(project(":fonts"))
implementation("androidx.activity:activity-compose:1.8.2")
implementation("androidx.compose.animation:animation")
implementation("androidx.compose.material3:material3")
diff --git a/android/apps/ensu/app/src/main/java/io/ente/ensu/designsystem/Theme.kt b/android/apps/ensu/app/src/main/java/io/ente/ensu/designsystem/Theme.kt
index c072da5ddc..00465c69d3 100644
--- a/android/apps/ensu/app/src/main/java/io/ente/ensu/designsystem/Theme.kt
+++ b/android/apps/ensu/app/src/main/java/io/ente/ensu/designsystem/Theme.kt
@@ -14,6 +14,7 @@ import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.sp
import io.ente.ensu.R
+import io.ente.fonts.EnteFontFamily
object EnsuColor {
val backgroundBaseLight = Color(0xFFF8F5F0)
@@ -114,13 +115,7 @@ object EnsuTypography {
Font(R.font.dm_serif_text_regular, FontWeight.SemiBold),
)
- private val uiFamily =
- FontFamily(
- Font(R.font.inter_regular, FontWeight.Normal),
- Font(R.font.inter_medium, FontWeight.Medium),
- Font(R.font.inter_semibold, FontWeight.SemiBold),
- Font(R.font.inter_bold, FontWeight.Bold),
- )
+ private val uiFamily = EnteFontFamily.inter
private val messageFamily = uiFamily
diff --git a/android/packages/fonts/build.gradle.kts b/android/packages/fonts/build.gradle.kts
new file mode 100644
index 0000000000..b4c39336a8
--- /dev/null
+++ b/android/packages/fonts/build.gradle.kts
@@ -0,0 +1,27 @@
+import org.jetbrains.kotlin.gradle.dsl.JvmTarget
+
+plugins {
+ id("com.android.library")
+ id("org.jetbrains.kotlin.android")
+}
+
+kotlin { explicitApi() }
+
+android {
+ namespace = "io.ente.fonts"
+ compileSdk = 36
+
+ defaultConfig { minSdk = 24 }
+
+ compileOptions {
+ sourceCompatibility = JavaVersion.VERSION_17
+ targetCompatibility = JavaVersion.VERSION_17
+ }
+}
+
+kotlin { compilerOptions { jvmTarget.set(JvmTarget.JVM_17) } }
+
+dependencies {
+ api("androidx.compose.ui:ui-text")
+ api(platform("androidx.compose:compose-bom:2025.02.00"))
+}
diff --git a/android/packages/fonts/src/main/AndroidManifest.xml b/android/packages/fonts/src/main/AndroidManifest.xml
new file mode 100644
index 0000000000..cc947c5679
--- /dev/null
+++ b/android/packages/fonts/src/main/AndroidManifest.xml
@@ -0,0 +1 @@
+<manifest />
diff --git a/android/packages/fonts/src/main/kotlin/io/ente/fonts/EnteFontFamily.kt b/android/packages/fonts/src/main/kotlin/io/ente/fonts/EnteFontFamily.kt
new file mode 100644
index 0000000000..30a2a4300e
--- /dev/null
+++ b/android/packages/fonts/src/main/kotlin/io/ente/fonts/EnteFontFamily.kt
@@ -0,0 +1,17 @@
+package io.ente.fonts
+
+import androidx.compose.ui.text.font.Font
+import androidx.compose.ui.text.font.FontFamily
+import androidx.compose.ui.text.font.FontWeight
+
+public object EnteFontFamily {
+ public val inter: FontFamily =
+ FontFamily(
+ Font(R.font.inter_regular, FontWeight.Normal),
+ Font(R.font.inter_medium, FontWeight.Medium),
+ Font(R.font.inter_semibold, FontWeight.SemiBold),
+ Font(R.font.inter_bold, FontWeight.Bold),
+ )
+
+ public val montserrat: FontFamily = FontFamily(Font(R.font.montserrat_bold, FontWeight.Bold))
+}
diff --git a/android/apps/ensu/app/src/main/res/font/inter_bold.ttf b/android/packages/fonts/src/main/res/font/inter_bold.ttf
similarity index 100%
rename from android/apps/ensu/app/src/main/res/font/inter_bold.ttf
rename to android/packages/fonts/src/main/res/font/inter_bold.ttf
diff --git a/android/apps/ensu/app/src/main/res/font/inter_medium.ttf b/android/packages/fonts/src/main/res/font/inter_medium.ttf
similarity index 100%
rename from android/apps/ensu/app/src/main/res/font/inter_medium.ttf
rename to android/packages/fonts/src/main/res/font/inter_medium.ttf
diff --git a/android/apps/ensu/app/src/main/res/font/inter_regular.ttf b/android/packages/fonts/src/main/res/font/inter_regular.ttf
similarity index 100%
rename from android/apps/ensu/app/src/main/res/font/inter_regular.ttf
rename to android/packages/fonts/src/main/res/font/inter_regular.ttf
diff --git a/android/apps/ensu/app/src/main/res/font/inter_semibold.ttf b/android/packages/fonts/src/main/res/font/inter_semibold.ttf
similarity index 100%
rename from android/apps/ensu/app/src/main/res/font/inter_semibold.ttf
rename to android/packages/fonts/src/main/res/font/inter_semibold.ttf
diff --git a/apple/apps/cast/Cast/Fonts/Montserrat-Bold.ttf b/android/packages/fonts/src/main/res/font/montserrat_bold.ttf
similarity index 100%
rename from apple/apps/cast/Cast/Fonts/Montserrat-Bold.ttf
rename to android/packages/fonts/src/main/res/font/montserrat_bold.ttf
diff --git a/android/settings.gradle.kts b/android/settings.gradle.kts
index 7dab0f6a8d..d4d56428aa 100644
--- a/android/settings.gradle.kts
+++ b/android/settings.gradle.kts
@@ -36,3 +36,7 @@ include(":ensu")
project(":ensu").projectDir = file("apps/ensu")
include(":ensu:app", ":ensu:rust")
+
+include(":fonts")
+
+project(":fonts").projectDir = file("packages/fonts")
diff --git a/apple/apps/cast/Cast.xcodeproj/project.pbxproj b/apple/apps/cast/Cast.xcodeproj/project.pbxproj
index 7416d124a0..0742800cc1 100644
--- a/apple/apps/cast/Cast.xcodeproj/project.pbxproj
+++ b/apple/apps/cast/Cast.xcodeproj/project.pbxproj
@@ -8,6 +8,7 @@
/* Begin PBXBuildFile section */
DAF584672E61BB8300F8A08F /* ZIPFoundation in Frameworks */ = {isa = PBXBuildFile; productRef = DAF584662E61BB8300F8A08F /* ZIPFoundation */; };
+ E17E10012F00000100000001 /* EnteFonts in Frameworks */ = {isa = PBXBuildFile; productRef = E17E10022F00000100000002 /* EnteFonts */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
@@ -60,6 +61,7 @@
buildActionMask = 2147483647;
files = (
DAF584672E61BB8300F8A08F /* ZIPFoundation in Frameworks */,
+ E17E10012F00000100000001 /* EnteFonts in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -128,6 +130,7 @@
name = Cast;
packageProductDependencies = (
DAF584662E61BB8300F8A08F /* ZIPFoundation */,
+ E17E10022F00000100000002 /* EnteFonts */,
);
productName = Cast;
productReference = DA72BC612E5F87A000D128FF /* Cast.app */;
@@ -207,6 +210,7 @@
minimizedProjectReferenceProxies = 1;
packageReferences = (
DAF584652E61BB6300F8A08F /* XCRemoteSwiftPackageReference "ZIPFoundation" */,
+ E17E10032F00000100000003 /* XCLocalSwiftPackageReference "../../packages/EnteFonts" */,
);
preferredProjectObjectVersion = 77;
productRefGroup = DA72BC622E5F87A000D128FF /* Products */;
@@ -614,6 +618,13 @@
};
/* End XCConfigurationList section */
+/* Begin XCLocalSwiftPackageReference section */
+ E17E10032F00000100000003 /* XCLocalSwiftPackageReference "../../packages/EnteFonts" */ = {
+ isa = XCLocalSwiftPackageReference;
+ relativePath = ../../packages/EnteFonts;
+ };
+/* End XCLocalSwiftPackageReference section */
+
/* Begin XCRemoteSwiftPackageReference section */
DAF584652E61BB6300F8A08F /* XCRemoteSwiftPackageReference "ZIPFoundation" */ = {
isa = XCRemoteSwiftPackageReference;
@@ -626,6 +637,10 @@
/* End XCRemoteSwiftPackageReference section */
/* Begin XCSwiftPackageProductDependency section */
+ E17E10022F00000100000002 /* EnteFonts */ = {
+ isa = XCSwiftPackageProductDependency;
+ productName = EnteFonts;
+ };
DAF584662E61BB8300F8A08F /* ZIPFoundation */ = {
isa = XCSwiftPackageProductDependency;
package = DAF584652E61BB6300F8A08F /* XCRemoteSwiftPackageReference "ZIPFoundation" */;
diff --git a/apple/apps/cast/Cast/Info.plist b/apple/apps/cast/Cast/Info.plist
index 1853b470de..983f7e6a6e 100644
--- a/apple/apps/cast/Cast/Info.plist
+++ b/apple/apps/cast/Cast/Info.plist
@@ -2,14 +2,6 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
- <key>UIAppFonts</key>
- <array>
- <string>Montserrat-Bold.ttf</string>
- <string>Inter-Regular.ttf</string>
- <string>Inter-Medium.ttf</string>
- <string>Inter-SemiBold.ttf</string>
- <string>Inter-Bold.ttf</string>
- </array>
<key>ITSAppUsesNonExemptEncryption</key>
<false/>
</dict>
diff --git a/apple/apps/cast/Cast/Utils/FontUtils.swift b/apple/apps/cast/Cast/Utils/FontUtils.swift
deleted file mode 100644
index d00a7ec591..0000000000
--- a/apple/apps/cast/Cast/Utils/FontUtils.swift
+++ /dev/null
@@ -1,40 +0,0 @@
-import SwiftUI
-import UIKit
-
-enum FontUtils {
- private static func safeFont(name: String, size: CGFloat, fallback: Font) -> Font {
- if UIFont(name: name, size: size) != nil {
- .custom(name, size: size)
- } else {
- fallback
- }
- }
-
- static func montserratBold(size: CGFloat) -> Font {
- safeFont(name: "Montserrat-Bold", size: size, fallback: .system(size: size, weight: .bold))
- }
-
- static func montserratExtraBold(size: CGFloat) -> Font {
- safeFont(name: "Montserrat-Bold", size: size, fallback: .system(size: size, weight: .heavy))
- }
-
- static func interRegular(size: CGFloat) -> Font {
- safeFont(name: "Inter-Regular", size: size, fallback: .system(size: size, weight: .regular))
- }
-
- static func interMedium(size: CGFloat) -> Font {
- safeFont(name: "Inter-Medium", size: size, fallback: .system(size: size, weight: .medium))
- }
-
- static func interSemiBold(size: CGFloat) -> Font {
- safeFont(
- name: "Inter-SemiBold",
- size: size,
- fallback: .system(size: size, weight: .semibold),
- )
- }
-
- static func interBold(size: CGFloat) -> Font {
- safeFont(name: "Inter-Bold", size: size, fallback: .system(size: size, weight: .bold))
- }
-}
diff --git a/apple/apps/cast/Cast/Views/EnteBranding.swift b/apple/apps/cast/Cast/Views/EnteBranding.swift
index 912b4dfcfc..ab688025e5 100644
--- a/apple/apps/cast/Cast/Views/EnteBranding.swift
+++ b/apple/apps/cast/Cast/Views/EnteBranding.swift
@@ -1,14 +1,15 @@
+import EnteFonts
import SwiftUI
struct EnteBranding: View {
var body: some View {
VStack(alignment: .leading, spacing: -4) {
Text("ente")
- .font(FontUtils.montserratExtraBold(size: 40))
+ .font(EnteFont.montserrat(fixedSize: 40))
.foregroundColor(.black)
Text("photos")
- .font(FontUtils.montserratBold(size: 20))
+ .font(EnteFont.montserrat(fixedSize: 20))
.foregroundColor(.white)
.padding(.horizontal, 10)
.padding(.vertical, 4)
diff --git a/apple/apps/cast/Cast/Views/PairingView.swift b/apple/apps/cast/Cast/Views/PairingView.swift
index 4d169262f9..36b643daa6 100644
--- a/apple/apps/cast/Cast/Views/PairingView.swift
+++ b/apple/apps/cast/Cast/Views/PairingView.swift
@@ -1,3 +1,4 @@
+import EnteFonts
import SwiftUI
import UIKit
@@ -24,15 +25,17 @@ struct PairingView: View {
VStack(spacing: -5) {
Text("Ready to")
.font(
- FontUtils
- .montserratExtraBold(size: geometry.size.width * 0.035)
+ EnteFont.montserrat(
+ fixedSize: geometry.size.width * 0.035
+ )
)
.foregroundColor(.white)
Text("Connect?")
.font(
- FontUtils
- .montserratExtraBold(size: geometry.size.width * 0.065)
+ EnteFont.montserrat(
+ fixedSize: geometry.size.width * 0.065
+ )
)
.foregroundColor(.white)
}
@@ -110,7 +113,12 @@ struct PairingView: View {
.frame(height: geometry.size.height * 0.06)
Text("Visit ente.com/cast for help")
- .font(FontUtils.interMedium(size: geometry.size.width * 0.012))
+ .font(
+ EnteFont.inter(
+ fixedSize: geometry.size.width * 0.012,
+ weight: .medium
+ )
+ )
.foregroundColor(.white)
Spacer()
@@ -189,7 +197,12 @@ struct InstructionStep: View {
}
Text(text)
- .font(FontUtils.interMedium(size: geometry.size.width * 0.012))
+ .font(
+ EnteFont.inter(
+ fixedSize: geometry.size.width * 0.012,
+ weight: .medium
+ )
+ )
.foregroundColor(.white)
.multilineTextAlignment(.center)
}
diff --git a/apple/apps/cast/Cast/Views/StatusView.swift b/apple/apps/cast/Cast/Views/StatusView.swift
index aacaba137c..6b9ab23697 100644
--- a/apple/apps/cast/Cast/Views/StatusView.swift
+++ b/apple/apps/cast/Cast/Views/StatusView.swift
@@ -1,3 +1,4 @@
+import EnteFonts
import SwiftUI
struct StatusView: View {
@@ -27,13 +28,13 @@ struct StatusView: View {
.padding(.bottom, 16)
Text(title)
- .font(FontUtils.interSemiBold(size: 42))
+ .font(EnteFont.inter(fixedSize: 42, weight: .semibold))
.foregroundColor(.black)
.multilineTextAlignment(.center)
if !message.isEmpty {
Text(message)
- .font(FontUtils.interRegular(size: 20))
+ .font(EnteFont.inter(fixedSize: 20))
.foregroundColor(.gray)
.multilineTextAlignment(.center)
.padding(.horizontal, 60)
diff --git a/apple/packages/EnteFonts/Package.swift b/apple/packages/EnteFonts/Package.swift
new file mode 100644
index 0000000000..96e7a66507
--- /dev/null
+++ b/apple/packages/EnteFonts/Package.swift
@@ -0,0 +1,15 @@
+// swift-tools-version: 6.0
+
+import PackageDescription
+
+let package = Package(
+ name: "EnteFonts",
+ platforms: [.iOS("15.1"), .macOS(.v13), .tvOS(.v16)],
+ products: [.library(name: "EnteFonts", targets: ["EnteFonts"])],
+ targets: [
+ .target(
+ name: "EnteFonts",
+ resources: [.process("Resources")]
+ )
+ ]
+)
diff --git a/apple/packages/EnteFonts/Sources/EnteFonts/EnteFont.swift b/apple/packages/EnteFonts/Sources/EnteFonts/EnteFont.swift
new file mode 100644
index 0000000000..c0f485d349
--- /dev/null
+++ b/apple/packages/EnteFonts/Sources/EnteFonts/EnteFont.swift
@@ -0,0 +1,61 @@
+import CoreText
+import SwiftUI
+
+public enum EnteFont {
+ public enum InterWeight {
+ case light
+ case regular
+ case medium
+ case semibold
+ case bold
+
+ fileprivate var name: String {
+ switch self {
+ case .light: "Inter-Light"
+ case .regular: "Inter-Regular"
+ case .medium: "Inter-Medium"
+ case .semibold: "Inter-SemiBold"
+ case .bold: "Inter-Bold"
+ }
+ }
+ }
+
+ public static func inter(
+ size: CGFloat,
+ weight: InterWeight = .regular,
+ relativeTo textStyle: Font.TextStyle = .body
+ ) -> Font {
+ _ = registration
+ return .custom(weight.name, size: size, relativeTo: textStyle)
+ }
+
+ public static func inter(fixedSize: CGFloat, weight: InterWeight = .regular) -> Font {
+ _ = registration
+ return .custom(weight.name, fixedSize: fixedSize)
+ }
+
+ public static func montserrat(
+ size: CGFloat,
+ relativeTo textStyle: Font.TextStyle = .body
+ ) -> Font {
+ _ = registration
+ return .custom("Montserrat-Bold", size: size, relativeTo: textStyle)
+ }
+
+ public static func montserrat(fixedSize: CGFloat) -> Font {
+ _ = registration
+ return .custom("Montserrat-Bold", fixedSize: fixedSize)
+ }
+
+ private static let registration: Void = {
+ for url in Bundle.module.urls(forResourcesWithExtension: "ttf", subdirectory: nil) ?? [] {
+ var error: Unmanaged<CFError>?
+ let registered = CTFontManagerRegisterFontsForURL(url as CFURL, .process, &error)
+ let errorCode = error.map { CFErrorGetCode($0.takeRetainedValue()) }
+ assert(
+ registered || errorCode == CTFontManagerError.alreadyRegistered.rawValue,
+ "Failed to register font: \(url.lastPathComponent)"
+ )
+ }
+ }()
+}
diff --git a/apple/apps/cast/Cast/Fonts/Inter-Bold.ttf b/apple/packages/EnteFonts/Sources/EnteFonts/Resources/Inter-Bold.ttf
similarity index 100%
rename from apple/apps/cast/Cast/Fonts/Inter-Bold.ttf
rename to apple/packages/EnteFonts/Sources/EnteFonts/Resources/Inter-Bold.ttf
diff --git a/apple/apps/cast/Cast/Fonts/Inter-Light.ttf b/apple/packages/EnteFonts/Sources/EnteFonts/Resources/Inter-Light.ttf
similarity index 100%
rename from apple/apps/cast/Cast/Fonts/Inter-Light.ttf
rename to apple/packages/EnteFonts/Sources/EnteFonts/Resources/Inter-Light.ttf
diff --git a/apple/apps/cast/Cast/Fonts/Inter-Medium.ttf b/apple/packages/EnteFonts/Sources/EnteFonts/Resources/Inter-Medium.ttf
similarity index 100%
rename from apple/apps/cast/Cast/Fonts/Inter-Medium.ttf
rename to apple/packages/EnteFonts/Sources/EnteFonts/Resources/Inter-Medium.ttf
diff --git a/apple/apps/cast/Cast/Fonts/Inter-Regular.ttf b/apple/packages/EnteFonts/Sources/EnteFonts/Resources/Inter-Regular.ttf
similarity index 100%
rename from apple/apps/cast/Cast/Fonts/Inter-Regular.ttf
rename to apple/packages/EnteFonts/Sources/EnteFonts/Resources/Inter-Regular.ttf
diff --git a/apple/apps/cast/Cast/Fonts/Inter-SemiBold.ttf b/apple/packages/EnteFonts/Sources/EnteFonts/Resources/Inter-SemiBold.ttf
similarity index 100%
rename from apple/apps/cast/Cast/Fonts/Inter-SemiBold.ttf
rename to apple/packages/EnteFonts/Sources/EnteFonts/Resources/Inter-SemiBold.ttf
diff --git a/apple/packages/EnteFonts/Sources/EnteFonts/Resources/Montserrat-Bold.ttf b/apple/packages/EnteFonts/Sources/EnteFonts/Resources/Montserrat-Bold.ttf
new file mode 100644
index 0000000000..55e0b1a553
Binary files /dev/null and b/apple/packages/EnteFonts/Sources/EnteFonts/Resources/Montserrat-Bold.ttf differ