MachineTranslations: Add font settings (#10307)
* Add font settings * Bump version * Fix utf-8 * Add open fonts * Fix lint * Update messages * Fix filename * Remove distinctBy
This commit is contained in:
parent
f990ba581a
commit
7dea021357
@ -0,0 +1,25 @@
|
||||
This font is © 2006 Nate Piekos. All Rights Reserved.
|
||||
Created for Blambot Fonts
|
||||
|
||||
This font is freeware for independent comic book creation and
|
||||
non-profit use ONLY. ( This excludes use by "mainstream" publishers,
|
||||
(Marvel, DC, Dark Horse, Oni, Image, SLG, Top Cow, Crossgen and their
|
||||
subsidiaries) without a license fee. Use by a "mainstream" publisher
|
||||
(or it's employee), and use for commercial non-comic book production
|
||||
(eg. magazine ads, merchandise lables etc.) incurs a license fee
|
||||
be paid to the designer, Nate Piekos.
|
||||
This font may not be redistributed without the author's permission and
|
||||
never with this text file missing from the .zip, .sit or .hqx.
|
||||
|
||||
Blambot/Nate Piekos makes no guarantees about these font files,
|
||||
the completeness of character sets, or safety of these files on your
|
||||
computer. By installing these fonts on your system, you prove that
|
||||
you have read and understand the above.
|
||||
|
||||
If you have any questions, visit http://www.blambot.com/license.shtml
|
||||
|
||||
For more free and original fonts visit Blambot.
|
||||
www.blambot.com
|
||||
|
||||
Nate Piekos
|
||||
studio@blambot.com
|
@ -0,0 +1,93 @@
|
||||
Copyright 2014 The Comic Neue Project Authors (https://github.com/crozynski/comicneue)
|
||||
|
||||
This Font Software is licensed under the SIL Open Font License, Version 1.1.
|
||||
This license is copied below, and is also available with a FAQ at:
|
||||
https://openfontlicense.org
|
||||
|
||||
|
||||
-----------------------------------------------------------
|
||||
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
|
||||
-----------------------------------------------------------
|
||||
|
||||
PREAMBLE
|
||||
The goals of the Open Font License (OFL) are to stimulate worldwide
|
||||
development of collaborative font projects, to support the font creation
|
||||
efforts of academic and linguistic communities, and to provide a free and
|
||||
open framework in which fonts may be shared and improved in partnership
|
||||
with others.
|
||||
|
||||
The OFL allows the licensed fonts to be used, studied, modified and
|
||||
redistributed freely as long as they are not sold by themselves. The
|
||||
fonts, including any derivative works, can be bundled, embedded,
|
||||
redistributed and/or sold with any software provided that any reserved
|
||||
names are not used by derivative works. The fonts and derivatives,
|
||||
however, cannot be released under any other type of license. The
|
||||
requirement for fonts to remain under this license does not apply
|
||||
to any document created using the fonts or their derivatives.
|
||||
|
||||
DEFINITIONS
|
||||
"Font Software" refers to the set of files released by the Copyright
|
||||
Holder(s) under this license and clearly marked as such. This may
|
||||
include source files, build scripts and documentation.
|
||||
|
||||
"Reserved Font Name" refers to any names specified as such after the
|
||||
copyright statement(s).
|
||||
|
||||
"Original Version" refers to the collection of Font Software components as
|
||||
distributed by the Copyright Holder(s).
|
||||
|
||||
"Modified Version" refers to any derivative made by adding to, deleting,
|
||||
or substituting -- in part or in whole -- any of the components of the
|
||||
Original Version, by changing formats or by porting the Font Software to a
|
||||
new environment.
|
||||
|
||||
"Author" refers to any designer, engineer, programmer, technical
|
||||
writer or other person who contributed to the Font Software.
|
||||
|
||||
PERMISSION & CONDITIONS
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of the Font Software, to use, study, copy, merge, embed, modify,
|
||||
redistribute, and sell modified and unmodified copies of the Font
|
||||
Software, subject to the following conditions:
|
||||
|
||||
1) Neither the Font Software nor any of its individual components,
|
||||
in Original or Modified Versions, may be sold by itself.
|
||||
|
||||
2) Original or Modified Versions of the Font Software may be bundled,
|
||||
redistributed and/or sold with any software, provided that each copy
|
||||
contains the above copyright notice and this license. These can be
|
||||
included either as stand-alone text files, human-readable headers or
|
||||
in the appropriate machine-readable metadata fields within text or
|
||||
binary files as long as those fields can be easily viewed by the user.
|
||||
|
||||
3) No Modified Version of the Font Software may use the Reserved Font
|
||||
Name(s) unless explicit written permission is granted by the corresponding
|
||||
Copyright Holder. This restriction only applies to the primary font name as
|
||||
presented to the users.
|
||||
|
||||
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
|
||||
Software shall not be used to promote, endorse or advertise any
|
||||
Modified Version, except to acknowledge the contribution(s) of the
|
||||
Copyright Holder(s) and the Author(s) or with their explicit written
|
||||
permission.
|
||||
|
||||
5) The Font Software, modified or unmodified, in part or in whole,
|
||||
must be distributed entirely under this license, and must not be
|
||||
distributed under any other license. The requirement for fonts to
|
||||
remain under this license does not apply to any document created
|
||||
using the Font Software.
|
||||
|
||||
TERMINATION
|
||||
This license becomes null and void if any of the above conditions are
|
||||
not met.
|
||||
|
||||
DISCLAIMER
|
||||
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
|
||||
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
|
||||
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
|
||||
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
|
||||
OTHER DEALINGS IN THE FONT SOFTWARE.
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,9 +1,13 @@
|
||||
font_name_title=Font name
|
||||
font_name_summary=Customize dialogues by choosing your preferred font. To apply the change to chapters that have already been read, you will need to clear the chapter cache in "More > Data and storage > Clear chapter cache". Font changes will not affect downloaded chapters
|
||||
font_name_message=Font name changed to %s
|
||||
font_name_device_title=Device
|
||||
font_size_title=Font size
|
||||
font_size_summary=Font changes will not be applied to downloaded or cached chapters. The font size will be adjusted according to the size of the dialog box.
|
||||
font_size_message=Font size changed to %s
|
||||
default_font_size=Default
|
||||
disable_website_setting_title=Disable source settings
|
||||
disable_website_setting_summary=Site fonts will be disabled and your device's fonts will be applied. This does not apply to downloaded or cached chapters.
|
||||
default_font_name=Default
|
||||
default_font_name_title=Web site
|
||||
disable_word_break_title=Disable word break
|
||||
disable_word_break_summary=This feature prevents words from being automatically broken in the middle of a line.
|
||||
disable_translator_title=Disable translator
|
||||
|
@ -1,9 +1,13 @@
|
||||
font_name_title=Fonte
|
||||
font_name_summary=Personalize os diálogos escolhendo a fonte de sua preferência. Para aplicar a alteração em capitulos lidos será necessário limpar o cache de capitulos em "Mais > Dados e armazenamento > Limpar cache de capítulos". As alterações de fonte não serão aplicadas aos capítulos baixados.
|
||||
font_name_message=Fonte alterada para %s
|
||||
font_name_device_title=Dispositivo
|
||||
font_size_title=Tamanho da fonte
|
||||
font_size_summary=As alterações de fonte não serão aplicadas aos capítulos baixados ou armazenados em cache. O tamanho da fonte será ajustado de acordo com o tamanho da caixa de diálogo.
|
||||
font_size_message=Tamanho da fonte foi alterada para %s
|
||||
default_font_size=Padrão
|
||||
disable_website_setting_title=Desativar configurações do site
|
||||
disable_website_setting_summary=As fontes do site serão desativadas e as fontes de seu dispositivo serão aplicadas. Isso não se aplica a capítulos baixados ou armazenados em cache.
|
||||
default_font_name=Padrão
|
||||
default_font_name_title=Site
|
||||
disable_word_break_title=Desativar quebra de palavras
|
||||
disable_word_break_summary=Esse recurso impede que palavras sejam quebradas automaticamente no meio da linha.
|
||||
disable_translator_title=Desativar tradutor
|
||||
|
@ -2,7 +2,7 @@ plugins {
|
||||
id("lib-multisrc")
|
||||
}
|
||||
|
||||
baseVersionCode = 8
|
||||
baseVersionCode = 9
|
||||
|
||||
dependencies {
|
||||
api(project(":lib:i18n"))
|
||||
|
@ -73,6 +73,10 @@ abstract class MachineTranslations(
|
||||
get() = preferences.getString(FONT_SIZE_PREF, DEFAULT_FONT_SIZE)!!.toInt()
|
||||
set(value) = preferences.edit().putString(FONT_SIZE_PREF, value.toString()).apply()
|
||||
|
||||
protected var fontName: String
|
||||
get() = preferences.getString(FONT_NAME_PREF, language.fontName)!!
|
||||
set(value) = preferences.edit().putString(FONT_NAME_PREF, value).apply()
|
||||
|
||||
protected var disableWordBreak: Boolean
|
||||
get() = preferences.getBoolean(DISABLE_WORD_BREAK_PREF, language.disableWordBreak)
|
||||
set(value) = preferences.edit().putBoolean(DISABLE_WORD_BREAK_PREF, value).apply()
|
||||
@ -81,10 +85,6 @@ abstract class MachineTranslations(
|
||||
get() = preferences.getBoolean(DISABLE_TRANSLATOR_PREF, language.disableTranslator)
|
||||
set(value) = preferences.edit().putBoolean(DISABLE_TRANSLATOR_PREF, value).apply()
|
||||
|
||||
protected var disableSourceSettings: Boolean
|
||||
get() = preferences.getBoolean(DISABLE_SOURCE_SETTINGS_PREF, language.disableSourceSettings)
|
||||
set(value) = preferences.edit().putBoolean(DISABLE_SOURCE_SETTINGS_PREF, value).apply()
|
||||
|
||||
protected var enableMangaDetailsTranslation: Boolean
|
||||
get() = preferences.getBoolean(ENABLE_MANGA_DETAILS_TRANSLATION_PREF, false)
|
||||
set(value) = preferences.edit().putBoolean(ENABLE_MANGA_DETAILS_TRANSLATION_PREF, value).apply()
|
||||
@ -98,9 +98,10 @@ abstract class MachineTranslations(
|
||||
|
||||
private val settings get() = language.copy(
|
||||
fontSize = this@MachineTranslations.fontSize,
|
||||
fontName = this@MachineTranslations.fontName,
|
||||
disableWordBreak = this@MachineTranslations.disableWordBreak,
|
||||
disableTranslator = this@MachineTranslations.disableTranslator,
|
||||
disableSourceSettings = this@MachineTranslations.disableSourceSettings,
|
||||
disableFontSettings = this@MachineTranslations.fontName == DEVICE_FONT,
|
||||
)
|
||||
|
||||
override val client: OkHttpClient get() = clientInstance!!
|
||||
@ -328,6 +329,14 @@ abstract class MachineTranslations(
|
||||
"80", "88", "96",
|
||||
)
|
||||
|
||||
val fonts = arrayOf(
|
||||
intl["default_font_name_title"] to "",
|
||||
intl["font_name_device_title"] to DEVICE_FONT,
|
||||
"Anime Ace" to "animeace2_regular",
|
||||
"Comic Neue" to "comic_neue_bold",
|
||||
"Coming Soon" to "coming_soon_regular",
|
||||
)
|
||||
|
||||
ListPreference(screen.context).apply {
|
||||
key = FONT_SIZE_PREF
|
||||
title = intl["font_size_title"]
|
||||
@ -335,7 +344,11 @@ abstract class MachineTranslations(
|
||||
"${it}pt" + if (it == DEFAULT_FONT_SIZE) " - ${intl["default_font_size"]}" else ""
|
||||
}.toTypedArray()
|
||||
entryValues = sizes
|
||||
summary = intl["font_size_summary"]
|
||||
|
||||
summary = buildString {
|
||||
appendLine(intl["font_size_summary"])
|
||||
append("\t* %s")
|
||||
}
|
||||
|
||||
setDefaultValue(fontSize.toString())
|
||||
|
||||
@ -356,15 +369,35 @@ abstract class MachineTranslations(
|
||||
}
|
||||
}.also(screen::addPreference)
|
||||
|
||||
if (!language.disableSourceSettings) {
|
||||
SwitchPreferenceCompat(screen.context).apply {
|
||||
key = DISABLE_SOURCE_SETTINGS_PREF
|
||||
title = "⚠ ${intl["disable_website_setting_title"]}"
|
||||
summary = intl["disable_website_setting_summary"]
|
||||
setDefaultValue(language.disableSourceSettings)
|
||||
if (!language.disableFontSettings) {
|
||||
ListPreference(screen.context).apply {
|
||||
key = FONT_NAME_PREF
|
||||
title = intl["font_name_title"]
|
||||
entries = fonts.map {
|
||||
it.first + if (it.second.isBlank()) " - ${intl["default_font_name"]}" else ""
|
||||
}.toTypedArray()
|
||||
entryValues = fonts.map { it.second }.toTypedArray()
|
||||
summary = buildString {
|
||||
appendLine(intl["font_name_summary"])
|
||||
append("\t* %s")
|
||||
}
|
||||
|
||||
setDefaultValue(fontName)
|
||||
|
||||
setOnPreferenceChange { _, newValue ->
|
||||
disableSourceSettings = newValue as Boolean
|
||||
true
|
||||
val selected = newValue as String
|
||||
val index = this.findIndexOfValue(selected)
|
||||
val entry = entries[index] as String
|
||||
|
||||
fontName = selected
|
||||
|
||||
Toast.makeText(
|
||||
screen.context,
|
||||
intl["font_name_message"].format(entry),
|
||||
Toast.LENGTH_LONG,
|
||||
).show()
|
||||
|
||||
true // It's necessary to update the user interface
|
||||
}
|
||||
}.also(screen::addPreference)
|
||||
}
|
||||
@ -453,9 +486,10 @@ abstract class MachineTranslations(
|
||||
|
||||
companion object {
|
||||
val PAGE_REGEX = Regex(".*?\\.(webp|png|jpg|jpeg)#\\[.*?]", RegexOption.IGNORE_CASE)
|
||||
const val DEVICE_FONT = "device:"
|
||||
const val PREFIX_SEARCH = "id:"
|
||||
private const val FONT_SIZE_PREF = "fontSizePref"
|
||||
private const val DISABLE_SOURCE_SETTINGS_PREF = "disableSourceSettingsPref"
|
||||
private const val FONT_NAME_PREF = "fontNamePref"
|
||||
private const val DISABLE_WORD_BREAK_PREF = "disableWordBreakPref"
|
||||
private const val DISABLE_TRANSLATOR_PREF = "disableTranslatorPref"
|
||||
private const val ENABLE_MANGA_DETAILS_TRANSLATION_PREF = "enableMangaDetailsTranslationPref"
|
||||
|
@ -7,8 +7,9 @@ data class Language(
|
||||
val target: String = lang,
|
||||
val origin: String = "en",
|
||||
val fontSize: Int = 24,
|
||||
val disableSourceSettings: Boolean = false,
|
||||
val disableFontSettings: Boolean = false,
|
||||
val disableWordBreak: Boolean = false,
|
||||
val disableTranslator: Boolean = false,
|
||||
val supportNativeTranslation: Boolean = false,
|
||||
val fontName: String = "",
|
||||
)
|
||||
|
@ -60,7 +60,7 @@ class ComposedImageInterceptor(
|
||||
|
||||
// Load the fonts before opening the connection to load the image,
|
||||
// so there aren't two open connections inside the interceptor.
|
||||
if (language.disableSourceSettings.not()) {
|
||||
if (!language.disableFontSettings) {
|
||||
loadAllFont(chain)
|
||||
}
|
||||
|
||||
@ -115,7 +115,7 @@ class ComposedImageInterceptor(
|
||||
}
|
||||
|
||||
private fun selectFontFamily(type: String): Typeface? {
|
||||
if (language.disableSourceSettings) {
|
||||
if (language.disableFontSettings) {
|
||||
return null
|
||||
}
|
||||
|
||||
@ -136,6 +136,11 @@ class ComposedImageInterceptor(
|
||||
if (font.second != null) {
|
||||
return@forEach
|
||||
}
|
||||
if (language.fontName.isNotBlank()) {
|
||||
fontFamily[key] = key to loadFont("${language.fontName}.ttf")
|
||||
return@forEach
|
||||
}
|
||||
|
||||
fontFamily[key] = key to (loadRemoteFont(font.first, chain) ?: fallback)
|
||||
}
|
||||
}
|
||||
@ -231,7 +236,7 @@ class ComposedImageInterceptor(
|
||||
|
||||
return StaticLayout.Builder.obtain(text, 0, text.length, textPaint, dialog.width.toInt()).apply {
|
||||
setAlignment(Layout.Alignment.ALIGN_CENTER)
|
||||
setIncludePad(language.disableSourceSettings)
|
||||
setIncludePad(language.disableFontSettings)
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||
if (language.disableWordBreak) {
|
||||
setBreakStrategy(LineBreaker.BREAK_STRATEGY_SIMPLE)
|
||||
|
@ -11,7 +11,7 @@ class SnowmtlFactory : SourceFactory {
|
||||
}
|
||||
|
||||
private val languageList = listOf(
|
||||
Language("ar", disableSourceSettings = true),
|
||||
Language("ar", disableFontSettings = true),
|
||||
Language("en"),
|
||||
Language("es"),
|
||||
Language("fr", supportNativeTranslation = true),
|
||||
|
@ -11,7 +11,7 @@ class SolarmtlFactory : SourceFactory {
|
||||
}
|
||||
|
||||
private val languageList = listOf(
|
||||
Language("ar", disableSourceSettings = true),
|
||||
Language("ar", disableFontSettings = true),
|
||||
Language("en"),
|
||||
Language("es"),
|
||||
Language("fr", supportNativeTranslation = true),
|
||||
|
Loading…
x
Reference in New Issue
Block a user