Skip to content

Commit

Permalink
Default value and translation for Chinese China and Taiwan.
Browse files Browse the repository at this point in the history
  • Loading branch information
Guo Yunhe committed Sep 9, 2015
1 parent f966c77 commit 64726fa
Show file tree
Hide file tree
Showing 6 changed files with 161 additions and 202 deletions.
115 changes: 113 additions & 2 deletions src/me/guoyunhe/fontweak/FontConfigXML.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.parsers.DocumentBuilder;
Expand Down Expand Up @@ -83,8 +85,8 @@ public class FontConfigXML {

private static final String[] familyOptions = {"sans-serif", "serif", "monospace"};
public static final int SANS = 0;
public static final int SERIF = 0;
public static final int MONO = 0;
public static final int SERIF = 1;
public static final int MONO = 2;

private final String[][] fontArray;

Expand Down Expand Up @@ -490,6 +492,15 @@ private String familyEncode(int num) {
return str;
}

public String fontFallback(String[] fonts, List<String> list) {
for (String font : fonts) {
if (list.contains(font)) {
return font;
}
}
return null;
}

public void setFontFamily(int lang, int family, String font) {
fontArray[lang][family] = font;
}
Expand All @@ -498,6 +509,106 @@ public String getFontFamily(int lang, int family) {
return fontArray[lang][family];
}

public String[][] getDefaultFontFamilyArray(String[] list) {
String[][] defaultFontArray = new String[langOptions.length][familyOptions.length];
List fontList = Arrays.asList(list);

defaultFontArray[EN][SANS] = fontFallback(new String[]{
"Ubuntu", // Ubuntu pre-install
"Nimbus Sans L",
"DejaVu Sans",
"Liberation Sans",
"Droid Sans"
}, fontList);

defaultFontArray[EN][SERIF] = fontFallback(new String[]{
"Nimbus Roman No9 L",
"DejaVu Serif",
"Liberation Serif",
"Droid Serif"
}, fontList);

defaultFontArray[EN][MONO] = fontFallback(new String[]{
"Ubuntu Mono", // Ubuntu pre-install
"DejaVu Sans Mono",
"Libration Mono",
"Droid Sans Mono",
}, fontList);

defaultFontArray[ZH][SANS] = fontFallback(new String[]{
"WenQuanYi Micro Hei",
"Droid Sans Fallback",
"WenQuanYi Zen Hei"
}, fontList);

defaultFontArray[ZH][SERIF] = fontFallback(new String[]{
"AR PL UMing CN"
}, fontList);

defaultFontArray[ZH][MONO] = fontFallback(new String[]{
"WenQuanYi Micro Hei Mono",
}, fontList);

defaultFontArray[ZH_CN][SANS] = fontFallback(new String[]{
"WenQuanYi Micro Hei",
"Droid Sans Fallback",
"WenQuanYi Zen Hei"
}, fontList);

defaultFontArray[ZH_CN][SERIF] = fontFallback(new String[]{
"AR PL UMing CN"
}, fontList);

defaultFontArray[ZH_CN][MONO] = fontFallback(new String[]{
"WenQuanYi Micro Hei Mono",
}, fontList);

defaultFontArray[ZH_TW][SANS] = fontFallback(new String[]{
"WenQuanYi Micro Hei",
"Droid Sans Fallback",
"WenQuanYi Zen Hei"
}, fontList);

defaultFontArray[ZH_TW][SERIF] = fontFallback(new String[]{
"AR PL UMing TW"
}, fontList);

defaultFontArray[ZH_TW][MONO] = fontFallback(new String[]{
"WenQuanYi Micro Hei Mono",
}, fontList);

defaultFontArray[JA][SANS] = fontFallback(new String[]{
"Droid Sans Japanese",
"WenQuanYi Micro Hei",
"WenQuanYi Zen Hei"
}, fontList);

defaultFontArray[JA][SERIF] = fontFallback(new String[]{
"AR PL UMing TW"
}, fontList);

defaultFontArray[JA][MONO] = fontFallback(new String[]{
"Droid Sans Japanese",
"WenQuanYi Micro Hei Mono"
}, fontList);

defaultFontArray[KO][SANS] = fontFallback(new String[]{
"WenQuanYi Micro Hei",
"Droid Sans Fallback",
"WenQuanYi Zen Hei"
}, fontList);

defaultFontArray[KO][SERIF] = fontFallback(new String[]{
"AR PL UMing TW"
}, fontList);

defaultFontArray[KO][MONO] = fontFallback(new String[]{
"WenQuanYi Micro Hei Mono"
}, fontList);

return defaultFontArray;
}

public void setAntiAlias(boolean antialias) {
this.antialias = antialias;
}
Expand Down
140 changes: 0 additions & 140 deletions src/me/guoyunhe/fontweak/FontList.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,144 +100,4 @@ public void refresh() {
public boolean contains(String font) {
return list.contains(font);
}

/**
* Find installed from fallback font list. Only first installed font will be
* returned. Note: in different language environment, names of fonts may
* differ.
* @param fonts A list of fonts to be search.
* @return The first font found, or null if nothing found.
*/
public String fontFallback(String[] fonts) {
for (String font : fonts) {
if (list.contains(font)) {
return font;
}
}
return null;
}

public String sansFallback() {
// This fallback list only contains Free and Open Source fonts
String[] fonts = {
"Ubuntu", // Ubuntu pre-install
"Nimbus Sans L",
"DejaVu Sans",
"Liberation Sans",
"Droid Sans"
};
return fontFallback(fonts);
}

public String serifFallback() {
// This fallback list only contains Free and Open Source fonts
String[] fonts = {
"Nimbus Roman No9 L",
"DejaVu Serif",
"Liberation Serif",
"Droid Serif"
};
return fontFallback(fonts);
}

public String monoFallback() {
// This fallback list only contains Free and Open Source fonts
String[] fonts = {
"Ubuntu Mono", // Ubuntu pre-install
"DejaVu Sans Mono",
"Libration Mono",
"Droid Sans Mono",
};
return fontFallback(fonts);
}

public String zhCNSansFallback() {
// This fallback list only contains Free and Open Source fonts
String[] fonts = {
"WenQuanYi Micro Hei",
"Droid Sans Fallback",
"WenQuanYi Zen Hei"
};
return fontFallback(fonts);
}

public String zhCNSerifFallback() {
// This fallback list only contains Free and Open Source fonts
String[] fonts = {
"AR PL UMing CN"
};
return fontFallback(fonts);
}

public String zhTWSansFallback() {
// This fallback list only contains Free and Open Source fonts
String[] fonts = {
"WenQuanYi Micro Hei",
"Droid Sans Fallback",
"WenQuanYi Zen Hei"
};
return fontFallback(fonts);
}

public String zhTWSerifFallback() {
// This fallback list only contains Free and Open Source fonts
String[] fonts = {
"AR PL UMing TW"
};
return fontFallback(fonts);
}

public String zhHKSansFallback() {
// This fallback list only contains Free and Open Source fonts
String[] fonts = {
"WenQuanYi Micro Hei",
"Droid Sans Fallback",
"WenQuanYi Zen Hei"
};
return fontFallback(fonts);
}

public String zhHKSerifFallback() {
// This fallback list only contains Free and Open Source fonts
String[] fonts = {
"AR PL UMing HK"
};
return fontFallback(fonts);
}

public String jaSansFallback() {
// This fallback list only contains Free and Open Source fonts
String[] fonts = {
"Droid Sans Japanese",
"WenQuanYi Micro Hei",
"WenQuanYi Zen Hei"
};
return fontFallback(fonts);
}

public String jaSerifFallback() {
// This fallback list only contains Free and Open Source fonts
String[] fonts = {
"AR PL UMing TW"
};
return fontFallback(fonts);
}

public String koSansFallback() {
// This fallback list only contains Free and Open Source fonts
String[] fonts = {
"WenQuanYi Micro Hei",
"Droid Sans Fallback",
"WenQuanYi Zen Hei"
};
return fontFallback(fonts);
}

public String koSerifFallback() {
// This fallback list only contains Free and Open Source fonts
String[] fonts = {
"AR PL UMing TW"
};
return fontFallback(fonts);
}
}
20 changes: 10 additions & 10 deletions src/me/guoyunhe/fontweak/MainWindow.form
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,11 @@
</Constraint>
</Constraints>
</Component>
<Component class="javax.swing.JLabel" name="westLabel">
<Component class="javax.swing.JLabel" name="enLabel">
<Properties>
<Property name="horizontalAlignment" type="int" value="4"/>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="me/guoyunhe/fontweak/i18n/translation.properties" key="WESTERN FONTS" replaceFormat="java.util.ResourceBundle.getBundle(&quot;{bundleNameSlashes}&quot;).getString(&quot;{key}&quot;)"/>
<ResourceString bundle="me/guoyunhe/fontweak/i18n/translation.properties" key="ENGLISH DEFAULT" replaceFormat="java.util.ResourceBundle.getBundle(&quot;{bundleNameSlashes}&quot;).getString(&quot;{key}&quot;)"/>
</Property>
</Properties>
<Constraints>
Expand Down Expand Up @@ -249,7 +249,7 @@
<Properties>
<Property name="horizontalAlignment" type="int" value="4"/>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="me/guoyunhe/fontweak/i18n/translation.properties" key="CHINESE FONTS" replaceFormat="java.util.ResourceBundle.getBundle(&quot;{bundleNameSlashes}&quot;).getString(&quot;{key}&quot;)"/>
<ResourceString bundle="me/guoyunhe/fontweak/i18n/translation.properties" key="CHINESE" replaceFormat="java.util.ResourceBundle.getBundle(&quot;{bundleNameSlashes}&quot;).getString(&quot;{key}&quot;)"/>
</Property>
</Properties>
<Constraints>
Expand Down Expand Up @@ -298,7 +298,7 @@
<Properties>
<Property name="horizontalAlignment" type="int" value="4"/>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="me/guoyunhe/fontweak/i18n/translation.properties" key="JAPANESE FONTS" replaceFormat="java.util.ResourceBundle.getBundle(&quot;{bundleNameSlashes}&quot;).getString(&quot;{key}&quot;)"/>
<ResourceString bundle="me/guoyunhe/fontweak/i18n/translation.properties" key="JAPANESE" replaceFormat="java.util.ResourceBundle.getBundle(&quot;{bundleNameSlashes}&quot;).getString(&quot;{key}&quot;)"/>
</Property>
</Properties>
<Constraints>
Expand All @@ -311,7 +311,7 @@
<Properties>
<Property name="horizontalAlignment" type="int" value="4"/>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="me/guoyunhe/fontweak/i18n/translation.properties" key="KOREAN FONTS" replaceFormat="java.util.ResourceBundle.getBundle(&quot;{bundleNameSlashes}&quot;).getString(&quot;{key}&quot;)"/>
<ResourceString bundle="me/guoyunhe/fontweak/i18n/translation.properties" key="KOREAN" replaceFormat="java.util.ResourceBundle.getBundle(&quot;{bundleNameSlashes}&quot;).getString(&quot;{key}&quot;)"/>
</Property>
</Properties>
<Constraints>
Expand Down Expand Up @@ -396,7 +396,7 @@
<Properties>
<Property name="horizontalAlignment" type="int" value="4"/>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="me/guoyunhe/fontweak/i18n/translation.properties" key="MainWindow.zhCNLabel.text" replaceFormat="java.util.ResourceBundle.getBundle(&quot;{bundleNameSlashes}&quot;).getString(&quot;{key}&quot;)"/>
<ResourceString bundle="me/guoyunhe/fontweak/i18n/translation.properties" key="CHINESE CHINA" replaceFormat="java.util.ResourceBundle.getBundle(&quot;{bundleNameSlashes}&quot;).getString(&quot;{key}&quot;)"/>
</Property>
</Properties>
<Constraints>
Expand All @@ -409,7 +409,7 @@
<Properties>
<Property name="horizontalAlignment" type="int" value="4"/>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="me/guoyunhe/fontweak/i18n/translation.properties" key="MainWindow.zhTWLabel.text" replaceFormat="java.util.ResourceBundle.getBundle(&quot;{bundleNameSlashes}&quot;).getString(&quot;{key}&quot;)"/>
<ResourceString bundle="me/guoyunhe/fontweak/i18n/translation.properties" key="CHINESE TAIWAN" replaceFormat="java.util.ResourceBundle.getBundle(&quot;{bundleNameSlashes}&quot;).getString(&quot;{key}&quot;)"/>
</Property>
</Properties>
<Constraints>
Expand Down Expand Up @@ -816,11 +816,11 @@
<CodeMethod name="add" class="java.awt.Container" parameterTypes="java.awt.Component, java.lang.Object"/>
</StatementProvider>
<Parameters>
<CodeExpression id="24_westLabel">
<CodeVariable name="westLabel" type="8194" declaredType="javax.swing.JLabel"/>
<CodeExpression id="24_enLabel">
<CodeVariable name="enLabel" type="8194" declaredType="javax.swing.JLabel"/>
<ExpressionOrigin>
<ExpressionProvider type="ComponentRef">
<ComponentRef name="westLabel"/>
<ComponentRef name="enLabel"/>
</ExpressionProvider>
</ExpressionOrigin>
</CodeExpression>
Expand Down
Loading

0 comments on commit 64726fa

Please sign in to comment.