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 { CreateDrawingLattice(void* sptrAddr)25RefPtr<DrawingLattice> DrawingLattice::CreateDrawingLattice(void* sptrAddr) 26 { 27 CHECK_NULL_RETURN(sptrAddr, nullptr); 28 auto* jsLattice = reinterpret_cast<OHOS::Rosen::Drawing::JsLattice*>(sptrAddr); 29 return AceType::MakeRefPtr<DrawingLatticePreview>(jsLattice->GetLattice()); 30 } 31 CreateDrawingLatticeFromNative(void* sptrAddr)32RefPtr<DrawingLattice> DrawingLattice::CreateDrawingLatticeFromNative(void* sptrAddr) 33 { 34 CHECK_NULL_RETURN(sptrAddr, nullptr); 35 auto* lattice = reinterpret_cast<std::shared_ptr<OHOS::Rosen::Drawing::Lattice>*>(sptrAddr); 36 return AceType::MakeRefPtr<DrawingLatticePreview>(*lattice); 37 } 38 GetDrawingLatticeSptrAddr()39void* DrawingLatticePreview::GetDrawingLatticeSptrAddr() 40 { 41 return static_cast<void*>(&lattice_); 42 } 43 DumpToString()44std::string DrawingLatticePreview::DumpToString() 45 { 46 if (lattice_) { 47 std::string drawingConfigStr; 48 drawingConfigStr.append("fXCount = " + std::to_string(lattice_->fXCount)); 49 drawingConfigStr.append("fXDivs = ["); 50 for (int32_t idx = 0; idx < lattice_->fXCount; ++idx) { 51 drawingConfigStr.append(std::to_string(lattice_->fXDivs[idx]) + " "); 52 } 53 drawingConfigStr.append("] "); 54 drawingConfigStr.append("fYCount = " + std::to_string(lattice_->fYCount)); 55 drawingConfigStr.append("fYDivs = ["); 56 for (int32_t idx = 0; idx < lattice_->fYCount; ++idx) { 57 drawingConfigStr.append(std::to_string(lattice_->fYDivs[idx]) + " "); 58 } 59 drawingConfigStr.append("] "); 60 return drawingConfigStr; 61 } 62 return "Lattice is null"; 63 } 64 } // namespace OHOS::Ace 65