-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpagepc.tsx
150 lines (96 loc) · 3.89 KB
/
pagepc.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import React, { useState } from 'react';
import { Button, View, StyleSheet, ScrollView } from 'react-native';
import { Paragraph, Skia, useFonts, TextAlign, Canvas, Circle, Group, useFont, Text, TextBlob, Rect, TextHeightBehavior, SkCanvas, SkPaint, useCanvasRef, Image, SkiaPictureView, createPicture, PaintStyle, BlendMode, Path } from "@shopify/react-native-skia";
import { quranTextService, PAGE_WIDTH, FONTSIZE, MARGIN, INTERLINE } from './qurantext.service'
import Line from './line';
import { PreCalulatedLayout, usePreCalulatedLayout } from './precalculated.service';
type PageProps = {
pageWidth: number;
fontSize: number;
index: number;
};
const PagePC = (props: PageProps) => {
const preCalulatedLayout = usePreCalulatedLayout();
const ref = useCanvasRef();
if (!preCalulatedLayout) {
return null;
}
const pageIndex = props.index;
const pageWidth = props.pageWidth
const scale = pageWidth / PAGE_WIDTH;
const margin = MARGIN * scale;
const interLine = INTERLINE * scale
const pageHeight = 15 * interLine + (300 * scale);
let yPos = -200 * scale;
let paint: SkPaint = Skia.Paint()
paint.setStyle(PaintStyle.Fill);
paint.setAntiAlias(true)
//paint.setBlendMode(BlendMode.Multiply);
/*
const paths = preCalulatedLayout.getOutlines(58173, 0, 0)
return (
<ScrollView contentContainerStyle={styles.page}>
<Canvas style={{ width: pageWidth, height: pageHeight }}>
<Path path={paths[0].path} transform={[{ translateX: pageWidth - 3000 * scale }, { translateY: 800 * scale },{ scaleX: scale }, { scaleY: -scale }]}>
</Path>
</Canvas>
</ScrollView>
);*/
const pagePicture = createPicture((canvas) => {
canvas.clear(Skia.Color("transparent"));
drawPage(preCalulatedLayout, canvas, paint, props.index, pageWidth)
})
return (
<ScrollView contentContainerStyle={styles.page}>
<SkiaPictureView style={{ width: pageWidth, height: pageHeight }} picture={pagePicture} />
</ScrollView>
);
};
function drawPage(preCalulatedLayout: PreCalulatedLayout, canvas: SkCanvas, paint: SkPaint, pageIndex: number, pageWidth: number) {
const fontSizeScale: number = 1.0;
const scale: number = pageWidth / (17000)
const x_start: number = pageWidth - 400 * scale
const inter_line = INTERLINE * scale
let y_start = inter_line * 0.72
if (pageIndex === 0 || pageIndex === 1) {
y_start = y_start + 3.5 * inter_line
}
const page = preCalulatedLayout.getPage(pageIndex)
for (let l = 0; l < page.getLinesList().length; l++) {
const line = page.getLinesList()[l]
canvas.save()
const x = x_start - line.getX() * scale
canvas.translate(x, y_start + l * inter_line)
canvas.scale(scale, -scale)
for (const glyph of line.getGlyphsList()) {
canvas.translate(-glyph.getXAdvance(), 0.0)
canvas.translate(glyph.getXOffset(), glyph.getYOffset())
const paths = preCalulatedLayout.getOutlines(glyph.getCodepoint(), glyph.getLefttatweel(), glyph.getRighttatweel())
let glyphColor = Skia.Color("black")
if (glyph.hasColor()) {
const color = glyph.getColor()
const red = (color >> 24) & 0xff
const green = (color >> 16) & 0xff
const blue = (color >> 8) & 0xff
glyphColor = Float32Array.from([red / 255, green / 255, blue / 255])
}
for (const path of paths) {
const color = path.color
if (color) {
paint.setColor(color)
} else {
paint.setColor(glyphColor)
}
canvas.drawPath(path.path, paint)
}
canvas.translate(-glyph.getXOffset(), -glyph.getYOffset())
}
canvas.restore()
}
}
const styles = StyleSheet.create({
page: {
backgroundColor: "rgb(255, 255, 255)",
},
});
export default PagePC;