Skip to content

Commit 1f107a8

Browse files
committed
Added additional coverage and refined code
1 parent 7cf227a commit 1f107a8

File tree

12 files changed

+189
-30
lines changed

12 files changed

+189
-30
lines changed

CodenameOne/src/com/codename1/ui/Display.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2698,8 +2698,6 @@ public int convertToPixels(float value, byte unitType) {
26982698
* @since 8.0
26992699
*/
27002700
public int convertToPixels(float value, byte unitType, boolean horizontal) {
2701-
2702-
27032701
switch (unitType) {
27042702
case Style.UNIT_TYPE_REM:
27052703
return Math.round(value * Font.getDefaultFont().getHeight());

CodenameOne/src/com/codename1/ui/Graphics.java

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,9 +1091,9 @@ void drawImageArea(Image img, int x, int y, int imageX, int imageY, int imageWid
10911091
* Draws a closed polygon defined by arrays of x and y coordinates.
10921092
* Each pair of (x, y) coordinates defines a point.
10931093
*
1094-
* @param xPoints - a an array of x coordinates.
1095-
* @param yPoints - a an array of y coordinates.
1096-
* @param nPoints - a the total number of points.
1094+
* @param xPoints - an array of x coordinates.
1095+
* @param yPoints - an array of y coordinates.
1096+
* @param nPoints - the total number of points.
10971097
*/
10981098
public void drawPolygon(int[] xPoints, int[] yPoints, int nPoints) {
10991099
int[] cX = xPoints;
@@ -1151,7 +1151,7 @@ public int concatenateAlpha(int a) {
11511151
}
11521152

11531153
/**
1154-
* Returnes the alpha as a value between 0-255 (0 - 0xff) where 255 is completely opaque
1154+
* Returns the alpha as a value between 0-255 (0 - 0xff) where 255 is completely opaque
11551155
* and 0 is completely transparent
11561156
*
11571157
* @return the alpha value
@@ -1171,59 +1171,59 @@ public void setAlpha(int a) {
11711171
}
11721172

11731173
/**
1174-
* Returns true if anti-aliasing for standard rendering operations is supported,
1175-
* notice that text anti-aliasing is a separate attribute.
1174+
* Returns true if antialiasing for standard rendering operations is supported,
1175+
* notice that text antialiasing is a separate attribute.
11761176
*
1177-
* @return true if anti aliasing is supported
1177+
* @return true if antialiasing is supported
11781178
*/
11791179
public boolean isAntiAliasingSupported() {
11801180
return impl.isAntiAliasingSupported(nativeGraphics);
11811181
}
11821182

11831183
/**
1184-
* Returns true if anti-aliasing for text is supported,
1185-
* notice that text anti-aliasing is a separate attribute from standard anti-alisaing.
1184+
* Returns true if antialiasing for text is supported,
1185+
* notice that text antialiasing is a separate attribute from standard anti-alisaing.
11861186
*
1187-
* @return true if text anti aliasing is supported
1187+
* @return true if text antialiasing is supported
11881188
*/
11891189
public boolean isAntiAliasedTextSupported() {
11901190
return impl.isAntiAliasedTextSupported(nativeGraphics);
11911191
}
11921192

11931193

11941194
/**
1195-
* Returns true if anti-aliasing for standard rendering operations is turned on.
1195+
* Returns true if antialiasing for standard rendering operations is turned on.
11961196
*
1197-
* @return true if anti aliasing is active
1197+
* @return true if antialiasing is active
11981198
*/
11991199
public boolean isAntiAliased() {
12001200
return impl.isAntiAliased(nativeGraphics);
12011201
}
12021202

12031203
/**
1204-
* Set whether anti-aliasing for standard rendering operations is turned on.
1204+
* Set whether antialiasing for standard rendering operations is turned on.
12051205
*
1206-
* @param a true if anti aliasing is active
1206+
* @param a true if antialiasing is active
12071207
*/
12081208
public void setAntiAliased(boolean a) {
12091209
impl.setAntiAliased(nativeGraphics, a);
12101210
}
12111211

12121212
/**
1213-
* Indicates whether anti-aliasing for text is active,
1214-
* notice that text anti-aliasing is a separate attribute from standard anti-alisaing.
1213+
* Indicates whether antialiasing for text is active,
1214+
* notice that text antialiasing is a separate attribute from standard anti-alisaing.
12151215
*
1216-
* @return true if text anti aliasing is supported
1216+
* @return true if text antialiasing is supported
12171217
*/
12181218
public boolean isAntiAliasedText() {
12191219
return impl.isAntiAliasedText(nativeGraphics);
12201220
}
12211221

12221222
/**
1223-
* Set whether anti-aliasing for text is active,
1224-
* notice that text anti-aliasing is a separate attribute from standard anti-alisaing.
1223+
* Set whether antialiasing for text is active,
1224+
* notice that text antialiasing is a separate attribute from standard anti-alisaing.
12251225
*
1226-
* @param a true if text anti aliasing is supported
1226+
* @param a true if text antialiasing is supported
12271227
*/
12281228
public void setAntiAliasedText(boolean a) {
12291229
impl.setAntiAliasedText(nativeGraphics, a);

CodenameOne/src/com/codename1/ui/Image.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ public static Image exifRotation(String capturedImage, String rotatedImage, int
392392
boolean isJpeg = isJPEG(fss.openInputStream(capturedImage));
393393
boolean isPNG = isPNG(fss.openInputStream(capturedImage));
394394
String format;
395-
// IMPORTANT: we cannot relies on the file extension of the capturedImage path,
395+
// IMPORTANT: we cannot rely on the file extension of the capturedImage path,
396396
// because some Android devices return images from the gallery without extension!
397397
if (!isJpeg && !isPNG) {
398398
// Only jpeg and png images are supported, but some devices can return also different formats from the gallery (like gif).
@@ -472,7 +472,7 @@ public static Image exifRotation(String capturedImage, String rotatedImage, int
472472

473473
/**
474474
* <p>
475-
* Gets the EXIF orientation tag of an image, if it's available.</p>
475+
* Gets the EXIF orientation tag of an image if it's available.</p>
476476
* <p>
477477
* The Exif Orientation Tag is a number from 0 to 8, for the explanation of
478478
* each value see the

scripts/android/tests/ProcessScreenshots.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -350,9 +350,6 @@ private static PNGImage loadPng(Path path) throws IOException {
350350
byte[] type = java.util.Arrays.copyOfRange(data, offset + 4, offset + 8);
351351
offset += 8;
352352
if (offset + length + 4 > data.length) {
353-
System.out.println("Error processing PNG chunk of length: " + length +
354-
" with data length of: " + data.length +
355-
"\nTotal chunks: " + idatChunks);
356353
throw new IOException("PNG chunk truncated before CRC while processing: " + path);
357354
}
358355
byte[] chunkData = java.util.Arrays.copyOfRange(data, offset, offset + length);

scripts/hellocodenameone/common/src/main/java/com/codenameone/examples/hellocodenameone/tests/AbstractGraphicsScreenshotTest.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.codenameone.examples.hellocodenameone.tests;
22

3+
import com.codename1.ui.CN;
34
import com.codename1.ui.Component;
45
import com.codename1.ui.Font;
56
import com.codename1.ui.Form;
@@ -12,14 +13,18 @@
1213
public abstract class AbstractGraphicsScreenshotTest extends BaseTest {
1314
private final int[] colorSet = {0xff0000, 0xff00, 0xff, 0xffffff};
1415
private int currentColor = -1;
16+
private int factor = 0;
1517

1618
protected void nextColor(Graphics g) {
17-
if (currentColor == -1) {
19+
if(factor == 0) {
20+
factor = CN.getDisplayWidth() < 400 ? 5 : 1;
21+
}
22+
if(currentColor == -1) {
1823
currentColor = 0;
1924
g.setColor(colorSet[0]);
2025
}
2126
g.darkerColor(1);
22-
if (g.getColor() == 0) {
27+
if(g.getColor() == 0) {
2328
currentColor++;
2429
if (currentColor == colorSet.length) {
2530
currentColor = 0;

scripts/hellocodenameone/common/src/main/java/com/codenameone/examples/hellocodenameone/tests/Cn1ssDeviceRunner.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,20 @@
77
import com.codename1.ui.Display;
88
import com.codename1.ui.Form;
99
import com.codename1.util.StringUtil;
10+
import com.codenameone.examples.hellocodenameone.tests.graphics.AffineScale;
1011
import com.codenameone.examples.hellocodenameone.tests.graphics.DrawArc;
12+
import com.codenameone.examples.hellocodenameone.tests.graphics.DrawGradient;
1113
import com.codenameone.examples.hellocodenameone.tests.graphics.DrawImage;
1214
import com.codenameone.examples.hellocodenameone.tests.graphics.DrawLine;
1315
import com.codenameone.examples.hellocodenameone.tests.graphics.DrawRect;
1416
import com.codenameone.examples.hellocodenameone.tests.graphics.DrawRoundRect;
1517
import com.codenameone.examples.hellocodenameone.tests.graphics.DrawString;
1618
import com.codenameone.examples.hellocodenameone.tests.graphics.DrawStringDecorated;
1719
import com.codenameone.examples.hellocodenameone.tests.graphics.FillArc;
20+
import com.codenameone.examples.hellocodenameone.tests.graphics.FillPolygon;
1821
import com.codenameone.examples.hellocodenameone.tests.graphics.FillRect;
1922
import com.codenameone.examples.hellocodenameone.tests.graphics.FillRoundRect;
23+
import com.codenameone.examples.hellocodenameone.tests.graphics.Scale;
2024

2125
public final class Cn1ssDeviceRunner extends DeviceRunner {
2226
private static final BaseTest[] TEST_CLASSES = new BaseTest[] {
@@ -31,6 +35,10 @@ public final class Cn1ssDeviceRunner extends DeviceRunner {
3135
new DrawString(),
3236
new DrawImage(),
3337
new DrawStringDecorated(),
38+
new DrawGradient(),
39+
new FillPolygon(),
40+
new AffineScale(),
41+
new Scale(),
3442
new BrowserComponentScreenshotTest(),
3543
new MediaPlaybackScreenshotTest()
3644
};
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.codenameone.examples.hellocodenameone.tests.graphics;
2+
3+
import com.codename1.ui.Graphics;
4+
import com.codename1.ui.Transform;
5+
import com.codename1.ui.geom.AffineTransform;
6+
import com.codename1.ui.geom.Rectangle;
7+
import com.codenameone.examples.hellocodenameone.tests.AbstractGraphicsScreenshotTest;
8+
9+
public class AffineScale extends AbstractGraphicsScreenshotTest {
10+
11+
@Override
12+
protected void drawContent(Graphics g, Rectangle bounds) {
13+
if(!g.isAffineSupported()) {
14+
g.drawString("Affine unsupported", 0, 0);
15+
return;
16+
}
17+
18+
float xScale = 0.01f * ((float)bounds.getHeight());
19+
float yScale = 0.01f * ((float)bounds.getWidth());
20+
AffineTransform affine = new AffineTransform();
21+
affine.setToScale(xScale, yScale);
22+
Transform transform = affine.toTransform();
23+
int translateX = (int)(bounds.getX() / xScale);
24+
int translateY = (int)(bounds.getY() / yScale);
25+
transform.translate(translateX, translateY);
26+
g.setTransform(transform);
27+
g.fillLinearGradient(0xff0000, 0xff, 0, 0, 100, 100, true);
28+
29+
transform.scale(-1, 1);
30+
g.fillLinearGradient(0xff0000, 0xff, 100, 100, 100, 100, true);
31+
g.resetAffine();
32+
}
33+
34+
@Override
35+
protected String screenshotName() {
36+
return "graphics-affine-scale";
37+
}
38+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.codenameone.examples.hellocodenameone.tests.graphics;
2+
3+
import com.codename1.ui.EncodedImage;
4+
import com.codename1.ui.FontImage;
5+
import com.codename1.ui.Graphics;
6+
import com.codename1.ui.Image;
7+
import com.codename1.ui.RGBImage;
8+
import com.codename1.ui.geom.Rectangle;
9+
import com.codenameone.examples.hellocodenameone.tests.AbstractGraphicsScreenshotTest;
10+
11+
public class DrawGradient extends AbstractGraphicsScreenshotTest {
12+
13+
@Override
14+
protected void drawContent(Graphics g, Rectangle bounds) {
15+
int height = bounds.getHeight() / 3;
16+
int width = bounds.getWidth() / 2;
17+
int y = bounds.getY();
18+
g.fillRadialGradient(0xff, 0xff00, bounds.getX(), y, width, height);
19+
g.fillRadialGradient(0xff, 0xff00, bounds.getX() + width, y, width, height,20, 200);
20+
y += height;
21+
22+
g.fillRectRadialGradient(0xff0000, 0xcccccc, bounds.getX() + width, y, width, height,0.5f, 0.5f, 2);
23+
g.fillLinearGradient(0xff, 0x999999, bounds.getX(), y, width, height, true);
24+
y += height;
25+
26+
g.fillLinearGradient(0xff, 0x999999, bounds.getX(), y, width, height, false);
27+
}
28+
29+
@Override
30+
protected String screenshotName() {
31+
return "graphics-draw-gradient";
32+
}
33+
}

scripts/hellocodenameone/common/src/main/java/com/codenameone/examples/hellocodenameone/tests/graphics/DrawImage.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.codenameone.examples.hellocodenameone.tests.graphics;
22

33
import com.codename1.ui.EncodedImage;
4+
import com.codename1.ui.FontImage;
45
import com.codename1.ui.Graphics;
56
import com.codename1.ui.Image;
67
import com.codename1.ui.RGBImage;
@@ -14,10 +15,12 @@ public class DrawImage extends AbstractGraphicsScreenshotTest {
1415
private RGBImage rgbImage;
1516
private Image fromRgba;
1617
private Image fromBytes;
18+
private FontImage fontImage;
19+
private Image scaled;
1720

1821
@Override
1922
protected void drawContent(Graphics g, Rectangle bounds) {
20-
int size = bounds.getWidth() / 3;
23+
int size = bounds.getWidth() / 4;
2124
if(mutable == null) {
2225
mutable = Image.createImage(size, size);
2326
Graphics mg = mutable.getGraphics();
@@ -30,6 +33,8 @@ protected void drawContent(Graphics g, Rectangle bounds) {
3033
rgbImage = new RGBImage(mutable);
3134
fromRgba = Image.createImage(rgbImage.getRGB(), size, size);
3235
fromBytes = Image.createImage(encoded.getImageData(), 0, encoded.getImageData().length);
36+
fontImage = FontImage.createFixed("" + FontImage.MATERIAL_ALARM_ON, FontImage.getMaterialDesignFont(), 0xff0000, size, size, 2);
37+
scaled = mutable.scaled(size * 2, size * 2).scaled(size, size);
3338
}
3439
int yBound = bounds.getY();
3540
g.drawImage(mutable, bounds.getX(), yBound);
@@ -39,10 +44,13 @@ protected void drawContent(Graphics g, Rectangle bounds) {
3944
g.drawImage(mutableWithAlpha, bounds.getX() + size, yBound);
4045

4146
g.drawImage(encoded, bounds.getX() + size * 2, yBound);
47+
g.drawImage(fontImage, bounds.getX() + size * 3, yBound);
48+
4249
yBound = bounds.getY() + size;
4350
g.drawImage(rgbImage, bounds.getX(), yBound);
4451
g.drawImage(fromRgba, bounds.getX() + size, yBound);
4552
g.drawImage(fromBytes, bounds.getX() + size * 2, yBound);
53+
g.drawImage(scaled, bounds.getX() + size * 3, yBound);
4654

4755
int smallSize = size / 2;
4856
yBound = bounds.getY() + size * 2;
@@ -55,6 +63,8 @@ protected void drawContent(Graphics g, Rectangle bounds) {
5563
g.drawImage(rgbImage, bounds.getX() + smallSize * 3, yBound, smallSize, smallSize);
5664
g.drawImage(fromRgba, bounds.getX() + smallSize * 4, yBound, smallSize, smallSize);
5765
g.drawImage(fromBytes, bounds.getX() + smallSize * 5, yBound, smallSize, smallSize);
66+
g.drawImage(fontImage, bounds.getX() + smallSize * 6, yBound, smallSize, smallSize);
67+
g.drawImage(scaled, bounds.getX() + smallSize * 7, yBound, smallSize, smallSize);
5868
yBound += smallSize;
5969

6070
int larger = bounds.getWidth() / 2;
@@ -70,6 +80,10 @@ protected void drawContent(Graphics g, Rectangle bounds) {
7080
yBound += larger;
7181
g.drawImage(fromRgba, bounds.getX(), yBound, larger, larger);
7282
g.drawImage(fromBytes, bounds.getX() + larger, yBound, larger, larger);
83+
84+
yBound += larger;
85+
g.drawImage(fontImage, bounds.getX(), yBound, larger, larger);
86+
g.drawImage(scaled, bounds.getX() + larger, yBound, larger, larger);
7387
}
7488

7589
@Override

scripts/hellocodenameone/common/src/main/java/com/codenameone/examples/hellocodenameone/tests/graphics/DrawString.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ protected void drawContent(Graphics g, Rectangle bounds) {
2525
g.drawString(name, bounds.getX(), y);
2626
y += g.getFont().getHeight();
2727
}
28+
29+
g.setColor(0xff0000);
30+
g.drawStringBaseline("Baseline and עברית", bounds.getX(), bounds.getY() + bounds.getHeight());
2831
}
2932

3033
@Override

0 commit comments

Comments
 (0)