Skip to content

Commit

Permalink
Attempt to fix TextPaint inconsistencies.
Browse files Browse the repository at this point in the history
Changes:
1. Added support for computing dimensions based on correct, passed-in
TextPaint.
2. Removed tests to simplify things.
3. Added Bazel support.
4. Remove Android Q functionality.
  • Loading branch information
BenHenning committed Mar 16, 2021
1 parent 1d43f77 commit 871dfa1
Show file tree
Hide file tree
Showing 26 changed files with 269 additions and 3,686 deletions.
15 changes: 15 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

RULES_JVM_EXTERNAL_TAG = "2.4"
RULES_JVM_EXTERNAL_SHA = "2393f002b0a274055a4e803801cd078df90d1a8ac9f15748d1f803b97cfcdc9c"

http_archive(
name = "rules_jvm_external",
strip_prefix = "rules_jvm_external-%s" % RULES_JVM_EXTERNAL_TAG,
sha256 = RULES_JVM_EXTERNAL_SHA,
url = "https://github.com/bazelbuild/rules_jvm_external/archive/%s.zip" % RULES_JVM_EXTERNAL_TAG,
)

android_sdk_repository(
name = "androidsdk",
)
11 changes: 11 additions & 0 deletions androidsvg/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
load("@rules_jvm_external//:defs.bzl", "artifact")

android_library(
name = "androidsvg",
custom_package = "com.caverock.androidsvg",
srcs = glob(["src/main/java/**/*.java"]),
resource_files = glob(["src/main/res/**"]),
manifest = "src/main/AndroidManifest.xml",
exports_manifest = True,
visibility = ["//visibility:public"],
)
202 changes: 101 additions & 101 deletions androidsvg/publish.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,103 +31,103 @@ def releaseRepoUrl = "https://oss.sonatype.org/service/local/staging/deploy/mav
def snapshotRepoUrl = "https://oss.sonatype.org/content/repositories/snapshots/"


publishing {
repositories {
maven {
url = version.endsWith('SNAPSHOT') ? snapshotRepoUrl : releaseRepoUrl
credentials {
// These are set in ~/.gradle/gradle.properties
username project.sonatypeUsername
password project.sonatypePassword
}
}
}

publications {

mavenAAR(MavenPublication) {
artifactId = artifactIdAAR
groupId = group

artifact("${buildDir}/outputs/aar/androidsvg-release.aar") {
// wrap in a closure because this task isn't defined 'till
// the android plugin finishes
builtBy { tasks["assembleRelease"] }
}
afterEvaluate {
artifact sourcesJar
artifact javadocJar
}

pom {
packaging = 'aar'

name = libraryName
description = libraryDescription
url = siteUrl

licenses {
license {
name = licenseName
url = licenseUrl
distribution = 'repo'
}
}
developers {
developer {
id = developerId
name = developerName
email = developerEmail
}
}
scm {
connection = gitUrl
developerConnection = gitUrl
url = siteUrl
}
}
}

mavenJAR(MavenPublication) {
artifactId = artifactIdJAR
groupId = group

afterEvaluate {
artifact libraryJar
artifact sourcesJar
artifact javadocJar
}

pom {
packaging = 'jar'

name = libraryName
description = libraryDescription
url = siteUrl

licenses {
license {
name = licenseName
url = licenseUrl
distribution = 'repo'
}
}
developers {
developer {
id = developerId
name = developerName
email = developerEmail
}
}
scm {
connection = gitUrl
developerConnection = gitUrl
url = siteUrl
}
}
}
}
}
//publishing {
// repositories {
// maven {
// url = version.endsWith('SNAPSHOT') ? snapshotRepoUrl : releaseRepoUrl
// credentials {
// // These are set in ~/.gradle/gradle.properties
// username project.sonatypeUsername
// password project.sonatypePassword
// }
// }
// }
//
// publications {
//
// mavenAAR(MavenPublication) {
// artifactId = artifactIdAAR
// groupId = group
//
// artifact("${buildDir}/outputs/aar/androidsvg-release.aar") {
// // wrap in a closure because this task isn't defined 'till
// // the android plugin finishes
// builtBy { tasks["assembleRelease"] }
// }
// afterEvaluate {
// artifact sourcesJar
// artifact javadocJar
// }
//
// pom {
// packaging = 'aar'
//
// name = libraryName
// description = libraryDescription
// url = siteUrl
//
// licenses {
// license {
// name = licenseName
// url = licenseUrl
// distribution = 'repo'
// }
// }
// developers {
// developer {
// id = developerId
// name = developerName
// email = developerEmail
// }
// }
// scm {
// connection = gitUrl
// developerConnection = gitUrl
// url = siteUrl
// }
// }
// }
//
// mavenJAR(MavenPublication) {
// artifactId = artifactIdJAR
// groupId = group
//
// afterEvaluate {
// artifact libraryJar
// artifact sourcesJar
// artifact javadocJar
// }
//
// pom {
// packaging = 'jar'
//
// name = libraryName
// description = libraryDescription
// url = siteUrl
//
// licenses {
// license {
// name = licenseName
// url = licenseUrl
// distribution = 'repo'
// }
// }
// developers {
// developer {
// id = developerId
// name = developerName
// email = developerEmail
// }
// }
// scm {
// connection = gitUrl
// developerConnection = gitUrl
// url = siteUrl
// }
// }
// }
// }
//}


