• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 "drawing_lattice_preview.h"
17 
18 #include "draw/core_canvas.h"
19 #include "lattice_napi/js_lattice.h"
20 
21 #include "base/image/drawing_lattice.h"
22 #include "base/utils/utils.h"
23 
24 namespace OHOS::Ace {
25 
26 #if defined(ACE_STATIC)
CreateDrawingLatticeFromAni(void * aniAddr)27 RefPtr<DrawingLattice> DrawingLattice::CreateDrawingLatticeFromAni(void* aniAddr)
28 {
29     return nullptr;
30 }
31 #endif
32 
CreateDrawingLattice(void * sptrAddr)33 RefPtr<DrawingLattice> DrawingLattice::CreateDrawingLattice(void* sptrAddr)
34 {
35     CHECK_NULL_RETURN(sptrAddr, nullptr);
36     auto* jsLattice = reinterpret_cast<OHOS::Rosen::Drawing::JsLattice*>(sptrAddr);
37     return AceType::MakeRefPtr<DrawingLatticePreview>(jsLattice->GetLattice());
38 }
39 
CreateDrawingLatticeFromNative(void * sptrAddr)40 RefPtr<DrawingLattice> DrawingLattice::CreateDrawingLatticeFromNative(void* sptrAddr)
41 {
42     CHECK_NULL_RETURN(sptrAddr, nullptr);
43     auto* lattice = reinterpret_cast<std::shared_ptr<OHOS::Rosen::Drawing::Lattice>*>(sptrAddr);
44     return AceType::MakeRefPtr<DrawingLatticePreview>(*lattice);
45 }
46 
GetDrawingLatticeSptrAddr()47 void* DrawingLatticePreview::GetDrawingLatticeSptrAddr()
48 {
49     return static_cast<void*>(&lattice_);
50 }
51 
DumpToString()52 std::string DrawingLatticePreview::DumpToString()
53 {
54     if (lattice_) {
55         std::string drawingConfigStr;
56         drawingConfigStr.append("fXCount = " + std::to_string(lattice_->fXCount));
57         drawingConfigStr.append("fXDivs = [");
58         for (int32_t idx = 0; idx < lattice_->fXCount; ++idx) {
59             drawingConfigStr.append(std::to_string(lattice_->fXDivs[idx]) + " ");
60         }
61         drawingConfigStr.append("] ");
62         drawingConfigStr.append("fYCount = " + std::to_string(lattice_->fYCount));
63         drawingConfigStr.append("fYDivs = [");
64         for (int32_t idx = 0; idx < lattice_->fYCount; ++idx) {
65             drawingConfigStr.append(std::to_string(lattice_->fYDivs[idx]) + " ");
66         }
67         drawingConfigStr.append("] ");
68         return drawingConfigStr;
69     }
70     return "Lattice is null";
71 }
72 } // namespace OHOS::Ace
73