Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for #76 rounding pt/px issue #77

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/utils/accessibility/accessibility.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ function isLargeScale(fontSize, fontSizeUnit, isFontBold) {
}

function fontSizeInPt(fontSize, fontSizeUnit) {
return (fontSizeUnit === 'pt') ? fontSize : Math.round(fontSize / PIXELS_IN_POINT);
return (fontSizeUnit === 'pt') ? fontSize : Math.floor(fontSize / PIXELS_IN_POINT);
}

function fontSizeInPx(fontSize, fontSizeUnit) {
return (fontSizeUnit === 'px') ? fontSize : Math.round(fontSize * PIXELS_IN_POINT);
return (fontSizeUnit === 'px') ? fontSize : Math.floor(fontSize * PIXELS_IN_POINT);
}

function accessibleContrast(accessibilityLevel, fontSize, fontSizeUnit, isFontBold) {
Expand Down
8 changes: 3 additions & 5 deletions src/utils/accessibility/accessibility.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ describe('Accessibility Utils', () => {
expect(accessibleContrast('AA', 18, 'pt', false)).to.equal(3);
expect(accessibleContrast('AA', 18, 'pt', true)).to.equal(3);
expect(accessibleContrast('AA', 24, 'pt', false)).to.equal(3);
expect(accessibleContrast('AA', 19, 'px', true)).to.equal(3);
});
});

Expand All @@ -30,19 +31,16 @@ describe('Accessibility Utils', () => {
it('should be 4.5 for large scale', () => {
expect(accessibleContrast('AAA', 14, 'pt', true)).to.equal(4.5);
expect(accessibleContrast('AAA', 18, 'pt', false)).to.equal(4.5);
expect(accessibleContrast('AAA', 18, 'px', true)).to.equal(4.5);
expect(accessibleContrast('AAA', 19, 'px', true)).to.equal(4.5);
expect(accessibleContrast('AAA', 24, 'px', false)).to.equal(4.5);
});
});
});

describe('fontSizeInPx()', () => {
it('Should round up', () => {
expect(fontSizeInPx(14, 'pt')).to.equal(19);
});

it('Should round down', () => {
expect(fontSizeInPx(10, 'pt')).to.equal(13);
expect(fontSizeInPx(18, 'pt')).to.equal(23);
});

it('Should return number unchanged', () => {
Expand Down