font-metrics's People
font-metrics's Issues
Feature 5-1: Setting line-height returns the x-height to line-height ratio
This is an important feature, actually.
- It lets the user learn how the typical value of
line-height
such as 1.2 and 1.5 will be translated into the visually relevant parameter of the x-height to line-height ratio.
Refactor the file upload component
FontNameDisplay: Show the font file name set as a state variable in App.js
A subtask of #6
Set up the development environment
Install
- Boilerplate React app
- Cypress for test-driven development
Feature 4-2: Setting modular scale renders the sample paragraphs accordingly
Validate user inputs
cf. Use the short-circuit evaluation so that the error message won't be shown before the user enters any value. See: https://www.evernote.com/l/AFPu_A_V5OFIBJDAJNg4ZKLxbshq0mOLfWM
https://www.evernote.com/l/AFMxkVlPI2VPTbv-PTG42R5uCOXIVspxiYA (the example from TestingJavaScript.com)
Based on Sonny Recio's article entitled "How to use HTML5 form validations with React", we need the following to validate each input field.
Step 1
Enclose all the input elements with the form element along with its noValidate attribute (to disable HTML5's own form validation for which we cannot style the error message)
<form className="form-inside-input"
onSubmit={this.onSubmit}
noValidate >
{/* form inputs here */}
</form>
And add the min
attribute to the input elements
<input type="text"
name=“xHeightBox"
min="1"
required />
Step 2
In the .changeHandler() function, access to event.target.validity.valid
- This property is
true
if the user input satisfies all the constraints.
or to `event.target.validity.rangeUnderflow - This property is
true
if the user input value goes below the minimum value - See MDN on ValidityState.rangeUnderFlow for detail
And store this boolean value asxHeightBox.valid
(true if it's valid).
Step 3
Create a component of the error message
const ErrorValidationLabel = ({ errMsg }) => (
<label htmlFor="" style={{ color: "red" }}>
{errMsg}
</label>
);
Step 4
If the constraint is not satisfied, show the error message
const renderValidationError = xHeightBox.valid ? (
""
) : (
<ErrorValidationLabel errMsg={'X-height needs to be larger than or equal to 1.'} />
);
For the time being, we only deal with critical ones
- Font size being zero
- X-height scale being zero
because these two values are used as a denominator in the calculation of line-height.
Revise the description meta tag in public/index.html
Important for Google search result summary.
Create Favicon
getFontMetrics: use OpenType.js to extract font metrics from a font file
A subtask of #6
We separate this process into two:
- From FileList object to Font object
- From Font object to font metrics
This is because we can easily test the second process by directly (instead of via web) reading a font file with opentype.js
- See opentype.js readme on API
For the first process, see Font Inspector source code
Feature 1-1: Uploading a font file displays the font name
Font files for testing are stored in /cypress/fixtures/ folder, because Cypress won't recognize files in other locations.
Subtasks
FontFileUploader: Call the change handler upon the file upload
A subtask of #6
For testing, we use
jest.fn()
mock function from Jest- the code for
react-testing-library
to simulate a file upload - an adapted version of
NewMessageForm.spec.js
on https://learntdd.in/react/ expect().toHaveBeenCalled
from Jest
UI: Set the theme colour
Choose UI component typeface(s)
Feature 2-2: Setting x-height renders sample paragraphs accordingly
The font-size property
value in React has to be either a number or a string that ends with px
.
We have stored the font-size value as a string value without px
at the end so that it will be shown in the font-size box, for issue #14.
Consequently, we use the Number()
method to convert the string value into a number.
Set the default font metrics to render sample paragraphs
Why needed?
Without the default font-size, uploading a font file won't show any sample paragraphs because the
font-size` is effectively zero.
- This is not an optimal user experience due to the obvious visual feedback to the user's action.
Without the default font-family
, the user without a font file cannot tell what this webapp is about. Once they find it useful, they may visit us again with their own font file.
UI: Feedback the pressed state
Feature 3-2: Setting font-size renders the sample paragraphs accordingly
The implementation of Feature 2-2 (#15) has already executed this feature.
Upload a font file
Feature 5-2: Setting the line-height renders the sample paragraphs accordingly
Feature 1-2: Uploading a font file renders sample paragraphs in the uploaded font
Initially, we used the HTML canvas to render sample paragraphs. This has the following issues:
- We do not know how to write the test code for checking the content of the canvas element
- It seems difficult to change the rendering when the user chooses a x-height value.
Consequently, we instead use CSS Font Load API, to set the font
property directly to a paragraph element.
Feature 2-1: Setting x-height returns the font-size property value
[x-height in px] = (sxHeight
/ unitsPerEm
) * [font-size
in px]
Consequently, we have
[font-size
in px] = (unitsPerEm
/ sxHeight
) * [x-height in px]
We keep the fractional values up to 4 decimal places.
- Even though fractional values in pixels will be converted into an integer (see StackOverFlow discussions), precise values should be used for a long chain of calculation.
- To round off factions to the 4 decimal places, use
.toFixed(4)
method. See MDN documentation on the.toFixed()
method.
Cypress: Find out how to simulate the uploading of a font file
A sub-task of #6
It seems Cypress doesn't support this function yet, given that its GitHub issue on this matter isn't closed.
Pick the scale with a preview of sample paragraphs
Feature 4-1: Setting the modular scale shows the line-height value
Feature 3-1: Setting font-size displays the corresponding x-height
This feature is useful for finding the reference x-height.
- e.g. Someone wants his/her website to look similar to Medium.com. Then he/she needs to find out the
font-family
and thefont-size
value, and our webapp converts these values into the x-height value.
Show an error message if a wrong file type is uploaded
A subtask of #6
Opentype.js handles the following file types (see the Feature section of Opentype.js readme)
- OTF
- TTF
- WOFF
Error message should be
Please upload an OpenType Font (.otf), TrueType Font (.ttf), or Web Open Font Format (.woff) file.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.