feat(theme): filter custom-font picker to font MIME types
Restrict the "Choose file…" document picker to font MIME types (font/ttf, font/otf, font/sfnt, font/collection plus legacy application/* font aliases) instead of */*, so only fonts are selectable. CustomFontStore's Font.Builder validation still guards anything a provider mislabels. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1402,6 +1402,23 @@ private fun fontLabel(token: String): String = when (token) {
|
|||||||
?: stringResource(R.string.settings_font_system)
|
?: stringResource(R.string.settings_font_system)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MIME types offered to the document picker so it lists only font files. Covers
|
||||||
|
* the modern `font/` types plus the legacy `application/` font aliases some
|
||||||
|
* providers still report. Anything that slips through is still validated by
|
||||||
|
* [de.jeanlucmakiola.calendula.data.fonts.CustomFontStore] before use.
|
||||||
|
*/
|
||||||
|
private val FONT_PICKER_MIME_TYPES = arrayOf(
|
||||||
|
"font/ttf",
|
||||||
|
"font/otf",
|
||||||
|
"font/sfnt",
|
||||||
|
"font/collection",
|
||||||
|
"application/x-font-ttf",
|
||||||
|
"application/x-font-otf",
|
||||||
|
"application/font-sfnt",
|
||||||
|
"application/vnd.ms-opentype",
|
||||||
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Full-screen font chooser for one [FontRole]: the system default, each bundled
|
* Full-screen font chooser for one [FontRole]: the system default, each bundled
|
||||||
* font (previewed in its own face), and "Choose file…" which opens the system
|
* font (previewed in its own face), and "Choose file…" which opens the system
|
||||||
@@ -1466,7 +1483,7 @@ private fun FontPicker(
|
|||||||
leadingIcon = if (isCustom) null else Icons.Default.UploadFile,
|
leadingIcon = if (isCustom) null else Icons.Default.UploadFile,
|
||||||
selected = isCustom,
|
selected = isCustom,
|
||||||
position = positionOf(rowCount - 1, rowCount),
|
position = positionOf(rowCount - 1, rowCount),
|
||||||
onClick = { launcher.launch(arrayOf("*/*")) },
|
onClick = { launcher.launch(FONT_PICKER_MIME_TYPES) },
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user