task sourcesJar(type: Jar) {
Expand Down Expand Up @@ -170,7 +170,7 @@ task libraryJar(type: Jar, dependsOn: 'compileReleaseJavaWithJavac') {
archiveName "${artifactIdJAR}-${version}.jar"
}

signing {
sign publishing.publications.mavenAAR
sign publishing.publications.mavenJAR
}
//signing {
// sign publishing.publications.mavenAAR
// sign publishing.publications.mavenJAR
//}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/**
* The PreserveAspectRatio class tells the renderer how to scale and position the
Expand Down Expand Up @@ -276,8 +277,10 @@ public String toString()
return alignment + " " + scale;
}



@Override
public int hashCode() {
return Objects.hash(alignment, scale);
}

private static PreserveAspectRatio parsePreserveAspectRatio(String val) throws SVGParseException
{
Expand Down
13 changes: 7 additions & 6 deletions androidsvg/src/main/java/com/caverock/androidsvg/SVG.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import android.graphics.Picture;
import android.graphics.RectF;

import com.caverock.androidsvg.utils.RenderOptionsBase;
import com.caverock.androidsvg.utils.SVGBase;

import java.io.IOException;
Expand Down Expand Up @@ -563,9 +564,9 @@ public Set<String> getViewList()
* @throws IllegalArgumentException if there is no current SVG document loaded.
*/
@SuppressWarnings({"WeakerAccess", "unused"})
public float getDocumentWidth()
public float getDocumentWidth(RenderOptionsBase options)
{
return base.getDocumentWidth();
return base.getDocumentWidth(options);
}


Expand Down Expand Up @@ -611,9 +612,9 @@ public void setDocumentWidth(String value) throws SVGParseException
* @throws IllegalArgumentException if there is no current SVG document loaded.
*/
@SuppressWarnings({"WeakerAccess", "unused"})
public float getDocumentHeight()
public float getDocumentHeight(RenderOptionsBase options)
{
return base.getDocumentWidth();
return base.getDocumentHeight(options);
}


Expand Down Expand Up @@ -726,9 +727,9 @@ public PreserveAspectRatio getDocumentPreserveAspectRatio()
* @throws IllegalArgumentException if there is no current SVG document loaded.
*/
@SuppressWarnings({"WeakerAccess", "unused"})
public float getDocumentAspectRatio()
public float getDocumentAspectRatio(RenderOptionsBase options)
{
return base.getDocumentAspectRatio();
return base.getDocumentAspectRatio(options);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import android.util.Log;

import com.caverock.androidsvg.BuildConfig;
//import com.caverock.androidsvg.BuildConfig;
import com.caverock.androidsvg.SVGExternalFileResolver;
import com.caverock.androidsvg.utils.SVGBase.SvgContainer;
import com.caverock.androidsvg.utils.SVGBase.SvgElementBase;
Expand Down Expand Up @@ -580,8 +580,8 @@ private Ruleset parseRuleset(CSSTextScanner scan)
catch (CSSParseException e)
{
Log.e(TAG, "CSS parser terminated early due to error: " + e.getMessage());
if (BuildConfig.DEBUG)
Log.e(TAG,"Stacktrace:", e);
// if (BuildConfig.DEBUG)
// Log.e(TAG,"Stacktrace:", e);
}
return ruleset;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.caverock.androidsvg.utils;

import android.graphics.Canvas;
import android.text.TextPaint;

import com.caverock.androidsvg.PreserveAspectRatio;
import com.caverock.androidsvg.RenderOptions;
Expand Down Expand Up @@ -49,6 +50,7 @@ public class RenderOptionsBase
SVGBase.Box viewBox = null;
String viewId = null;
SVGBase.Box viewPort = null;
TextPaint textPaint = null;


/**
Expand Down Expand Up @@ -85,6 +87,7 @@ public RenderOptionsBase(RenderOptionsBase other)
this.viewId = other.viewId;
this.viewPort = other.viewPort;
this.targetId = other.targetId;
this.textPaint = other.textPaint;
}

/**
Expand Down Expand Up @@ -242,5 +245,23 @@ public boolean hasTarget()
return this.targetId != null;
}

/**
* Updates this {@link RenderOptions} instance to include the specified {@link TextPaint}.
*
* @return this same <code>RenderOptions</code> instance
*/
public RenderOptionsBase textPaint(TextPaint textPaint)
{
this.textPaint = textPaint;
return this;
}

/**
* Returns whether this {@link RenderOptions} instance has a {@link TextPaint} set via {@link
* #textPaint(TextPaint)}.
*/
public boolean hasTextPaint()
{
return textPaint != null;
}
}
Loading

0 comments on commit 871dfa1

Please sign in to comment.