-
Notifications
You must be signed in to change notification settings - Fork 81
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
8 changed files
with
123 additions
and
15 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
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
34 changes: 34 additions & 0 deletions
34
src/main/java/moe/dituon/petpet/share/element/text/TextTemplate.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,34 @@ | ||
package moe.dituon.petpet.share.element.text | ||
|
||
import kotlinx.serialization.Serializable | ||
import moe.dituon.petpet.share.* | ||
import java.awt.Color | ||
|
||
@Serializable | ||
data class TextTemplate( | ||
var text: String, | ||
var pos: IntArray = intArrayOf(0, 0), | ||
var angle: Short = 0, | ||
var color: String = TextModel.DEFAULT_COLOR_STR, | ||
var font: String = "simsun", | ||
var size: Int = 16, | ||
var align: TextAlign = TextAlign.LEFT, | ||
var baseline: TextBaseline = TextBaseline.TOP, | ||
var wrap: TextWrap = TextWrap.NONE, | ||
var style: TextStyle = TextStyle.PLAIN, | ||
var position: List<Position>? = listOf(Position.LEFT, Position.TOP), | ||
var origin: TransformOrigin = TransformOrigin.DEFAULT, | ||
var strokeColor: String = TextModel.DEFAULT_STROKE_COLOR_STR, | ||
var strokeSize: Short = 0, | ||
var greedy: Boolean = false | ||
) { | ||
fun getAwtColor(): Color { | ||
if (color == moe.dituon.petpet.share.TextModel.DEFAULT_COLOR_STR) return moe.dituon.petpet.share.TextModel.DEFAULT_COLOR | ||
return decodeColor(color) | ||
} | ||
|
||
fun getStrokeAwtColor(): Color { | ||
if (strokeColor == moe.dituon.petpet.share.TextModel.DEFAULT_STROKE_COLOR_STR) return moe.dituon.petpet.share.TextModel.DEFAULT_STROKE_COLOR | ||
return decodeColor(strokeColor) | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
src/main/java/moe/dituon/petpet/share/service/FontManager.java
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,68 @@ | ||
package moe.dituon.petpet.share.service; | ||
|
||
import java.awt.*; | ||
import java.util.List; | ||
import java.util.*; | ||
import java.util.stream.Collectors; | ||
|
||
public class FontManager { | ||
protected static class FontManagerInstance { | ||
private static final FontManager INSTANCE = new FontManager(); | ||
} | ||
|
||
public static FontManager getInstance() { | ||
return FontManagerInstance.INSTANCE; | ||
} | ||
|
||
final GraphicsEnvironment environment = GraphicsEnvironment.getLocalGraphicsEnvironment(); | ||
public final List<SupportedLanguage> supportedLanguageList = List.of( | ||
new SupportedLanguage("en", "Latin", new char[]{0x0061}), | ||
new SupportedLanguage("zh", "CJK Unified Ideographs", new char[]{0x4E00}), | ||
new SupportedLanguage("ja", "Hiragana", new char[]{0x3041}), | ||
new SupportedLanguage("ko", "Hangul Syllables", new char[]{0xAC00}), | ||
new SupportedLanguage("th", "Thai", new char[]{0x0E01}), | ||
new SupportedLanguage("ru", "Cyrillic", new char[]{0x0410}), | ||
new SupportedLanguage("ar", "Arabic", new char[]{0x0621}), | ||
new SupportedLanguage("he", "Hebrew", new char[]{0x05D0}), | ||
new SupportedLanguage("vi", "Vietnamese", new char[]{0x0102}) | ||
// , new SupportedLanguage("emoji", "Emoji", Character.toChars(0x1F600)) | ||
); | ||
final Map<Font, Set<SupportedLanguage>> fontSupportedLanguageMap = new HashMap<>(256); | ||
final Map<SupportedLanguage, Set<Font>> supportedLanguageFontMap = new HashMap<>(256); | ||
|
||
protected FontManager() { | ||
for (Font font : environment.getAllFonts()) { | ||
addFont(font); | ||
} | ||
} | ||
|
||
public void addFont(Font font) { | ||
var langSet = fontSupportedLanguageMap.compute(font, (f, s) -> | ||
s == null ? new HashSet<>(supportedLanguageList.size()) : s | ||
); | ||
for (SupportedLanguage language : supportedLanguageList) { | ||
boolean flag = true; | ||
for (char point : language.testPoints) { | ||
if (!font.canDisplay(point)) flag = false; | ||
} | ||
if (flag) { | ||
langSet.add(language); | ||
supportedLanguageFontMap.compute(language, (l, s) -> | ||
s == null ? new HashSet<>(8) : s | ||
).add(font); | ||
} | ||
} | ||
} | ||
|
||
public static class SupportedLanguage { | ||
protected char[] testPoints; | ||
public final String name; | ||
public final String desc; | ||
|
||
protected SupportedLanguage(String name, String desc, char[] testPoints) { | ||
this.name = name; | ||
this.desc = desc; | ||
this.testPoints = testPoints; | ||
} | ||
} | ||
} |
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