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 "font_utils.h" 17 18 #include "drawing_text_font_descriptor.h" 19 20 namespace OHOS::Rosen::Drawing { CopyFontDescriptor(OH_Drawing_FontDescriptor * dst,const FontParser::FontDescriptor & src)21bool CopyFontDescriptor(OH_Drawing_FontDescriptor* dst, const FontParser::FontDescriptor& src) 22 { 23 if (dst == nullptr) { 24 return false; 25 } 26 dst->path = strdup(src.path.c_str()); 27 dst->postScriptName = strdup(src.postScriptName.c_str()); 28 dst->fullName = strdup(src.fullName.c_str()); 29 dst->fontFamily = strdup(src.fontFamily.c_str()); 30 dst->fontSubfamily = strdup(src.fontSubfamily.c_str()); 31 if (dst->path == NULL || dst->postScriptName == NULL || dst->fullName == NULL || dst->fontFamily == NULL || 32 dst->fontSubfamily == NULL) { 33 free(dst->path); 34 free(dst->postScriptName); 35 free(dst->fullName); 36 free(dst->fontFamily); 37 free(dst->fontSubfamily); 38 dst->path = nullptr; 39 dst->postScriptName = nullptr; 40 dst->fullName = nullptr; 41 dst->fontFamily = nullptr; 42 dst->fontSubfamily = nullptr; 43 return false; 44 } 45 dst->weight = src.weight; 46 dst->width = src.width; 47 dst->italic = src.italic; 48 dst->monoSpace = src.monoSpace; 49 dst->symbolic = src.symbolic; 50 return true; 51 } 52 } // namespace OHOS::Rosen::Drawing