diff --git a/packages/ui/resolution/ResolutionDecorator.js b/packages/ui/resolution/ResolutionDecorator.js index ee2854e85a..d0f54b39fc 100644 --- a/packages/ui/resolution/ResolutionDecorator.js +++ b/packages/ui/resolution/ResolutionDecorator.js @@ -9,7 +9,7 @@ import ReactDOM from 'react-dom'; import PropTypes from 'prop-types'; import hoc from '@enact/core/hoc'; -import {init, config as riConfig, defineScreenTypes, getResolutionClasses} from './resolution'; +import {init, calculateFontSize, config as riConfig, defineScreenTypes, getResolutionClasses, updateBaseFontSize, updateFontScale} from './resolution'; /** * Default config for `ResolutionDecorator`. @@ -92,18 +92,35 @@ const ResolutionDecorator = hoc(defaultConfig, (config, Wrapped) => { if (config.screenTypes) { defineScreenTypes(config.screenTypes); } + updateFontScale(config.fontScale); return class extends Component { static displayName = 'ResolutionDecorator'; static propTypes = /** @lends ui/resolution.ResolutionDecorator.prototype */ { - className: PropTypes.string + className: PropTypes.string, + + /** + * Font Scale value for the large screen mode. + * Use this value to set the scale of the font. + * This is the value that will be multiplied by pxPerRem, which is determined by the resolution. + * + * @type {Number} + * @default 1 + * @public + */ + fontScale: PropTypes.number + }; + + static defaultProps = { + fontScale: 1 }; constructor (props) { super(props); riConfig.intermediateScreenHandling = config.intermediateScreenHandling; riConfig.matchSmallerScreenType = config.matchSmallerScreenType; + updateFontScale(this.props.fontScale); init({measurementNode: (typeof window !== 'undefined' && window)}); this.state = { resolutionClasses: '' @@ -116,6 +133,13 @@ const ResolutionDecorator = hoc(defaultConfig, (config, Wrapped) => { this.rootNode = ReactDOM.findDOMNode(this); } + componentDidUpdate (prevProps) { + if (prevProps.fontScale !== this.props.fontScale) { + updateFontScale(this.props.fontScale); + updateBaseFontSize(calculateFontSize()); + } + } + componentWillUnmount () { if (config.dynamic) window.removeEventListener('resize', this.handleResize); } @@ -145,11 +169,15 @@ const ResolutionDecorator = hoc(defaultConfig, (config, Wrapped) => { } render () { + const {...rest} = this.props; + + delete rest.fontScale; + // Check if the classes are different from our previous classes let classes = getResolutionClasses(); if (this.props.className) classes += (classes ? ' ' : '') + this.props.className; - return ; + return ; } }; }); diff --git a/packages/ui/resolution/resolution.js b/packages/ui/resolution/resolution.js index 4028498a1b..124ae91120 100644 --- a/packages/ui/resolution/resolution.js +++ b/packages/ui/resolution/resolution.js @@ -1,4 +1,5 @@ let baseScreen, + fontScale = 1, orientation, riRatio, screenType, @@ -201,11 +202,11 @@ function calculateFontSize (type) { let size; if (orientation === 'portrait' && config.orientationHandling === 'scale') { - size = scrObj.height / scrObj.width * scrObj.pxPerRem; + size = scrObj.height / scrObj.width * (scrObj.pxPerRem * fontScale); } else { - size = scrObj.pxPerRem; + size = (scrObj.pxPerRem * fontScale); if (orientation === 'landscape' && shouldScaleFontSize) { - size = parseInt(workspaceBounds.height * scrObj.pxPerRem / scrObj.height); + size = parseInt(workspaceBounds.height * (scrObj.pxPerRem * fontScale) / scrObj.height); } } return size + 'px'; @@ -224,6 +225,17 @@ function updateBaseFontSize (size) { } } +/** + * @function + * @memberof ui/resolution + * @param {Number} fontScaleValue The value to scale the base font size. + * @returns {undefined} + * @private + */ +function updateFontScale (fontScaleValue) { + fontScale = fontScaleValue; +} + /** * Returns the CSS classes for the given `type`. * @@ -332,7 +344,7 @@ function getAspectRatioName (type) { * @public */ function scale (px) { - return (riRatio || getRiRatio()) * px; + return (riRatio || getRiRatio()) * px * fontScale; } /** @@ -365,8 +377,7 @@ function unit (pixels, toUnit) { if (!toUnit || !unitToPixelFactors[toUnit]) return; if (typeof pixels === 'string' && pixels.substr(-2) === 'px') pixels = parseInt(pixels.substr(0, pixels.length - 2)); if (typeof pixels !== 'number') return; - - return (pixels / unitToPixelFactors[toUnit]) + '' + toUnit; + return (pixels / (fontScale * unitToPixelFactors[toUnit])) + '' + toUnit; } /** @@ -494,5 +505,7 @@ export { scaleToRem, selectSrc, unit, - unitToPixelFactors + unitToPixelFactors, + updateBaseFontSize, + updateFontScale };