scale-fix
v0.0.3
Published
Angular library that corrects Windows display scaling between 110% and 175%.
Maintainers
Readme
scale-fix
Angular library that corrects Windows display scaling so an application keeps its 100% layout.
Windows display scaling between 110% and 175% raises devicePixelRatio above 1. Text, layout, and charts then render larger than designed. ScaleFixService applies the inverse CSS zoom on the document element and dispatches a resize event so chart libraries redraw at the corrected size.
Scaling at 100%, and scaling outside the configured range (for example 200%), is left unchanged. Manual browser zoom (Ctrl/Cmd + -, pinch) stays fully functional: the OS compensation is held steady while page zoom changes devicePixelRatio.
Installation
npm install scale-fixPeer dependencies:
| Package | Version |
| --- | --- |
| @angular/core | >=12.0.0 |
| @angular/common | >=12.0.0 |
The same package works in an Angular 12 project and in later majors, including future ones. It is published as partial Ivy, and the application links it with its own Angular compiler. Angular versions older than 12 cannot consume that format.
Usage
ScaleFixService is provided in the root injector. Call init() once when the application starts.
import { Component } from '@angular/core';
import { ScaleFixService } from 'scale-fix';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
})
export class AppComponent {
constructor(private readonly scaleFix: ScaleFixService) {
this.scaleFix.init();
}
}On Angular 14 or later, inject(ScaleFixService) works the same way.
Pass a custom inclusive range when the defaults are not the ones you want. Values are devicePixelRatio units (1.25 is 125% scaling).
this.scaleFix.init(1.25, 1.5);API
init(min = 1.1, max = 1.75): void
Reads window.devicePixelRatio, sets zoom on <html>, and listens for resize so the correction follows display-scale changes.
| devicePixelRatio | Display scaling | Result |
| --- | --- | --- |
| Below min or above max | for example 100% or 200% | No correction (zoom stays 1) |
| From min through max | 110%–175% by default | zoom is set to 1 / devicePixelRatio |
init() is safe to call more than once. The resize listener is registered only on the first call.
On the server, init() does nothing.
How it works
- Read
window.devicePixelRatio(default1). - If the ratio is inside
[min, max], setdocument.documentElementzoomto1 / devicePixelRatio. - On
resize, detect Ctrl+/- page zoom (DPR and CSS viewport width move in inverse proportion). In that case keep the existingzoomso user zoom is not cancelled. - Otherwise treat the change as a display-scale change and recompute the correction.
- Skip the update when the factor has not changed.
- Dispatch a
resizeevent on the next turn so charts and other resize-aware widgets redraw.
License
MIT © 2026 Om Dixit
Anyone may use, copy, modify, publish, distribute, sublicense, and sell this library, including in commercial applications. Copies must keep the copyright notice and the permission notice.
