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