Skip to content

Commit

Permalink
chore: linting
Browse files Browse the repository at this point in the history
  • Loading branch information
Vexcited committed Dec 13, 2024
1 parent be7f955 commit 88f201d
Show file tree
Hide file tree
Showing 22 changed files with 1,349 additions and 1,294 deletions.
2 changes: 1 addition & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ module.exports = [
"stylistic/no-trailing-spaces": "error"
}
}
];
];
56 changes: 34 additions & 22 deletions src/converter/pdf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { PageViewport } from "../pdf/shared/util";

const createScratchCanvas = (width: number, height: number): PDFCanvas => {
return new PDFCanvas({}, width, height);
}
};

class PDFPageParser {
public static RenderingStates = {
Expand All @@ -14,16 +14,16 @@ class PDFPageParser {
PAUSED: 2,
FINISHED: 3
};

public viewport: PageViewport;
public renderingState = PDFPageParser.RenderingStates.INITIAL;

public ctxCanvas: Canvas;
public Boxsets: any[];

constructor (
public pdfPage: PDFPageProxy,
public id: number,
public pdfPage: PDFPageProxy,
public id: number,
public scale: number
) {
this.scale = scale || 1;
Expand All @@ -32,13 +32,25 @@ class PDFPageParser {
this.Boxsets = [];
this.ctxCanvas = <Canvas>{};
}

get width() { return this.viewport!.width; }
get height() { return this.viewport!.height; }
get HLines() { return this.ctxCanvas.HLines; }
get VLines() { return this.ctxCanvas.VLines; }
get Fills() { return this.ctxCanvas.Fills; }
get Texts() { return this.ctxCanvas.Texts; }

get width() {
return this.viewport!.width;
}
get height() {
return this.viewport!.height;
}
get HLines() {
return this.ctxCanvas.HLines;
}
get VLines() {
return this.ctxCanvas.VLines;
}
get Fills() {
return this.ctxCanvas.Fills;
}
get Texts() {
return this.ctxCanvas.Texts;
}

destroy (): void {
this.pdfPage.destroy();
Expand All @@ -51,13 +63,13 @@ class PDFPageParser {

async parsePage (): Promise<void> {
if (this.renderingState !== PDFPageParser.RenderingStates.INITIAL) {
throw new Error('Must be in new state before drawing');
throw new Error("Must be in new state before drawing");
}

this.renderingState = PDFPageParser.RenderingStates.RUNNING;

const canvas = createScratchCanvas(1, 1);
const ctx = canvas.getContext('2d')!;
const ctx = canvas.getContext("2d")!;

const renderContext = {
canvasContext: ctx,
Expand All @@ -79,31 +91,31 @@ export default class PDF {
await this.loadPages();
};

async loadPages (): Promise<void> {
const promises = [];
async loadPages (): Promise<void> {
const promises = [];

for (let i = 1; i <= this.document!.numPages; i++) {
promises.push(this.document!.getPage(i));
for (let i = 1; i <= this.document!.numPages; i++) {
promises.push(this.document!.getPage(i));
}

const pages = await Promise.all(promises);
const pages = await Promise.all(promises);
await this.parsePages(pages, 0, 1.5);
}
}

async parsePages (pages: PDFPageProxy[], id: number, scale: number): Promise<void> {
while (id < this.document!.numPages) {
const parser = new PDFPageParser(pages[id], id, scale);
await parser.parsePage();

const page = {
Width: parser.width,
Height: parser.height,
HLines: parser.HLines,
VLines: parser.VLines,
Fills: parser.Fills,
Texts: parser.Texts,
Texts: parser.Texts
} satisfies Page;

this.pages.push(page);
id++;
}
Expand Down
Loading

0 comments on commit 88f201d

Please sign in to comment.