1 /*
2 * Copyright (C) 2022 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 "accessibility_caption_parcel.h"
17 #include "hilog_wrapper.h"
18 #include "parcel_util.h"
19
20 namespace OHOS {
21 namespace Accessibility {
CaptionPropertyParcel(const CaptionProperty & property)22 CaptionPropertyParcel::CaptionPropertyParcel(const CaptionProperty &property)
23 {
24 HILOG_DEBUG();
25
26 AccessibilityConfig::CaptionProperty *self = this;
27 *self = property;
28 }
29
ReadFromParcel(Parcel & parcel)30 bool CaptionPropertyParcel::ReadFromParcel(Parcel& parcel)
31 {
32 HILOG_DEBUG();
33 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, fontFamily_);
34 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, fontScale_);
35 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, fontColor_);
36 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, fontEdgeType_);
37 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, backgroundColor_);
38 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, windowColor_);
39
40 return true;
41 }
42
Marshalling(Parcel & parcel) const43 bool CaptionPropertyParcel::Marshalling(Parcel& parcel) const
44 {
45 HILOG_DEBUG();
46 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, fontFamily_);
47 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, fontScale_);
48 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, fontColor_);
49 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, fontEdgeType_);
50 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, backgroundColor_);
51 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, windowColor_);
52
53 return true;
54 }
55
Unmarshalling(Parcel & parcel)56 sptr<CaptionPropertyParcel> CaptionPropertyParcel::Unmarshalling(Parcel& parcel)
57 {
58 HILOG_DEBUG();
59 sptr<CaptionPropertyParcel> captionProperty = new(std::nothrow) CaptionPropertyParcel();
60 if (!captionProperty) {
61 HILOG_ERROR("Failed to create captionProperty.");
62 return nullptr;
63 }
64 if (!captionProperty->ReadFromParcel(parcel)) {
65 HILOG_ERROR("read from parcel failed");
66 return nullptr;
67 }
68 return captionProperty;
69 }
70 } // namespace Accessibility
71 } // namespace OHOS