-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
379 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
syntakts-android/src/main/kotlin/xyz/wingio/syntakts/android/style/AndroidFontResolver.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package xyz.wingio.syntakts.android.style | ||
|
||
import android.graphics.Typeface | ||
import xyz.wingio.syntakts.style.FontResolver | ||
import xyz.wingio.syntakts.style.Fonts | ||
|
||
/** | ||
* Keeps a record of [Typefaces][Typeface] with a plain font name | ||
* | ||
* For most cases it is reccommended to use [DefaultFontResolver] to register your fonts | ||
*/ | ||
public class AndroidFontResolver: FontResolver<Typeface>() { | ||
|
||
override val fontMap: MutableMap<String, Typeface> = mutableMapOf( | ||
Fonts.DEFAULT to Typeface.DEFAULT, | ||
Fonts.MONOSPACE to Typeface.MONOSPACE, | ||
"monospaced" to Typeface.MONOSPACE, | ||
Fonts.SERIF to Typeface.SERIF, | ||
Fonts.SANS_SERIF to Typeface.SANS_SERIF | ||
) | ||
|
||
/** | ||
* Gets a font in the [Typeface] format from a given name | ||
* | ||
* @param fontName Case-insensitive font name to look up | ||
*/ | ||
public override fun resolveFont(fontName: String): Typeface? { | ||
return fontMap[fontName.lowercase()] | ||
} | ||
|
||
/** | ||
* Registers a [Typeface] with the specified [name][fontName] | ||
* | ||
* @param fontName Case-insensitive name to use for the [font][platformFont] | ||
* @param platformFont The font to register with the [fontName] | ||
*/ | ||
override fun registerFont(fontName: String, platformFont: Typeface) { | ||
fontMap[fontName.lowercase()] = platformFont | ||
} | ||
|
||
|
||
} | ||
|
||
/** | ||
* Default [FontResolver] used when rendering | ||
*/ | ||
public val DefaultFontResolver: AndroidFontResolver = AndroidFontResolver() |
Oops, something went wrong.