[289739, 323933] WCAG 2.0/JIS support (level AA)
diff --git a/plugins/org.eclipse.actf.visualization.engines.lowvision/src/messages.properties b/plugins/org.eclipse.actf.visualization.engines.lowvision/src/messages.properties
index 83e764c..7f8ab24 100644
--- a/plugins/org.eclipse.actf.visualization.engines.lowvision/src/messages.properties
+++ b/plugins/org.eclipse.actf.visualization.engines.lowvision/src/messages.properties
@@ -26,6 +26,7 @@
ProhibitedBothColorsProblem_Both_of_the_foreground_and_background_colors_are_not_allowed_by_the_design_guideline__1=Both foreground and background colors are not allowed by the design guideline.
ProhibitedForegroundColorProblem_The_foreground_color_is_not_allowed_by_the_design_guideline__1=The foreground color is not allowed by the design guideline.
ProhibitedBackgroundColorProblem_The_background_color_is_not_allowed_by_the_design_guideline__1=The background color is not allowed by the design guideline.
+ContrastRatio = Contrast Ratio
#
# lowvision.ScoreUtil
#
diff --git a/plugins/org.eclipse.actf.visualization.engines.lowvision/src/messages_ja.properties b/plugins/org.eclipse.actf.visualization.engines.lowvision/src/messages_ja.properties
index f95ccfc..869b482 100644
--- a/plugins/org.eclipse.actf.visualization.engines.lowvision/src/messages_ja.properties
+++ b/plugins/org.eclipse.actf.visualization.engines.lowvision/src/messages_ja.properties
@@ -26,6 +26,7 @@
ProhibitedBothColorsProblem_Both_of_the_foreground_and_background_colors_are_not_allowed_by_the_design_guideline__1 = \u6587\u5b57\u8272\u3068\u80cc\u666f\u8272\u306e\u4e21\u65b9\u306b\u30ac\u30a4\u30c9\u30e9\u30a4\u30f3\u3067\u8a31\u3055\u308c\u3066\u3044\u306a\u3044\u8272\u304c\u4f7f\u308f\u308c\u3066\u3044\u307e\u3059
ProhibitedForegroundColorProblem_The_foreground_color_is_not_allowed_by_the_design_guideline__1 = \u6587\u5b57\u8272\u306b\u30ac\u30a4\u30c9\u30e9\u30a4\u30f3\u3067\u8a31\u3055\u308c\u3066\u3044\u306a\u3044\u8272\u304c\u4f7f\u308f\u308c\u3066\u3044\u307e\u3059
ProhibitedBackgroundColorProblem_The_background_color_is_not_allowed_by_the_design_guideline__1 = \u80cc\u666f\u8272\u306b\u30ac\u30a4\u30c9\u30e9\u30a4\u30f3\u3067\u8a31\u3055\u308c\u3066\u3044\u306a\u3044\u8272\u304c\u4f7f\u308f\u308c\u3066\u3044\u307e\u3059
+ContrastRatio = \u30b3\u30f3\u30c8\u30e9\u30b9\u30c8\u6bd4
#
# lowvision.ScoreUtil
#
diff --git a/plugins/org.eclipse.actf.visualization.engines.lowvision/src/org/eclipse/actf/visualization/internal/engines/lowvision/LowVisionProblemConverter.java b/plugins/org.eclipse.actf.visualization.engines.lowvision/src/org/eclipse/actf/visualization/internal/engines/lowvision/LowVisionProblemConverter.java
index ccebac3..d472036 100644
--- a/plugins/org.eclipse.actf.visualization.engines.lowvision/src/org/eclipse/actf/visualization/internal/engines/lowvision/LowVisionProblemConverter.java
+++ b/plugins/org.eclipse.actf.visualization.engines.lowvision/src/org/eclipse/actf/visualization/internal/engines/lowvision/LowVisionProblemConverter.java
@@ -34,7 +34,13 @@
"L_" + target[i].getLowVisionProblemType()); //$NON-NLS-1$
tmp.setSubType(target[i].getLowVisionProblemType());
try {
- if (tmp.getSubType() != ILowvisionProblemSubtype.LOWVISION_BACKGROUND_IMAGE_WARNING) {
+ switch (tmp.getSubType()) {
+ case ILowvisionProblemSubtype.LOWVISION_BACKGROUND_IMAGE_WARNING:
+ break;
+ case ILowvisionProblemSubtype.LOWVISION_COLOR_PROBLEM:
+ tmp.setDescription(target[i].getRepresentative().getDescription());
+ break;
+ default:
tmp.setDescription(target[i].getDescription());
}
} catch (Exception e) {
@@ -53,7 +59,7 @@
tmp.setWidth(target[i].getWidth());
tmp.setHeight(target[i].getHeight());
tmp.setArea(target[i].getWidth() * target[i].getHeight());
-
+
// TODO recommendation
result.add(tmp);
}
diff --git a/plugins/org.eclipse.actf.visualization.engines.lowvision/src/org/eclipse/actf/visualization/internal/engines/lowvision/Messages.java b/plugins/org.eclipse.actf.visualization.engines.lowvision/src/org/eclipse/actf/visualization/internal/engines/lowvision/Messages.java
index e8aeddf..b76eb0f 100644
--- a/plugins/org.eclipse.actf.visualization.engines.lowvision/src/org/eclipse/actf/visualization/internal/engines/lowvision/Messages.java
+++ b/plugins/org.eclipse.actf.visualization.engines.lowvision/src/org/eclipse/actf/visualization/internal/engines/lowvision/Messages.java
@@ -40,6 +40,7 @@
public static String PageEvaluation_Good;
public static String PageEvaluation_Poor;
public static String ImageDumpUtil_TrueColor;
+ public static String ContrastRatio;
static {
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
diff --git a/plugins/org.eclipse.actf.visualization.engines.lowvision/src/org/eclipse/actf/visualization/internal/engines/lowvision/PageElement.java b/plugins/org.eclipse.actf.visualization.engines.lowvision/src/org/eclipse/actf/visualization/internal/engines/lowvision/PageElement.java
index 55f37d6..5f61755 100644
--- a/plugins/org.eclipse.actf.visualization.engines.lowvision/src/org/eclipse/actf/visualization/internal/engines/lowvision/PageElement.java
+++ b/plugins/org.eclipse.actf.visualization.engines.lowvision/src/org/eclipse/actf/visualization/internal/engines/lowvision/PageElement.java
@@ -271,27 +271,17 @@
private ColorProblem checkColors(LowVisionType _lvType)
throws LowVisionException {
- if (!(_lvType.doChangeColors())) {
- return (null);
- }
if (!isTextTag()) {
return (null);
}
- ColorIRGB fgSim = null;
- ColorIRGB bgSim = null;
- try {
- fgSim = new ColorIRGB(_lvType.convertColor(foregroundColor));
- bgSim = new ColorIRGB(_lvType.convertColor(backgroundColor));
- } catch (LowVisionException e) {
- e.printStackTrace();
- throw new LowVisionException("Could not convert colors."); //$NON-NLS-1$
- }
+ ColorIRGB fgOrg = new ColorIRGB(foregroundColor);
+ ColorIRGB bgOrg = new ColorIRGB(backgroundColor);
- W3CColorChecker w3c = new W3CColorChecker(fgSim, bgSim);
- double severity = w3c.calcSeverity();
+ W3CColorChecker w3c = new W3CColorChecker(fgOrg, bgOrg);
+ double contrast = w3c.calcContrast();
try {
- if (severity <= 0.0) {
+ if (contrast > 4.5) {
if (style.getBackgroundImage() != null
&& !style.getBackgroundImage().equalsIgnoreCase("none")) {
ColorProblem result = new ColorProblem(this, _lvType, 0);
@@ -300,16 +290,40 @@
}
return (null);
} else {
- ColorProblem result = new ColorProblem(this, _lvType, severity);
+ ColorProblem result = new ColorProblem(this, _lvType,
+ w3c.calcSeverity());
if (style.getBackgroundImage() != null
- && !style.getBackgroundImage().equalsIgnoreCase("none"))
+ && !style.getBackgroundImage().equalsIgnoreCase("none")){
result.setHasBackgroundImage(true);
+ }else{
+ result.setContrast(contrast);
+ }
return (result);
}
} catch (LowVisionProblemException e) {
return (null);
}
+ /*
+ * if (!(_lvType.doChangeColors())) { //TODO ColorIRGB fgSim = null;
+ * ColorIRGB bgSim = null; try { fgSim = new
+ * ColorIRGB(_lvType.convertColor(foregroundColor)); bgSim = new
+ * ColorIRGB(_lvType.convertColor(backgroundColor)); } catch
+ * (LowVisionException e) { e.printStackTrace(); throw new
+ * LowVisionException("Could not convert colors."); //$NON-NLS-1$ }
+ *
+ * W3CColorChecker w3c = new W3CColorChecker(fgSim, bgSim); double
+ * severity = w3c.calcSeverity(); try { if (severity <= 0.0) { if
+ * (style.getBackgroundImage() != null &&
+ * !style.getBackgroundImage().equalsIgnoreCase( "none")) { ColorProblem
+ * result = new ColorProblem(this, _lvType, 0);
+ * result.setHasBackgroundImage(true); return (result); } return (null);
+ * } else { ColorProblem result = new ColorProblem(this, _lvType,
+ * severity); if (style.getBackgroundImage() != null &&
+ * !style.getBackgroundImage().equalsIgnoreCase( "none"))
+ * result.setHasBackgroundImage(true); return (result); } } catch
+ * (LowVisionProblemException e) { return (null); } } return(null);
+ */
}
/*
@@ -354,7 +368,7 @@
String fontStr = style.getFontSize().toLowerCase();
- System.out.println(fontStr);
+ //System.out.println(fontStr);
// directly under the <BODY>
if (fontStr.indexOf(DELIM) == -1) {
diff --git a/plugins/org.eclipse.actf.visualization.engines.lowvision/src/org/eclipse/actf/visualization/internal/engines/lowvision/checker/ColorChecker.java b/plugins/org.eclipse.actf.visualization.engines.lowvision/src/org/eclipse/actf/visualization/internal/engines/lowvision/checker/ColorChecker.java
index 98b7acf..d657aa0 100644
--- a/plugins/org.eclipse.actf.visualization.engines.lowvision/src/org/eclipse/actf/visualization/internal/engines/lowvision/checker/ColorChecker.java
+++ b/plugins/org.eclipse.actf.visualization.engines.lowvision/src/org/eclipse/actf/visualization/internal/engines/lowvision/checker/ColorChecker.java
@@ -27,4 +27,6 @@
}
//[0.0, 1.0]
public abstract double calcSeverity();
+
+ public abstract double calcContrast();
}
diff --git a/plugins/org.eclipse.actf.visualization.engines.lowvision/src/org/eclipse/actf/visualization/internal/engines/lowvision/checker/W3CColorChecker.java b/plugins/org.eclipse.actf.visualization.engines.lowvision/src/org/eclipse/actf/visualization/internal/engines/lowvision/checker/W3CColorChecker.java
index c233e57..128df73 100644
--- a/plugins/org.eclipse.actf.visualization.engines.lowvision/src/org/eclipse/actf/visualization/internal/engines/lowvision/checker/W3CColorChecker.java
+++ b/plugins/org.eclipse.actf.visualization.engines.lowvision/src/org/eclipse/actf/visualization/internal/engines/lowvision/checker/W3CColorChecker.java
@@ -25,9 +25,13 @@
private double sevY;
private double sevC;
+
+ private double sevL;
private double severity;
+ private double contrastRatio;
+
public W3CColorChecker(ColorIRGB _c1, ColorIRGB _c2) {
super(_c1, _c2);
int r1 = color1.getR();
@@ -38,11 +42,24 @@
int b2 = color2.getB();
double y1 = calcY(r1, g1, b1);
double y2 = calcY(r2, g2, b2);
+
+ double l1 = calcL(r1, g1, b1);
+ double l2 = calcL(r2, g2, b2);
+
+ if(l1>l2){
+ contrastRatio = (l1+0.05)/(l2+0.05);
+ }else{
+ contrastRatio = (l2+0.05)/(l1+0.05);
+ }
+
diffY = Math.abs(y1 - y2);
diffC = Math.abs(r1 - r2) + Math.abs(g1 - g2) + Math.abs(b1 - b2);
sevY = calcSevY(diffY);
sevC = calcSevC(diffC);
- severity = Math.min(sevY, sevC);
+ sevL = calcSevL(contrastRatio);
+ //severity = Math.min(sevY, sevC); WCAG 1.0, simulation
+ severity = sevL;
+
}
public W3CColorChecker(int _i1, int _i2) {
@@ -94,9 +111,23 @@
return ((new W3CColorChecker(_c1, _c2)).calcChrominanceDifference());
}
+ private static double calcL(int _r, int _g, int _b){
+ return(0.2126*calcRGB(_r)+0.7152*calcRGB(_g)+0.0722*calcRGB(_b));
+ }
+
private static double calcY(int _r, int _g, int _b) {
return ( (_r * 299 + _g * 587 + _b * 114) / 1000.0);
}
+
+ private static double calcRGB(int rgb){
+ double tmp = (double)rgb/255;
+ if(tmp<=0.03928){
+ return(tmp/12.92);
+ }else{
+ return(Math.pow((tmp+0.055)/1.055,2.4));
+ }
+ }
+
private static double calcSevY(double _diffY) {
double sevY = 0.0;
@@ -121,4 +152,17 @@
sevC = 1.0;
return (sevC);
}
+
+ private static double calcSevL(double contrast){
+ double sevL = 0.0;
+ if(contrast>7){
+ return sevL;
+ }
+ return(1.0-(contrast-1)/(7.0-1));
+ }
+
+ @Override
+ public double calcContrast() {
+ return contrastRatio;
+ }
}
diff --git a/plugins/org.eclipse.actf.visualization.engines.lowvision/src/org/eclipse/actf/visualization/internal/engines/lowvision/problem/ColorProblem.java b/plugins/org.eclipse.actf.visualization.engines.lowvision/src/org/eclipse/actf/visualization/internal/engines/lowvision/problem/ColorProblem.java
index ad9f5fb..79922c9 100644
--- a/plugins/org.eclipse.actf.visualization.engines.lowvision/src/org/eclipse/actf/visualization/internal/engines/lowvision/problem/ColorProblem.java
+++ b/plugins/org.eclipse.actf.visualization.engines.lowvision/src/org/eclipse/actf/visualization/internal/engines/lowvision/problem/ColorProblem.java
@@ -11,6 +11,8 @@
package org.eclipse.actf.visualization.internal.engines.lowvision.problem;
+import java.math.BigDecimal;
+
import org.eclipse.actf.visualization.engines.lowvision.LowVisionType;
import org.eclipse.actf.visualization.internal.engines.lowvision.Messages;
import org.eclipse.actf.visualization.internal.engines.lowvision.PageElement;
@@ -24,6 +26,7 @@
private int foregroundColor = -1;
private int backgroundColor = -1;
private boolean hasBackgroundImage = false;
+ private double contrast = 0;
public ColorProblem( PageComponent _pc, LowVisionType _lvType, double _proba ) throws LowVisionProblemException{
super( LOWVISION_COLOR_PROBLEM, _lvType, Messages.ColorProblem_Foreground_and_background_colors_are_too_close__1, _pc, _proba );
@@ -63,6 +66,10 @@
}
public String getDescription() throws LowVisionProblemException{
+ if(contrast>=1&&contrast<=21){
+ BigDecimal bd = new BigDecimal(contrast);
+ return(super.getDescription()+"("+Messages.ContrastRatio+"="+bd.setScale(2,BigDecimal.ROUND_HALF_UP)+")");
+ }
return( super.getDescription() );
}
@@ -86,4 +93,12 @@
problemType = LOWVISION_COLOR_PROBLEM;
}
}
+
+ public double getContrast() {
+ return contrast;
+ }
+
+ public void setContrast(double contrast) {
+ this.contrast = contrast;
+ }
}