Skip to content

Commit

Permalink
Added SVG favicon support
Browse files Browse the repository at this point in the history
  • Loading branch information
M66B committed Jul 12, 2021
1 parent 98e69c1 commit 39e7735
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
1 change: 1 addition & 0 deletions ATTRIBUTION.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ FairEmail uses:
* [POI-HMEF](https://poi.apache.org/components/hmef/index.html). Copyright © 2001-2020 The Apache Software Foundation. [Apache Software License v2](https://poi.apache.org/devel/guidelines.html#The+Licensing).
* [GoSquared's Flag Icon Set](https://github.com/gosquared/flags). Copyright (c) 2017 Go Squared Ltd. [MIT License](https://github.com/gosquared/flags/blob/master/LICENSE.txt).
* [OpenDyslexic](https://github.com/antijingoist/opendyslexic). Copyright (c) 12/2012 - 2019. Copyright (c) 2019-07-29, Abbie Gonzalez. [SIL Open Font License 1.1](https://github.com/antijingoist/opendyslexic/blob/master/OFL.txt).
* [AndroidSVG](https://github.com/BigBadaboom/androidsvg). Copyright 2013 Paul LeBeau, Cave Rock Software Ltd. [Apache License 2.0](https://github.com/BigBadaboom/androidsvg/blob/master/LICENSE).
4 changes: 4 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ dependencies {
def apache_poi = "3.17" // Do not update
def reactivestreams_version = "1.0.3"
def rxjava2_version = "2.2.21"
def svg_version = "1.4"

// https://developer.android.com/jetpack/androidx/releases/startup
implementation "androidx.startup:startup-runtime:$startup_version"
Expand Down Expand Up @@ -483,4 +484,7 @@ dependencies {
// https://mvnrepository.com/artifact/io.reactivex.rxjava2/rxjava
implementation "org.reactivestreams:reactive-streams:$reactivestreams_version"
implementation "io.reactivex.rxjava2:rxjava:$rxjava2_version"

// http://bigbadaboom.github.io/androidsvg/
implementation "com.caverock:androidsvg:$svg_version"
}
1 change: 1 addition & 0 deletions app/src/main/assets/ATTRIBUTION.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ FairEmail uses:
* [POI-HMEF](https://poi.apache.org/components/hmef/index.html). Copyright © 2001-2020 The Apache Software Foundation. [Apache Software License v2](https://poi.apache.org/devel/guidelines.html#The+Licensing).
* [GoSquared's Flag Icon Set](https://github.com/gosquared/flags). Copyright (c) 2017 Go Squared Ltd. [MIT License](https://github.com/gosquared/flags/blob/master/LICENSE.txt).
* [OpenDyslexic](https://github.com/antijingoist/opendyslexic). Copyright (c) 12/2012 - 2019. Copyright (c) 2019-07-29, Abbie Gonzalez. [SIL Open Font License 1.1](https://github.com/antijingoist/opendyslexic/blob/master/OFL.txt).
* [AndroidSVG](https://github.com/BigBadaboom/androidsvg). Copyright 2013 Paul LeBeau, Cave Rock Software Ltd. [Apache License 2.0](https://github.com/BigBadaboom/androidsvg/blob/master/LICENSE).
22 changes: 21 additions & 1 deletion app/src/main/java/eu/faircode/email/ContactInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
import androidx.annotation.NonNull;
import androidx.preference.PreferenceManager;

import com.caverock.androidsvg.SVG;

import org.json.JSONArray;
import org.json.JSONObject;
import org.jsoup.nodes.Document;
Expand Down Expand Up @@ -701,7 +703,25 @@ public boolean verify(String hostname, SSLSession session) {
throw new FileNotFoundException("Error " + status + ":" + connection.getResponseMessage());

if ("image/svg+xml".equals(type) || url.getPath().endsWith(".svg"))
; // Android does not support SVG
try {
SVG svg = SVG.getFromInputStream(connection.getInputStream());
float w = svg.getDocumentWidth();
float h = svg.getDocumentHeight();
if (w < 0 || h < 0) {
w = 1;
h = 1;
}
Bitmap favicon = Bitmap.createBitmap(
scaleToPixels,
Math.round(scaleToPixels * h / w),
Bitmap.Config.ARGB_8888);
favicon.eraseColor(Color.WHITE);
Canvas canvas = new Canvas(favicon);
svg.renderToCanvas(canvas);
return favicon;
} catch (Throwable ex) {
throw new IOException("SVG", ex);
}

Bitmap bitmap = ImageHelper.getScaledBitmap(connection.getInputStream(), url.toString(), scaleToPixels);
if (bitmap == null)
Expand Down

0 comments on commit 39e7735

Please sign in to comment.