mirror of
https://github.com/viq/NewsBlur.git
synced 2025-09-18 21:43:31 +00:00
Add Noto web font
This commit is contained in:
parent
eadb43efec
commit
7e2ec25df7
3 changed files with 44 additions and 28 deletions
|
@ -372,16 +372,19 @@
|
|||
<string name="whitney_font">Whitney</string>
|
||||
<string name="gotham_narrow_font">Gotham Narrow</string>
|
||||
<string name="chronicle_font">Chronicle</string>
|
||||
<string name="noto_font">Noto</string>
|
||||
<string-array name="default_font_entries">
|
||||
<item>@string/chronicle_font</item>
|
||||
<item>@string/default_font</item>
|
||||
<item>@string/gotham_narrow_font</item>
|
||||
<item>@string/noto_font</item>
|
||||
<item>@string/whitney_font</item>
|
||||
</string-array>
|
||||
<string-array name="default_font_values">
|
||||
<item>CHRONICLE</item>
|
||||
<item>DEFAULT</item>
|
||||
<item>GOTHAM_NARROW</item>
|
||||
<item>NOTO</item>
|
||||
<item>WHITNEY</item>
|
||||
</string-array>
|
||||
<string name="default_font_value">DEFAULT</string>
|
||||
|
|
|
@ -43,7 +43,6 @@ import com.newsblur.domain.UserDetails;
|
|||
import com.newsblur.service.NBSyncService;
|
||||
import com.newsblur.util.DefaultFeedView;
|
||||
import com.newsblur.util.FeedUtils;
|
||||
import com.newsblur.util.FileCache;
|
||||
import com.newsblur.util.Font;
|
||||
import com.newsblur.util.PrefsUtils;
|
||||
import com.newsblur.util.StoryUtils;
|
||||
|
@ -544,16 +543,10 @@ public class ReadingItemFragment extends NbFragment implements ClassifierDialogF
|
|||
|
||||
float currentSize = PrefsUtils.getTextSize(getActivity());
|
||||
Font font = PrefsUtils.getFont(getActivity());
|
||||
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("<html><head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=0\" />");
|
||||
builder.append("<style style=\"text/css\">");
|
||||
builder.append(font.getFontFace());
|
||||
builder.append(String.format("body { font-size: %sem;", Float.toString(currentSize)));
|
||||
if (font.isUserSelected()) {
|
||||
builder.append("font-family: 'SelectedFont';");
|
||||
}
|
||||
builder.append("} </style>");
|
||||
builder.append(font.forWebView(currentSize));
|
||||
builder.append("<link rel=\"stylesheet\" type=\"text/css\" href=\"reading.css\" />");
|
||||
if (PrefsUtils.isLightThemeSelected(getActivity())) {
|
||||
builder.append("<link rel=\"stylesheet\" type=\"text/css\" href=\"light_reading.css\" />");
|
||||
|
|
|
@ -6,19 +6,26 @@ package com.newsblur.util;
|
|||
|
||||
public class Font {
|
||||
|
||||
public static Font CHRONICLE = new Font("ChronicleSSm-Book.otf");
|
||||
public static Font DEFAULT = new Font(null);
|
||||
public static Font GOTHAM_NARROW = new Font("GothamNarrow-Book.otf");
|
||||
public static Font WHITNEY = new Font("WhitneySSm-Book-Bas.otf");
|
||||
public static Font CHRONICLE = new Font(Type.OTF, "ChronicleSSm-Book.otf", "'SelectedFont'");
|
||||
public static Font DEFAULT = new Font(Type.DEFAULT, null, null);
|
||||
public static Font GOTHAM_NARROW = new Font(Type.OTF, "GothamNarrow-Book.otf", "'SelectedFont'");
|
||||
public static Font WHITNEY = new Font(Type.OTF, "WhitneySSm-Book-Bas.otf", "'SelectedFont'");
|
||||
public static Font NOTO = new Font(Type.WEB, "https://fonts.googleapis.com/css?family=Noto+Sans", "'Noto Sans', sans-serif");
|
||||
|
||||
private String bookFile;
|
||||
|
||||
private Font(String bookFile) {
|
||||
this.bookFile = bookFile;
|
||||
private enum Type {
|
||||
OTF,
|
||||
WEB,
|
||||
DEFAULT
|
||||
}
|
||||
|
||||
public boolean isUserSelected() {
|
||||
return bookFile != null;
|
||||
private Type type;
|
||||
private String resource;
|
||||
private String fontFamily;
|
||||
|
||||
private Font(Type type, String resource, String fontFamily) {
|
||||
this.type = type;
|
||||
this.resource = resource;
|
||||
this.fontFamily = fontFamily;
|
||||
}
|
||||
|
||||
public static Font getFont(String preferenceValue) {
|
||||
|
@ -29,20 +36,33 @@ public class Font {
|
|||
return GOTHAM_NARROW;
|
||||
case "WHITNEY":
|
||||
return WHITNEY;
|
||||
case "NOTO":
|
||||
return NOTO;
|
||||
default:
|
||||
return DEFAULT;
|
||||
}
|
||||
}
|
||||
|
||||
public String getFontFace() {
|
||||
if (isUserSelected()) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("@font-face { font-family: 'SelectedFont'; src: url(\"file:///android_asset/fonts/");
|
||||
builder.append(bookFile);
|
||||
builder.append("\") }\n");
|
||||
return builder.toString();
|
||||
} else {
|
||||
return "";
|
||||
public String forWebView(float currentSize) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
if (type == Type.WEB) {
|
||||
builder.append("<link href=\"");
|
||||
builder.append(resource);
|
||||
builder.append("\" rel=\"stylesheet\">");
|
||||
}
|
||||
builder.append("<style style=\"text/css\">");
|
||||
if (type == Type.OTF) {
|
||||
builder.append("@font-face { font-family: 'SelectedFont'; src: url(\"file:///android_asset/fonts/");
|
||||
builder.append(resource);
|
||||
builder.append("\") }\n");
|
||||
}
|
||||
builder.append(String.format("body { font-size: %sem;", Float.toString(currentSize)));
|
||||
if (type != Type.DEFAULT) {
|
||||
builder.append("font-family: ");
|
||||
builder.append(fontFamily);
|
||||
builder.append(";");
|
||||
}
|
||||
builder.append("} </style>");
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue