MyGit

jondavidjohn/hidpi-canvas-polyfill

Fork: 261 Star: 667 (更新于 2024-12-18 08:15:26)

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-12-22 13:19:55 gethomepage/homepage

2024-12-22 11:34:40 chris81605/Degrees-of-Lewdity_Cheat_Extended

2024-12-22 00:44:14 gorhill/uBlock

2024-12-21 12:14:02 layui/layui

2024-12-21 03:44:01 emberjs/ember.js

2024-12-20 02:57:09 nodejs/node