1 /*
2 * Copyright (c) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "texgine_canvas.h"
17
18 namespace OHOS {
19 namespace Rosen {
20 namespace TextEngine {
DrawLine(double x0,double y0,double x1,double y1,const TexginePaint & paint)21 void TexgineCanvas::DrawLine(double x0, double y0, double x1, double y1, const TexginePaint &paint)
22 {
23 if (canvas_ == nullptr) {
24 return;
25 }
26
27 canvas_->drawLine(x0, y0, x1, y1, paint.GetPaint());
28 }
29
DrawRect(const TexgineRect & rect,const TexginePaint & paint) const30 void TexgineCanvas::DrawRect(const TexgineRect &rect, const TexginePaint &paint) const
31 {
32 if (canvas_ == nullptr || rect.GetRect() == nullptr) {
33 return;
34 }
35 canvas_->drawRect(*rect.GetRect(), paint.GetPaint());
36 }
37
DrawTextBlob(const std::shared_ptr<TexgineTextBlob> & blob,float x,float y,const TexginePaint & paint)38 void TexgineCanvas::DrawTextBlob(
39 const std::shared_ptr<TexgineTextBlob> &blob, float x, float y, const TexginePaint &paint)
40 {
41 if (canvas_ == nullptr || blob == nullptr) {
42 return;
43 }
44
45 canvas_->drawTextBlob(blob->GetTextBlob(), x, y, paint.GetPaint());
46 }
47
Clear(uint32_t color) const48 void TexgineCanvas::Clear(uint32_t color) const
49 {
50 if (canvas_ == nullptr) {
51 return;
52 }
53
54 canvas_->clear(color);
55 }
56
Save() const57 int TexgineCanvas::Save() const
58 {
59 if (canvas_ == nullptr) {
60 // 1 is failed
61 return 1;
62 }
63
64 return canvas_->save();
65 }
66
Translate(float dx,float dy) const67 void TexgineCanvas::Translate(float dx, float dy) const
68 {
69 if (canvas_ == nullptr) {
70 return;
71 }
72
73 canvas_->translate(dx, dy);
74 }
75
GetCanvas() const76 SkCanvas *TexgineCanvas::GetCanvas() const
77 {
78 return canvas_;
79 }
80
Restore() const81 void TexgineCanvas::Restore() const
82 {
83 if (canvas_ == nullptr) {
84 return;
85 }
86
87 canvas_->restore();
88 }
89
SetCanvas(SkCanvas * canvas)90 void TexgineCanvas::SetCanvas(SkCanvas *canvas)
91 {
92 canvas_ = canvas;
93 }
94 } // namespace TextEngine
95 } // namespace Rosen
96 } // namespace OHOS
97