Skip to content

Commit

Permalink
FOP-3135: Allow source resolution configuration by João André Gonçalves
Browse files Browse the repository at this point in the history
  • Loading branch information
simonsteiner1984 committed Jul 15, 2024
1 parent 2ee8f32 commit ccfb34f
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 113 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -310,11 +310,7 @@ void checkLoadExternalResource(ParsedURL resourceURL,
/** Returns the Font Family Resolver */
FontFamilyResolver getFontFamilyResolver();

float getTargetResolution();

float getSourceResolution();

void setTargetResolution(float targetResolution);

void setSourceResolution(float sourceResolution);
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ public class UserAgentAdapter implements UserAgent {

private float sourceResolution = 96;

private float targetResolution = UnitConv.IN2PT;

/**
* Sets the BridgeContext to be used for error information.
*/
Expand Down Expand Up @@ -154,7 +152,7 @@ public String getDefaultFontFamily() {
* Returns the medium font size.
*/
public float getMediumFontSize() {
return 9f * UnitConv.IN2MM / (getTargetResolution() * getPixelUnitToMillimeter());
return 9f * UnitConv.IN2MM / (UnitConv.IN2PT * getPixelUnitToMillimeter());
}

/**
Expand Down Expand Up @@ -471,13 +469,7 @@ public FontFamilyResolver getFontFamilyResolver() {

public float getSourceResolution() { return sourceResolution; }

public float getTargetResolution() { return targetResolution; }

public void setSourceResolution(float sourceResolution) {
this.sourceResolution = sourceResolution;
}

public void setTargetResolution(float targetResolution) {
this.targetResolution = targetResolution;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,54 +26,34 @@ Licensed to the Apache Software Foundation (ASF) under one or more
public class UserAgentAdapterTestCase {

@Test
public void testEqualResolution_72() {
checkGetMediumFontSize(72f, 72f, 9f);
public void testMediumFontResolution_72() {
checkGetMediumFontSize(72f, 9f);
}

@Test
public void testEqualResolution_96() {
checkGetMediumFontSize(96f, 96f, 9f);
}

@Test
public void testDiffResolution_72_96() {
checkGetMediumFontSize(72f, 96f, 6.74f);
}

@Test
public void testDiffResolution_96_72() {
checkGetMediumFontSize(96f, 72f, 12f);
public void testMediumFontResolution_96() {
checkGetMediumFontSize(96f, 12f);
}

@Test
public void testPixelMM_72() {
checkGetPixelUnitToMillimeter(72f, 72f);
checkGetPixelUnitToMillimeter(72f);
}

@Test
public void testPixelMM_96() { checkGetPixelUnitToMillimeter(96f, 96f); }

@Test
public void testPixelMM_72_96() { checkGetPixelUnitToMillimeter(72f, 96f); }

@Test
public void testPixelMM_96_72() {
checkGetPixelUnitToMillimeter(96f, 72f);
}
public void testPixelMM_96() { checkGetPixelUnitToMillimeter(96f); }

private void checkGetMediumFontSize(float sourceRes, float targetRes, float expectedSize) {
private void checkGetMediumFontSize(float sourceRes, float expectedSize) {
UserAgentAdapter adapter = new UserAgentAdapter();
adapter.setSourceResolution(sourceRes);
adapter.setTargetResolution(targetRes);

// Size must be calculated based on the dpi settings
assertEquals(expectedSize, adapter.getMediumFontSize(), 0.01);
}

private void checkGetPixelUnitToMillimeter(float sourceRes, float targetRes) {
private void checkGetPixelUnitToMillimeter(float sourceRes) {
UserAgentAdapter adapter = new UserAgentAdapter();
adapter.setSourceResolution(sourceRes);
adapter.setTargetResolution(targetRes);

// Pixel unit to mm must be calculated using the resolution set in the conf
// instead of assuming what the resolution is
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2747,8 +2747,6 @@ protected class UserAgent implements SVGUserAgent {

private float sourceResolution = 96;

private float targetResolution = UnitConv.IN2PT;

/**
* Creates a new SVGUserAgent.
*/
Expand Down Expand Up @@ -2847,7 +2845,7 @@ public String getDefaultFontFamily() {
*/
public float getMediumFontSize() {
// 9pt (72pt == 1in)
return 9f * UnitConv.IN2MM / (getTargetResolution() * getPixelUnitToMillimeter());
return 9f * UnitConv.IN2MM / (UnitConv.IN2PT * getPixelUnitToMillimeter());
}

/**
Expand Down Expand Up @@ -3084,21 +3082,11 @@ public void checkLoadScript(String scriptType,
}
}

@Override
public float getTargetResolution() {
return targetResolution;
}

@Override
public float getSourceResolution() {
return sourceResolution;
}

@Override
public void setTargetResolution(float targetResolution) {
this.targetResolution = targetResolution;
}

@Override
public void setSourceResolution(float sourceResolution) {
this.sourceResolution = sourceResolution;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3102,17 +3102,10 @@ public float getSourceResolution() {
return userAgent.getSourceResolution();
}

public float getTargetResolution() {
return userAgent.getTargetResolution();
}

public void setSourceResolution(float sourceResolution) {
userAgent.setSourceResolution(sourceResolution);
}

public void setTargetResolution(float targetResolution) {
userAgent.setTargetResolution(targetResolution);
}
}

/**
Expand Down Expand Up @@ -3726,17 +3719,9 @@ public float getSourceResolution() {
return svgUserAgent.getSourceResolution();
}

public float getTargetResolution() {
return svgUserAgent.getTargetResolution();
}

public void setSourceResolution(float sourceResolution) {
svgUserAgent.setSourceResolution(sourceResolution);
}

public void setTargetResolution(float targetResolution) {
svgUserAgent.setTargetResolution(targetResolution);
}
}

protected static final Set FEATURES = new HashSet();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,7 @@ void checkLoadScript(String scriptType,
void checkLoadExternalResource(ParsedURL resourceURL,
ParsedURL docURL) throws SecurityException;

float getTargetResolution();

float getSourceResolution();

void setTargetResolution(float targetResolution);

void setSourceResolution(float sourceResolution);
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ public class SVGUserAgentAdapter implements SVGUserAgent {

private float sourceResolution = 96;

private float targetResolution = UnitConv.IN2PT;

public SVGUserAgentAdapter() { }

/**
Expand Down Expand Up @@ -136,7 +134,7 @@ public String getDefaultFontFamily() {
* Returns the medium font size.
*/
public float getMediumFontSize() {
return 9f * UnitConv.IN2MM / (getTargetResolution() * getPixelUnitToMillimeter());
return 9f * UnitConv.IN2MM / (UnitConv.IN2PT * getPixelUnitToMillimeter());
}

/**
Expand Down Expand Up @@ -360,15 +358,7 @@ public float getSourceResolution() {
return sourceResolution;
}

public float getTargetResolution() {
return targetResolution;
}

public void setSourceResolution(float sourceResolution) {
this.sourceResolution = sourceResolution;
}

public void setTargetResolution(float targetResolution) {
this.targetResolution = targetResolution;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,54 +26,34 @@ Licensed to the Apache Software Foundation (ASF) under one or more
public class SVGUserAgentAdapterTestCase {

@Test
public void testEqualResolution_72() {
checkGetMediumFontSize(72f, 72f, 9f);
public void testMediumFontResolution_72() {
checkGetMediumFontSize(72f, 9f);
}

@Test
public void testEqualResolution_96() {
checkGetMediumFontSize(96f, 96f, 9f);
public void testMediumFontResolution_96() {
checkGetMediumFontSize(96f, 12f);
}

@Test
public void testDiffResolution_72_96() {
checkGetMediumFontSize(72f, 96f, 6.74f);
}

@Test
public void testDiffResolution_96_72() {
checkGetMediumFontSize(96f, 72f, 12f);
}

@Test
public void testPixelMM_72() {
checkGetPixelUnitToMillimeter(72f, 72f);
}

@Test
public void testPixelMM_96() { checkGetPixelUnitToMillimeter(96f, 96f); }

@Test
public void testPixelMM_72_96() { checkGetPixelUnitToMillimeter(72f, 96f); }
public void testPixelMM_72() { checkGetPixelUnitToMillimeter(72f); }

@Test
public void testPixelMM_96_72() {
checkGetPixelUnitToMillimeter(96f, 72f);
public void testPixelMM_96() {
checkGetPixelUnitToMillimeter(96f);
}

private void checkGetMediumFontSize(float sourceRes, float targetRes, float expectedSize) {
private void checkGetMediumFontSize(float sourceRes, float expectedSize) {
SVGUserAgentAdapter adapter = new SVGUserAgentAdapter();
adapter.setSourceResolution(sourceRes);
adapter.setTargetResolution(targetRes);

// Size must be calculated based on the dpi settings
assertEquals(expectedSize, adapter.getMediumFontSize(), 0.01);
}

private void checkGetPixelUnitToMillimeter(float sourceRes, float targetRes) {
private void checkGetPixelUnitToMillimeter(float sourceRes) {
SVGUserAgentAdapter adapter = new SVGUserAgentAdapter();
adapter.setSourceResolution(sourceRes);
adapter.setTargetResolution(targetRes);

// Pixel unit to mm must be calculated using the resolution set in the conf
// instead of assuming what the resolution is
Expand Down

0 comments on commit ccfb34f

Please sign in to comment.