Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
TwIStOy committed Dec 5, 2023
1 parent b427834 commit b862c4a
Show file tree
Hide file tree
Showing 3 changed files with 273 additions and 1 deletion.
63 changes: 63 additions & 0 deletions src/core/components/cairo-render.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import * as cairo from "3rd.cairo.cairo";

export type CompositeOperation =
| "source-over"
| "source-in"
| "source-out"
| "source-atop"
| "destination-over"
| "destination-in"
| "destination-out"
| "destination-atop"
| "xor"
| "color"
| "color-burn"
| "color-dodge"
| "darken"
| "difference"
| "exclusion"
| "hard-light"
| "hue"
| "lighten"
| "lighter"
| "luminosity"
| "multiply"
| "overlay"
| "saturation"
| "screen"
| "soft-light";

export class Context2DRender {
private surface: cairo.Surface;
private context: cairo.Context;

private _width: number;
private _height: number;
private _globalCompositeOperation: CompositeOperation;
private _globalAlpha: number;
// private _fillColor: Color;
// private _strokeColor: Color;
private _font: string;

constructor(width: number, height: number) {
this.surface = cairo.image_surface("argb32", width, height);
this.context = this.surface.context();

this._width = width;
this._height = height;

this._globalCompositeOperation = "source-over";
this._globalAlpha = 1.0;
// this._fillColor = new Color(0x000000);
// this._strokeColor = new Color(0x000000);
this._font = "10x sans-serif";
}

function setDimensions(width: number, height: number) {

Check failure on line 56 in src/core/components/cairo-render.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Unexpected token. A constructor, method, accessor, or property was expected.
this.surface = cairo.image_surface("argb32", width, height);

Check failure on line 57 in src/core/components/cairo-render.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'this' implicitly has type 'any' because it does not have a type annotation.
this.context = this.surface.context();

Check failure on line 58 in src/core/components/cairo-render.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'this' implicitly has type 'any' because it does not have a type annotation.

Check failure on line 58 in src/core/components/cairo-render.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'this' implicitly has type 'any' because it does not have a type annotation.

this._width = width;

Check failure on line 60 in src/core/components/cairo-render.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'this' implicitly has type 'any' because it does not have a type annotation.
this._height = height;

Check failure on line 61 in src/core/components/cairo-render.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'this' implicitly has type 'any' because it does not have a type annotation.
}
}

Check failure on line 63 in src/core/components/cairo-render.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Declaration or statement expected.
209 changes: 209 additions & 0 deletions src/types/3rd/cairo.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
declare module "3rd.cairo.cairo" {
type ImageType = "argb32" | "rgb24";

class Surface {
flush(): void;
context(): Context;
data(): number[];
create_for_rectangle(
x: number,
y: number,
width: number,
height: number
): Surface;
}

class Pattern {}
class TextExtents {
x_bearing: number;
y_bearing: number;
width: number;
height: number;
x_advance: number;
y_advance: number;
}
class FontExtents {
ascent: number;
descent: number;
height: number;
max_x_advance: number;
max_y_advance: number;
}

function image_surface(
this: void,
type: ImageType,
width: number,
height: number
): Surface;
function image_surface_from_data(
this: void,
type: ImageType,
data: number[],
width: number,
height: number,
stride: number
): Surface;

type LineCap = "butt" | "round" | "square";
type LineJoin = "miter" | "round" | "bevel";
type Operator =
| "clear"
| "source"
| "over"
| "in"
| "out"
| "atop"
| "dest"
| "dest_over"
| "dest_in"
| "dest_out"
| "dest_atop"
| "xor"
| "add"
| "saturate"
| "multiply"
| "screen"
| "overlay"
| "darken"
| "lighten"
| "color_dodge"
| "color_burn"
| "hard_light"
| "soft_light"
| "difference"
| "exclusion"
| "hsl_hue"
| "hsl_saturation"
| "hsl_color"
| "hsl_luminosity";

class Context {
save(): void;
restore(): void;

rgba(r: number, g: number, b: number, a: number): void;
source(source: Surface, x?: number, y?: number): void;
operator(): Operator;
operator(op: Operator): void;

font_face(name: string, slant: string, weight: string): void;
font_size(size: number): void;

line_width(): number;
line_width(value: number): void;
miter_limit(): number;
miter_limit(value: number): void;
line_cap(): LineCap;
line_cap(value: LineCap): void;
line_join(): LineJoin;
line_join(value: LineJoin): void;

get_matrix(): Matrix;
set_matrix(m: Matrix): void;
transform(m: Matrix): this;
translate(x: number, y: number): this;
scale(x: number, y: number): this;
rotate(rads: number): this;

new_path(): void;
new_sub_path(): void;
move_to(x: number, y: number): void;
line_to(x: number, y: number): void;
curve_to(
x1: number,
y1: number,
x2: number,
y2: number,
x3: number,
y3: number
): void;
quad_curve_to(x1: number, y1: number, x2: number, y2: number): void;
arc(
xc: number,
yc: number,
radius: number,
angle1: number,
angle2: number
): void;
arc_negative(
xc: number,
yc: number,
radius: number,
angle1: number,
angle2: number
): void;
rel_move_to(x: number, y: number): void;
rel_line_to(x: number, y: number): void;
rel_curve_to(
x1: number,
y1: number,
x2: number,
y2: number,
x3: number,
y3: number
): void;
rel_quad_curve_to(x1: number, y1: number, x2: number, y2: number): void;
close_path(): void;
path_extents(): [number, number, number, number];
mask(pattern: Pattern): void;
mask_surface(surface: Surface, x: number, y: number): void;
elliptic_arc(
cx: number,
cy: number,
rx: number,
ry: number,
rotation: number,
a1: number,
a2: number
): void;
elliptic_arc_negative(
cx: number,
cy: number,
rx: number,
ry: number,
rotation: number,
a1: number,
a2: number
): void;

rectangle(x: number, y: number, width: number, height: number): void;
rounded_rectangle(
x: number,
y: number,
width: number,
height: number,
radius: number
): void;

fill(): void;
fill_preserve(): void;
stroke(): void;
stroke_preserve(): void;

paint(): void;
paint_with_alpha(alpha: number): void;

reset_clip(): void;
clip(): void;
clip_preserve(): void;
clip_extends(): [number, number, number, number];

show_text(text: string): void;
text_path(text: string): void;
text_extents(text: string): TextExtents;
font_extents(): FontExtents;
}

class Matrix {}

/** @noSelf */
function matrix(
a?: number,
b?: number,
c?: number,
d?: number,
e?: number,
f?: number
): Matrix;
}
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"name": "./tstl_plugins/fix-require-path.ts"
}
],
"noResolvePaths": ["which-key-raw-nvim"],
"noResolvePaths": ["which-key-raw-nvim", "3rd.cairo.cairo"],
"luaLibImport": "require-minimal",
"luaBundle": "init.lua",
"luaBundleEntry": "src/index.ts"
Expand Down

0 comments on commit b862c4a

Please sign in to comment.