Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add FontFilenameProvider #50

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.0'
classpath 'com.android.tools.build:gradle:3.1.0'

// Code checks
classpath 'com.noveogroup.android:check:1.2.2'
Expand All @@ -22,6 +23,7 @@ plugins {
allprojects {
repositories {
jcenter()
google()
}
}

Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Mon Mar 06 12:21:04 EST 2017
#Wed Mar 28 11:18:42 CEST 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
12 changes: 6 additions & 6 deletions library/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 25
buildToolsVersion '25.0.2'
compileSdkVersion 27
buildToolsVersion '27.0.3'

defaultConfig {
minSdkVersion 11
targetSdkVersion 25
minSdkVersion 14
targetSdkVersion 27
}

buildTypes {
Expand All @@ -18,8 +18,8 @@ android {
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-annotations:25.2.0'
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:support-annotations:27.1.0'
}

apply from: new File('../bintray_upload.gradle')
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.pixplicity.sharp;

import android.support.annotation.Nullable;

public interface FontFilenameProvider {
@Nullable
String getFontFilename(String family, String style, String weight);
}
22 changes: 19 additions & 3 deletions library/src/main/java/com/pixplicity/sharp/Sharp.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ public abstract class Sharp {
private OnSvgElementListener mOnElementListener;
private AssetManager mAssetManager;

private FontFilenameProvider mFontFilenameProvider;

enum Unit {
PERCENT("%"),
PT("pt"),
Expand Down Expand Up @@ -292,6 +294,12 @@ public Sharp setOnElementListener(OnSvgElementListener onElementListener) {
return this;
}

@SuppressWarnings("unused")
public Sharp setFontFilenameProvider(FontFilenameProvider fontFilenameProvider) {
mFontFilenameProvider = fontFilenameProvider;
return this;
}

protected abstract InputStream getInputStream() throws IOException;

protected abstract void close(InputStream inputStream) throws IOException;
Expand Down Expand Up @@ -1416,7 +1424,7 @@ private boolean doText(Attributes atts, Properties props, Paint paint) {
if (fontSize != null) {
paint.setTextSize(fontSize);
}
Typeface typeface = setTypeface(atts, props, mSharp.getAssetManager(), paint.getTypeface());
Typeface typeface = setTypeface(atts, props, mSharp.getAssetManager(), paint.getTypeface(), mSharp.mFontFilenameProvider);
if (typeface != null) {
paint.setTypeface(typeface);
}
Expand Down Expand Up @@ -2273,7 +2281,7 @@ private Align getTextAlign(Attributes atts) {
}
}

private Typeface setTypeface(Attributes atts, Properties props, AssetManager assetManager, Typeface defaultTypeface) {
private Typeface setTypeface(Attributes atts, Properties props, AssetManager assetManager, Typeface defaultTypeface, FontFilenameProvider mFontFilenameProvider) {
// Prefer a dedicated attribute
String family = getStringAttr("font-family", atts);
if (family == null) {
Expand Down Expand Up @@ -2316,7 +2324,15 @@ private Typeface setTypeface(Attributes atts, Properties props, AssetManager ass
}
}
// Compose a filename
String typefaceFile = "fonts/" + family + ".ttf";
String typefaceFile = null;
if(mFontFilenameProvider != null) {
typefaceFile = mFontFilenameProvider.getFontFilename(family, style, weight);
}

if(typefaceFile == null) {
typefaceFile = "fonts/" + family + ".ttf";
}

try {
plain = Typeface.createFromAsset(assetManager, typefaceFile);
Log.d(TAG, "loaded typeface from assets: " + typefaceFile);
Expand Down
21 changes: 12 additions & 9 deletions sample-imageview/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ repositories {
}

android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
compileSdkVersion 27
buildToolsVersion '27.0.3'

defaultConfig {
applicationId "com.pixplicity.sharp.imageviewdemo"
minSdkVersion 18
targetSdkVersion 25
versionCode 3
versionName "1.0.2"
targetSdkVersion 27
versionCode 4
versionName "1.1.0"
}
buildTypes {
release {
Expand All @@ -24,10 +24,13 @@ android {
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:25.2.0'
implementation fileTree(dir: 'libs', include: ['*.jar'])

compile 'com.github.chrisbanes.photoview:library:1.2.3'
implementation('com.github.chrisbanes.photoview:library:1.2.3') {
exclude group: 'com.android.support'
}

implementation 'com.android.support:appcompat-v7:27.1.0'

compile project(':library')
implementation project(':library')
}
10 changes: 5 additions & 5 deletions sample-livewallpaper/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
compileSdkVersion 27
buildToolsVersion '27.0.3'

defaultConfig {
applicationId "com.larvalabs.androidify.wallpaper"
minSdkVersion 18
targetSdkVersion 25
targetSdkVersion 27
versionCode 3
versionName "1.0.2"
}
Expand All @@ -20,7 +20,7 @@ android {
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
implementation fileTree(dir: 'libs', include: ['*.jar'])

compile project(':library')
implementation project(':library')
}
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public SharpPicture getSVGForAsset(String path, String name, String suffix, Inte
try {
Sharp sharp = Sharp.loadAsset(assetManager, file);
if (searchColor != null) {
sharp.addColorReplacement(searchColor, replaceColor);
// sharp.addColorReplacement(searchColor, replaceColor);
}
return sharp.getSharpPicture();
} catch (SvgParseException e) {
Expand Down Expand Up @@ -239,7 +239,7 @@ public SharpPicture getSVGForResource(int resource, Integer searchColor, Integer
try {
Sharp sharp = Sharp.loadResource(resources, resource);
if (searchColor != null) {
sharp.addColorReplacement(searchColor, replaceColor);
// sharp.addColorReplacement(searchColor, replaceColor);
}
return sharp.getSharpPicture();
} catch (Exception e) {
Expand Down