Skip to content

Commit

Permalink
Fixed issue with cn1-source-dpi=0.
Browse files Browse the repository at this point in the history
  • Loading branch information
shannah committed Mar 29, 2017
1 parent 11f049a commit 188dffb
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ public void execute() throws BuildException {
String maxMemory = getProject().getProperty("cn1css.max.memory");
if (maxMemory != null) {
javaTask.setMaxmemory("4096m");
} else {
javaTask.setMaxmemory(maxMemory);
}

Argument arg = javaTask.createArg();
Expand Down
16 changes: 15 additions & 1 deletion CN1CSSCompiler/src/com/codename1/ui/css/CSSTheme.java
Original file line number Diff line number Diff line change
Expand Up @@ -1938,14 +1938,28 @@ public Image getBackgroundImage(Map<String,LexicalUnit> styles, ScaledUnit bgIma
int[] dpis = getDpi(encImg);
if (styles.containsKey("cn1-source-dpi")) {
//System.out.println("Using cn1-source-dpi "+styles.get("cn1-source-dpi").getFloatValue());
resm.targetDensity = getDensityForDpi(((ScaledUnit)styles.get("cn1-source-dpi")).getNumericValue());
double densityVal = ((ScaledUnit)styles.get("cn1-source-dpi")).getNumericValue();
if (Math.abs(densityVal) < 0.5) {
resm.targetDensity = 0;
} else {
resm.targetDensity = getDensityForDpi(densityVal);
}
} else if (dpis[0] > 0) {
resm.targetDensity = getImageDensity(encImg);
} else {

resm.targetDensity = getDensityForDpi(bgImage.dpi);
}

if (styles.containsKey("cn1-densities")) {
ScaledUnit densities = (ScaledUnit)styles.get("cn1-densities");
if (densities.getLexicalUnitType() == LexicalUnit.SAC_IDENT && "none".equals(densities.getStringValue())) {
// Not a multi-image
resm.setMultiImage(false);

}
}

//System.out.println("Target density for image is "+resm.targetDensity);

//System.out.println("Loading image from "+url+" with density "+resm.targetDensity);
Expand Down
12 changes: 12 additions & 0 deletions CN1CSSCompiler/src/com/codename1/ui/css/ResourcesMutator.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
* @author shannah
*/
public class ResourcesMutator {
private boolean multiImage = true;
private final EditableResources res;
private Set<Integer> includedDensities = new HashSet<Integer>();
public static final int DEFAULT_TARGET_DENSITY = com.codename1.ui.Display.DENSITY_VERY_HIGH;
Expand Down Expand Up @@ -94,6 +95,9 @@ public com.codename1.ui.EncodedImage storeImage(com.codename1.ui.EncodedImage im

float ratioWidth = 0;
int multiVal = targetDensity;
if (!multiImage) {
multiVal = 0;
}
switch(multiVal) {
// Generate RGB Image
case 0:
Expand Down Expand Up @@ -618,4 +622,12 @@ public void log(String msg) {
System.out.println(msg);
}

public void setMultiImage(boolean mi) {
this.multiImage = mi;
}

public boolean getMultiImage() {
return multiImage;
}

}
Binary file added NowUIKit/css/desktop.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed NowUIKit/src/nowui.css.res
Binary file not shown.
Binary file modified bin/cn1css-ant-task.jar
Binary file not shown.

0 comments on commit 188dffb

Please sign in to comment.