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 : CaptionProperty(property)
24 {
25 }
26
ReadFromParcel(Parcel & parcel)27 bool CaptionPropertyParcel::ReadFromParcel(Parcel& parcel)
28 {
29 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, fontFamily_);
30 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, fontScale_);
31 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, fontColor_);
32 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, fontEdgeType_);
33 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, backgroundColor_);
34 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, windowColor_);
35
36 return true;
37 }
38
Marshalling(Parcel & parcel) const39 bool CaptionPropertyParcel::Marshalling(Parcel& parcel) const
40 {
41 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, fontFamily_);
42 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, fontScale_);
43 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, fontColor_);
44 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, fontEdgeType_);
45 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, backgroundColor_);
46 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, windowColor_);
47
48 return true;
49 }
50
Unmarshalling(Parcel & parcel)51 sptr<CaptionPropertyParcel> CaptionPropertyParcel::Unmarshalling(Parcel& parcel)
52 {
53 sptr<CaptionPropertyParcel> captionProperty = new(std::nothrow) CaptionPropertyParcel();
54 if (captionProperty == nullptr) {
55 HILOG_ERROR("Failed to create captionProperty.");
56 return nullptr;
57 }
58 if (!captionProperty->ReadFromParcel(parcel)) {
59 HILOG_ERROR("read from parcel failed");
60 return nullptr;
61 }
62 return captionProperty;
63 }
64 } // namespace Accessibility
65 } // namespace OHOS