Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
LukeXeon committed Dec 8, 2021
1 parent bcd8953 commit 192689a
Show file tree
Hide file tree
Showing 23 changed files with 264 additions and 73 deletions.
12 changes: 10 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,32 @@ buildscript {
google()
mavenCentral()
jcenter()
maven { url "https://jitpack.io" }
}
dependencies {
classpath "com.android.tools.build:gradle:4.1.1"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
classpath 'com.github.LukeXeon.android-iconfont-pipeline:iconfont-assets:ab8517244c'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
ext {
groupId = 'com.github.LukeXeon'
}
}

allprojects {
repositories {
google()
mavenCentral()
jcenter()
maven { url "https://jitpack.io" }
}
}

task clean(type: Delete) {
delete rootProject.buildDir
}
}


10 changes: 7 additions & 3 deletions iconfont-app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
plugins {
id 'com.android.application'
id 'kotlin-android'
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'open.source.iconfont.assets'

iconfont {
host = 'https://icon-font-assets.oss-cn-beijing.aliyuncs.com'
version = '0.0.1'
}

android {
Expand Down
14 changes: 5 additions & 9 deletions iconfont-app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,15 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:id="@+id/background"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/black"
tools:context=".MainActivity">

<ImageView
android:layout_gravity="center"
app:srcCompat="@xml/icon_font_test"
android:layout_width="100dp"
android:layout_height="100dp"/>
<TextView
android:layout_height="100dp"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!" />

app:srcCompat="@drawable/ref_daka_11" />
</FrameLayout>
21 changes: 19 additions & 2 deletions iconfont-assets/build.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
apply plugin: 'java-gradle-plugin'
apply plugin: 'groovy'
apply plugin: 'maven'
version = '1.0.0'
group = 'open.source.iconfont'
apply plugin: 'maven-publish'

group = rootProject.ext.groupId

java {
sourceCompatibility = JavaVersion.VERSION_1_7
Expand All @@ -14,3 +15,19 @@ dependencies {
implementation 'com.google.code.gson:gson:2.8.6'
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
}

afterEvaluate {
publishing {
publications {
// Creates a Maven publication called "release".
release(MavenPublication) {
from components.java
groupId = rootProject.ext.groupId
artifactId = 'iconfont-assets'
}
}
repositories {
mavenLocal()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@ import retrofit2.converter.gson.GsonConverterFactory

import java.nio.file.Paths
import java.util.concurrent.Callable
import java.util.function.Function

class GenAssetsTask extends DefaultTask {

private final Gson gson

private static final int RETRY_TIME = 10

GenAssetsTask() {
gson = new Gson()
}
Expand Down Expand Up @@ -62,21 +61,15 @@ class GenAssetsTask extends DefaultTask {
))
}

private <T> T fetch(Callable<T> callable) {
int count = 0
def result
while (true) {
if (++count > RETRY_TIME) {
throw new IllegalStateException(project.extensions.iconfont.host + "出问题了,或者version不对")
}
try {
result = callable.call()
} catch (Throwable ignored) {
continue
}
if (result != null) {
break
private static <T> T fetch(Callable<T> callable, Function<Throwable, Throwable> factory) {
def result = null
try {
result = callable.call()
if (result == null) {
throw new NullPointerException()
}
} catch (Throwable e) {
throw factory.apply(e)
}
return result
}
Expand Down Expand Up @@ -121,6 +114,11 @@ class GenAssetsTask extends DefaultTask {
}
return null
}
}, new Function<Throwable, Throwable>() {
@Override
Throwable apply(Throwable throwable) {
return new IllegalStateException(host + "出问题了", throwable)
}
})
def body = tuple.first
def fontUrl = tuple.second
Expand All @@ -136,6 +134,11 @@ class GenAssetsTask extends DefaultTask {
}
return null
}
}, new Function<Throwable, Throwable>() {
@Override
Throwable apply(Throwable throwable) {
return new IllegalStateException("拉取字体文件失败", throwable)
}
})
def fontFile = getTypefaceFile()
if (fontFile.exists()) {
Expand All @@ -148,12 +151,11 @@ class GenAssetsTask extends DefaultTask {
def xmlDir = getXmlDir()
if (xmlDir.exists()) {
xmlDir.deleteDir()
} else {
xmlDir.mkdir()
}
xmlDir.mkdir()
def fontName = getFontName()
for (def item : body.icons) {
def name = toName(item.key)
def name = "ref_" + toName(item.key)
def file = new File(xmlDir, name + ".xml")
file.createNewFile()
def writer = file.newWriter()
Expand All @@ -173,6 +175,8 @@ class GenAssetsTask extends DefaultTask {
def b = (byte) c
if ((b >= 97 && b <= 122) || (b >= 65 && b <= 90)) {
builder.append(c.toLowerCase())
} else if (c.isDigit()) {
builder.append(c)
} else if (i != 0 && i != source.length() - 1) {
builder.append('_')
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package open.source.iconfont.assets.test;

import com.google.gson.Gson;

import java.io.IOException;

import okhttp3.OkHttpClient;
import okhttp3.Request;
import open.source.iconfont.assets.IconFontAssetService;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class Main {
public static void main(String[] args) {
OkHttpClient client = new OkHttpClient();
IconFontAssetService service = new Retrofit.Builder()
.client(client)
.baseUrl("https://icon-font-assets.oss-cn-beijing.aliyuncs.com")
.addConverterFactory(GsonConverterFactory.create(new Gson()))
.build()
.create(IconFontAssetService.class);
try {
System.out.println(service.index("0.0.1").execute().body().icons);
client.newCall(new Request.Builder()
.url("https://icon-font-assets.oss-cn-beijing.aliyuncs.com/icon-font-assets/iconfont.ttf")
.build()).execute();
} catch (IOException e) {
e.printStackTrace();
}
}
}
6 changes: 4 additions & 2 deletions iconfont-export/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
/build
/.idea
/node_modules
yarn.lock
/.idea
/build
1 change: 1 addition & 0 deletions iconfont-export/assets/icons/daka-11.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions iconfont-export/assets/icons/fenxiang-05.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions iconfont-export/assets/icons/sousuo-02.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions iconfont-export/assets/icons/xiaoxi-03.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
73 changes: 73 additions & 0 deletions iconfont-export/gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
const iconfont = require('gulp-iconfont');
const gulp = require('gulp');
const fs = require('fs');
const del = require('del');
const path = require('path');
const argv = require('minimist')(process.argv.slice(2));
const input = argv['input'] || "assets/icons";
const output = argv['output'] || 'build/';
const fontName = argv['font-name'] || 'iconfont';
const version = argv['version'] || '0.0.1';
const outputWithVersion = path.join(output, version);

/* Creates a unicode literal based on the string */
function unicodeLiteral(str) {
function fixedHex(number, length) {
let str = number.toString(16).toUpperCase();
while (str.length < length)
str = "0" + str;
return str;
}

let i;
let result = "";
for (i = 0; i < str.length; ++i) {
/* You should probably replace this by an isASCII test */
if (str.charCodeAt(i) > 126 || str.charCodeAt(i) < 32)
result += fixedHex(str.charCodeAt(i), 4);
else
result += str[i];
}

return result.toLocaleLowerCase();
}

function saveJson(list) {
const icons = {};
for (let e of list) {
icons[e.name] = e.unicode
}
const json = {icons, version, fonts: ["./" + fontName + ".ttf"]};
const exportJson = path.join(outputWithVersion, "export.json");
if (fs.existsSync(exportJson)) {
fs.unlinkSync(exportJson);
}
fs.writeFileSync(exportJson, JSON.stringify(json));
}

gulp.task('clean', async () => {
await del([
path.join(output, '/**/*'),
]);
});

gulp.task('iconfont', () => {
return gulp.src([path.join(input, '*.svg')])
.pipe(iconfont({
fontName: fontName,
formats: ['ttf'],
}))
.on('glyphs', function (glyphs, options) {
// CSS templating, e.g.
saveJson(glyphs.map((e) => {
return {
name: e.name,
unicode: unicodeLiteral(e.unicode[0])
}
}));
//console.log(glyphs, options);
})
.pipe(gulp.dest(outputWithVersion));
});

gulp.task("default", gulp.series("clean", "iconfont"));
18 changes: 9 additions & 9 deletions iconfont-export/package.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
{
"name": "iconfont-export",
"name": "svg2iconfont",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"iconfont": "gulp default"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"del": "^6.0.0",
"gulp": "^4.0.2",
"gulp-filter": "^6.0.0",
"gulp-iconfont": "^11.0.0",
"hasha": "^5.2.2",
"minimist": "^1.2.5",
"xmldom": "^0.4.0"
},
"keywords": [],
"author": "",
"license": "ISC"
"minimist": "^1.2.5"
}
}
13 changes: 7 additions & 6 deletions iconfont/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
plugins {
id 'com.android.library'
id 'kotlin-android'
}
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'com.github.dcendents.android-maven'

group = rootProject.ext.groupId

android {
compileSdkVersion 30
Expand Down Expand Up @@ -33,10 +34,10 @@ android {
}

dependencies {

implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
}

Loading

0 comments on commit 192689a

Please sign in to comment.