Skip to content
This repository has been archived by the owner on Oct 28, 2018. It is now read-only.

Commit

Permalink
Fixed rounding values (Closes #23)
Browse files Browse the repository at this point in the history
  • Loading branch information
Cédric committed Oct 6, 2017
1 parent 8cc3c35 commit ab003e5
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 80 deletions.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
startingLineNumber = "30"
endingLineNumber = "30"
landmarkName = "setFail()"
landmarkType = "5">
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
Expand All @@ -95,8 +95,8 @@
endingColumnNumber = "9223372036854775807"
startingLineNumber = "27"
endingLineNumber = "27"
landmarkName = "drawRect(_:)"
landmarkType = "5">
landmarkName = "draw(_:)"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
Expand All @@ -111,8 +111,8 @@
endingColumnNumber = "9223372036854775807"
startingLineNumber = "26"
endingLineNumber = "26"
landmarkName = "drawRect(_:)"
landmarkType = "5">
landmarkName = "draw(_:)"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
Expand All @@ -122,7 +122,7 @@
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Colour Contrast Analyser/ColourDeficiencyAlgorithm.swift"
timestampString = "528981721.255751"
timestampString = "528989606.820743"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "121"
Expand All @@ -138,13 +138,13 @@
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Colour Contrast Analyser/CCAColourDeficiencyController.swift"
timestampString = "446380503.157904"
timestampString = "528989606.820792"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "35"
endingLineNumber = "35"
landmarkName = "init(coder:)"
landmarkType = "5">
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
Expand Down
98 changes: 47 additions & 51 deletions Colour Contrast Analyser/Base.lproj/MainWindow.xib

Large diffs are not rendered by default.

21 changes: 11 additions & 10 deletions Colour Contrast Analyser/Base.lproj/Preferences.xib
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="10117" systemVersion="15F34" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="13196" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="10117"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="13196"/>
<capability name="box content view" minToolsVersion="7.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="CCAPreferencesController" customModule="Colour_Contrast_Analyser" customModuleProvider="target">
Expand All @@ -18,19 +19,21 @@
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES"/>
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
<rect key="contentRect" x="196" y="240" width="579" height="421"/>
<rect key="screenRect" x="0.0" y="0.0" width="1920" height="1177"/>
<rect key="screenRect" x="0.0" y="0.0" width="2560" height="1417"/>
<view key="contentView" id="Cjg-Zk-v45">
<rect key="frame" x="0.0" y="0.0" width="579" height="421"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<box autoresizesSubviews="NO" fixedFrame="YES" title="Data formatters" borderType="line" translatesAutoresizingMaskIntoConstraints="NO" id="Mig-dT-6ux">
<box autoresizesSubviews="NO" fixedFrame="YES" borderType="line" title="Data formatters" translatesAutoresizingMaskIntoConstraints="NO" id="Mig-dT-6ux">
<rect key="frame" x="17" y="230" width="545" height="159"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<view key="contentView" id="9UF-b1-F4P">
<rect key="frame" x="1" y="1" width="543" height="143"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" fixedFrame="YES" setsMaxLayoutWidthAtFirstLayout="YES" translatesAutoresizingMaskIntoConstraints="NO" id="0oq-az-GEW">
<rect key="frame" x="16" y="14" width="543" height="119"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" controlSize="mini" sendsActionOnEndEditing="YES" id="D8h-TW-60Y">
<font key="font" metaFont="system"/>
<string key="title">%F : Foreground colour
Expand All @@ -46,11 +49,10 @@
</textField>
</subviews>
</view>
<color key="borderColor" white="0.0" alpha="0.41999999999999998" colorSpace="calibratedWhite"/>
<color key="fillColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
</box>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="TnO-5n-uD2">
<rect key="frame" x="18" y="397" width="122" height="17"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Result text format :" id="lty-BM-TA3">
<font key="font" metaFont="system"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
Expand All @@ -59,19 +61,18 @@
</textField>
<scrollView fixedFrame="YES" horizontalLineScroll="10" horizontalPageScroll="10" verticalLineScroll="10" verticalPageScroll="10" hasHorizontalScroller="NO" usesPredominantAxisScrolling="NO" translatesAutoresizingMaskIntoConstraints="NO" id="FLb-xF-s6Q">
<rect key="frame" x="20" y="8" width="539" height="218"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<clipView key="contentView" ambiguous="YES" id="6pq-ah-73g">
<rect key="frame" x="1" y="1" width="522" height="216"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<textView ambiguous="YES" importsGraphics="NO" findStyle="panel" continuousSpellChecking="YES" allowsUndo="YES" usesRuler="YES" usesFontPanel="YES" verticallyResizable="YES" allowsNonContiguousLayout="YES" quoteSubstitution="YES" dashSubstitution="YES" spellingCorrection="YES" smartInsertDelete="YES" id="vH3-lN-16S">
<textView ambiguous="YES" importsGraphics="NO" verticallyResizable="YES" usesFontPanel="YES" findStyle="panel" continuousSpellChecking="YES" allowsUndo="YES" usesRuler="YES" allowsNonContiguousLayout="YES" quoteSubstitution="YES" dashSubstitution="YES" spellingCorrection="YES" smartInsertDelete="YES" id="vH3-lN-16S">
<rect key="frame" x="0.0" y="0.0" width="522" height="216"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<size key="minSize" width="522" height="216"/>
<size key="maxSize" width="539" height="10000000"/>
<color key="insertionPointColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<size key="minSize" width="522" height="216"/>
<size key="maxSize" width="539" height="10000000"/>
</textView>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
Expand Down
11 changes: 9 additions & 2 deletions Colour Contrast Analyser/CCALuminosityControler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,16 @@ class CCALuminosityControler: NSViewController {
}

func updateResults() {
// if ((2.95 <= eRaw) and (3 > eRaw)) or ((4.45 <= eRaw) and (4.5 > eRaw)) then
luminosityValue = Luminosity.getResult(self.fColor, bColor:self.bColor)
contrastRatioString = String(format:"%.2f:1", luminosityValue!)
ratioText.stringValue = String(format:NSLocalizedString("contrast_ratio", comment:"Contrast Ratio: %.2f:1"), luminosityValue!)
let roundedValue = round(luminosityValue!*1000)/1000
contrastRatioString = String(format:"%.3f:1", roundedValue)
if ((luminosityValue! >= 6.95 && luminosityValue! < 7) || (luminosityValue! >= 4.45 && luminosityValue! < 4.5) || (luminosityValue! >= 2.95 && luminosityValue! < 3)) {
ratioText.stringValue = String(format:NSLocalizedString("contrast_ratio_below", comment:"")) + String(format:"%.1f:1 (%.3f:1)", luminosityValue!, roundedValue)
} else {
ratioText.stringValue = String(format:NSLocalizedString("contrast_ratio", comment:"")) + String(format:"%.1f:1", luminosityValue!)
}

passAA = true
passAAA = true
passAALarge = true
Expand Down
6 changes: 2 additions & 4 deletions Colour Contrast Analyser/LuminosityAlgorithm.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@
import Cocoa

class Luminosity {

class func getResult(_ fColor:NSColor, bColor:NSColor) -> Double {
let lf:CGFloat = relativeLuminance(fColor)
let lb:CGFloat = relativeLuminance(bColor)
let cr = contrastRatio(lf, lb:lb)
// Half round up to 0.x
let rounded = round(cr*10)/10
return Double(rounded)
return Double(cr)
}

class func contrastRatio (_ lf:CGFloat, lb:CGFloat) -> CGFloat {
Expand Down
5 changes: 3 additions & 2 deletions Colour Contrast Analyser/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* Contrast Ratio: %.2f:1 */
"contrast_ratio" = "Contrast Ratio: %.1f:1";
/* Contrast Ratio: %.1f:1 */
"contrast_ratio" = "Contrast Ratio: ";
"contrast_ratio_below" = "Contrast Ratio: just below ";

/* Colour/Brightness difference */
"colour_diff" = "Colour difference: %d (minimum 500)";
Expand Down
7 changes: 4 additions & 3 deletions Colour Contrast Analyser/fr.lproj/Localizable.strings
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* Contrast Ratio: %.2f:1 */
"contrast_ratio" = "Ratio de contraste: %.1f:1";
/* Contrast Ratio: %.2f:1 */
"contrast_ratio" = "Ratio de contraste: ";
"contrast_ratio_below" = "Ratio de contraste: juste en dessous de ";

/* Colour/Brightness difference */
"colour_diff" = "Différence de couleurs: %d (minimum 500)";
Expand Down Expand Up @@ -37,4 +38,4 @@ Note: Les polices spécialement petites ou décoratives sont difficiles à lire
"passed_large_AA" = "Grand texte conforme au niveau AA";
"failed_large_AA" = "Grand texte non conforme au niveau AA";
"passed_large_AAA" = "Grand texte conforme au niveau AAA";
"failed_large_AAA" = "Grand texte non conforme au niveau AAA";
"failed_large_AAA" = "Grand texte non conforme au niveau AAA";

0 comments on commit ab003e5

Please sign in to comment.