npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

web-gdi

v1.0.0

Published

A node package for simulating the Windows GDI

Downloads

3

Readme

English

Overview

Web-GDI is a TypeScript library that implements a compatibility layer for the classic Windows Graphics Device Interface (GDI) API on top of the modern HTML5 Canvas. It allows developers familiar with the Win32 GDI programming model to leverage their knowledge to create graphics applications that run in a Node.js or browser environment (with minimal adjustments).

This library provides abstractions for core GDI objects such as Pens, Brushes, Fonts, Bitmaps, and Device Contexts, along with a wide array of drawing functions and state management capabilities.

Features

GDI Object Modeling: Implementations of Pen, Brush, Font, and Bitmap classes.

Device Context (DC): A central DeviceContext class that manages drawing states and operations, mirroring the HDC concept.

Drawing Functions: Common GDI functions like MoveTo, LineTo, Rectangle, Ellipse, TextOut, SetPixel, BitBlt, and StretchBlt are supported.

Raster Operations (ROP2): Supports various raster operations like R2_COPYPEN, R2_XORPEN, R2_NOT, etc.

State Management: The DC state (current pen, brush, font, colors, modes, origin, etc.) can be retrieved and restored.

Mapping Modes: Basic support for mapping modes (e.g., MM_TEXT).

Installation

npm install web-gdi

Usage Example

import { DeviceContext, Pen, Brush } from 'web-gdi';
import { PenStyle, BrushStyle, HatchStyle, RasterOp } from 'web-gdi/enums';

// Create a new Device Context
const dc = new DeviceContext(800, 600);

// Create GDI objects
const redPen = new Pen(PenStyle.PS_SOLID, 2, 0xFF0000);
const blueBrush = new Brush(BrushStyle.BS_HATCHED, 0x0000FF, HatchStyle.HS_CROSS);cross-hatched brush

// Select them into the DC
dc.SelectObject(redPen);
dc.SelectObject(blueBrush);

// Set some DC attributes
dc.SetROP2(RasterOp.R2_COPYPEN);
dc.SetBkMode(2);
dc.SetTextColor(0x00FF00);

// Perform drawing operations
dc.Rectangle(50, 50, 300, 200);
dc.Ellipse(400, 100, 600, 250);
dc.MoveTo(10, 10);
dc.LineTo(100, 150);
dc.TextOut(200, 300, "Hello, Web-GDI!");

// Get the final image as a buffer
const imageBuffer = dc.ToBuffer();

API Overview

The library strives to mirror the GDI API structure. Key components include:

DeviceContext: The main class for all drawing operations.

Pen: Defines line style, width, and color.

Brush: Defines fill style, color, and hatch pattern.

Font: Defines font face, size, weight, and style.

Bitmap: Represents an off-screen drawing surface.

Enums: Various enums (PenStyle, BrushStyle, HatchStyle, RasterOp, BkMode, etc.) for specifying parameters.

中文

概述

Web-GDI 是一个 TypeScript 库,它在现代 HTML5 Canvas 之上实现了经典 Windows 图形设备接口 (GDI) API 的兼容层。它让熟悉 Win32 GDI 编程模型的开发者能够利用其知识,来创建可运行于 Node.js 或浏览器环境(只需极少调整)的图形应用程序。

该库为核心 GDI 对象(如画笔 Pen、画刷 Brush、字体 Font、位图 Bitmap 和设备上下文 Device Context)提供了抽象实现,并包含大量的绘图函数和状态管理功能。

特性

GDI 对象建模: 尽量参照原型实现了 Pen、Brush、Font 和 Bitmap 类。

设备上下文 (DC): 一个核心的 DeviceContext 类,用于管理绘图状态和操作,模拟了 HDC 的概念。

绘图函数: 支持常见的 GDI 函数,如 MoveTo, LineTo, Rectangle, Ellipse, TextOut, SetPixel, BitBlt 和 StretchBlt。

光栅操作 (ROP2): 支持多种光栅操作,如 R2_COPYPEN, R2_XORPEN, R2_NOT 等。

状态管理: 可以获取和恢复 DC 的状态(当前画笔、画刷、字体、颜色、模式、原点等)。

映射模式: 基本支持映射模式(例如 MM_TEXT)。

安装

npm install web-gdi

使用示例

import { DeviceContext, Pen, Brush } from 'web-gdi';
import { PenStyle, BrushStyle, HatchStyle, RasterOp } from 'web-gdi/enums';

// 创建一个新的设备上下文
const dc = new DeviceContext(800, 600);

// 创建 GDI 对象
const redPen = new Pen(PenStyle.PS_SOLID, 2, 0xFF0000);
const blueBrush = new Brush(BrushStyle.BS_HATCHED, 0x0000FF, HatchStyle.HS_CROSS);

// 将它们选入 DC
dc.SelectObject(redPen);
dc.SelectObject(blueBrush);

// 设置一些 DC 属性
dc.SetROP2(RasterOp.R2_COPYPEN);
dc.SetBkMode(2);
dc.SetTextColor(0x00FF00);

// 执行绘图操作
dc.Rectangle(50, 50, 300, 200);
dc.Ellipse(400, 100, 600, 250);
dc.MoveTo(10, 10);
dc.LineTo(100, 150);
dc.TextOut(200, 300, "Hello, Web-GDI!");

// 获取最终图像作为缓冲区
const imageBuffer = dc.ToBuffer();

API 概述

该库用于模拟GDI API的结构。关键组件包括:

DeviceContext: 所有绘图操作的主类。

Pen: 定义线条样式、宽度和颜色。

Brush: 定义填充样式、颜色和阴影图案。

Font: 定义字体、大小、粗细和样式。

Bitmap: 表示一个离屏绘图表面。

Enums: 各种枚举(PenStyle, BrushStyle, HatchStyle, RasterOp, BkMode 等)用于指定参数。