MyGit

jondavidjohn/hidpi-canvas-polyfill

Fork: 262 Star: 666 (更新于 2024-10-31 07:11:40)

license: NOASSERTION

Language: JavaScript .

:computer: A JavaScript drop-in module to polyfill consistent and automatic HiDPI Canvas support.

最后发布版本: 1.0.10 ( 2016-09-23 22:40:29)

官方网址 GitHub网址


Do you use webpack?

Wish your team made reducing the size of your webpack builds a priority? Want to know how the changes you're making impact your asset profile for every pull request?

Check it out at packtracker.io.


HiDPI Canvas Polyfill

Build Status

This is a drop-in polyfill to scale canvas appropriately to maintain sharpness in browsers that currently do not provide the appropriately scaled backing store to do this automatically.

As of this writing Safari is the only browser that accounts for this.

The goal of this drop-in is to make this behavior consistent accross all browsers, without having to modify any of your canvas code.

Scope

Currently this plugin handles most general cross browser drawing functions, but feel free to send Pull Requests as you find functions you need supported.

If the function simply needs all or some of its arguments multiplied by the ratio, it should simply require you to add it to the ratioArgs object, following the proper pattern.

It currently leaves images alone, so to retinize images on your canvas, simply duplicate the getPixelRatio function in your code and divide your image dimensions by the provided ratio.

var getPixelRatio = function(context) {
    var backingStore = context.backingStorePixelRatio ||
          context.webkitBackingStorePixelRatio ||
          context.mozBackingStorePixelRatio ||
          context.msBackingStorePixelRatio ||
          context.oBackingStorePixelRatio ||
          context.backingStorePixelRatio || 1;

    return (window.devicePixelRatio || 1) / backingStore;
};

Usage

To use this module, simply include it before any of your canvas code

  ...
  <script src=".../dist/hidpi-canvas.min.js"></script>
  <script src=".../your-canvas-stuff.js"></script>
  ...

Bower

This module is also installable via bower

bower install hidpi-canvas

TODO

  • More Complete context function coverage
  • Figure out how to write tests for this type of thing

Development

See CONTRIBUTING.md

最近版本更新:(数据更新于 2024-10-03 14:35:12)

2016-09-23 22:40:29 1.0.10

2014-07-28 01:20:31 1.0.9

2014-07-09 23:51:11 1.0.6

2014-06-26 02:22:48 1.0.5

2014-03-26 00:05:22 1.0.4

2014-03-15 01:10:39 1.0.3

2014-01-31 12:39:25 1.0.2

2013-10-26 13:14:18 1.0.1

2013-10-23 23:32:41 1.0.0

jondavidjohn/hidpi-canvas-polyfill同语言 JavaScript最近更新仓库

2024-11-15 00:07:06 MHSanaei/3x-ui

2024-11-13 05:41:28 nodejs/node

2024-11-13 00:07:54 bia-pain-bache/BPB-Worker-Panel

2024-11-12 11:08:54 emberjs/ember.js

2024-11-11 12:06:37 gethomepage/homepage

2024-11-10 21:29:01 Number178/kikoeru-express