Revize 7b710808
Přidáno uživatelem Ondřej Váně před asi 4 roky(ů)
fe/fulltextsearch/src/app/services/drawer/drawer.service.ts | ||
---|---|---|
1 |
import { Injectable } from '@angular/core';
|
|
1 |
import {Injectable} from '@angular/core';
|
|
2 | 2 |
import {LoggerService} from '../logger/logger.service'; |
3 | 3 |
import {TextRegion} from '../../model/parts/TextRegion'; |
4 | 4 |
import {Point} from '../../model/parts/Point'; |
5 | 5 |
import Utils from '../../../Utils'; |
6 |
import {DocumentSize} from '../../model/parts/DocumentSize'; |
|
6 | 7 |
|
7 | 8 |
@Injectable({ |
8 | 9 |
providedIn: 'root' |
9 | 10 |
}) |
10 | 11 |
export class DrawerService { |
11 | 12 |
|
13 |
resizeRation: number = null; |
|
14 |
|
|
12 | 15 |
constructor(private LOGGER: LoggerService) { } |
13 | 16 |
|
14 | 17 |
public drawResult(textRegion: TextRegion, imageId: string, canvasId: string) { |
15 |
const canvasContext = this.initCanvas(imageId, canvasId); |
|
16 |
|
|
17 |
if (textRegion !== null) { |
|
18 |
if (Utils.isIterable(textRegion.textLines) && textRegion.textLines.length !== 0) { |
|
19 |
for (const textLine of textRegion.textLines) { |
|
20 |
if (Utils.isIterable(textLine.textWords) && textLine.textWords.length !== 0) { |
|
21 |
for (const textWord of textLine.textWords) { |
|
22 |
if (textWord !== null) { |
|
23 |
// print words |
|
24 |
this.draw(textWord.wordCoords.points, canvasContext); |
|
25 |
this.LOGGER.info('printing words'); |
|
26 |
} |
|
18 |
const canvasContext = this.initCanvas(imageId, canvasId, textRegion.documentSize); |
|
19 |
if (Utils.isIterable(textRegion.textLines) && textRegion.textLines.length !== 0) { |
|
20 |
for (const textLine of textRegion.textLines) { |
|
21 |
if (Utils.isIterable(textLine.textWords) && textLine.textWords.length !== 0) { |
|
22 |
for (const textWord of textLine.textWords) { |
|
23 |
if (textWord !== null) { |
|
24 |
// print words |
|
25 |
this.draw(textWord.wordCoords.points, canvasContext); |
|
26 |
this.LOGGER.info('printing words'); |
|
27 | 27 |
} |
28 |
return; |
|
29 |
} else { |
|
30 |
// print lines |
|
31 |
this.draw(textLine.lineCoords.points, canvasContext); |
|
32 |
this.LOGGER.info('Print lines'); |
|
33 | 28 |
} |
29 |
return; |
|
30 |
} else { |
|
31 |
// print lines |
|
32 |
this.draw(textLine.lineCoords.points, canvasContext); |
|
33 |
this.LOGGER.info('Print lines'); |
|
34 | 34 |
} |
35 |
return; |
|
36 |
} else { |
|
37 |
// all region |
|
38 |
this.draw(textRegion.regionCoords.points, canvasContext); |
|
39 |
this.LOGGER.info('Print region'); |
|
40 | 35 |
} |
36 |
return; |
|
41 | 37 |
} else { |
42 |
// all document
|
|
43 |
// TODO : obarvit celý výřez
|
|
44 |
this.LOGGER.warn('Print all document');
|
|
38 |
// all region
|
|
39 |
this.draw(textRegion.regionCoords.points, canvasContext);
|
|
40 |
this.LOGGER.info('Print region');
|
|
45 | 41 |
} |
46 | 42 |
} |
47 | 43 |
|
48 |
private initCanvas(imageId: string, canvasId: string) { |
|
44 |
private initCanvas(imageId: string, canvasId: string, originalImageSize: DocumentSize) {
|
|
49 | 45 |
const img = document.getElementById(imageId); |
50 | 46 |
const canvasElement = document.getElementById(canvasId); |
51 | 47 |
const canvas = <HTMLCanvasElement> document.getElementById(canvasId); |
... | ... | |
60 | 56 |
ctx.canvas.width = img.offsetWidth; |
61 | 57 |
ctx.canvas.height = img.offsetHeight; |
62 | 58 |
|
59 |
this.countRatio(originalImageSize, new DocumentSize(img.offsetHeight, img.offsetWidth)); |
|
60 |
|
|
63 | 61 |
return ctx; |
64 | 62 |
} |
65 | 63 |
|
... | ... | |
69 | 67 |
|
70 | 68 |
for (const point of points) { |
71 | 69 |
if (firstPoint) { |
72 |
context.moveTo(point.x / 1.676, point.y / 1.676);
|
|
70 |
context.moveTo(point.x / this.resizeRation, point.y / this.resizeRation);
|
|
73 | 71 |
firstPoint = false; |
74 | 72 |
} else { |
75 |
context.lineTo(point.x / 1.676, point.y / 1.676);
|
|
73 |
context.lineTo(point.x / this.resizeRation, point.y / this.resizeRation);
|
|
76 | 74 |
} |
77 | 75 |
} |
78 | 76 |
context.closePath(); |
... | ... | |
83 | 81 |
context.fill(); |
84 | 82 |
context.stroke(); |
85 | 83 |
} |
84 |
|
|
85 |
private countRatio(originalSize: DocumentSize, shownSize: DocumentSize) { |
|
86 |
this.resizeRation = originalSize.width / shownSize.width; |
|
87 |
} |
|
86 | 88 |
} |
Také k dispozici: Unified diff
Re #7820: Vykreslení rámečku do výřezu dokumentu
- posunutí koordinátů dle výpočtu (originální/zobrazená velikost)
- genererování náhodného id na BE
- přijmutí náhodného id na FE a nastaveno jako id pro výsledky