• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2018 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "mojo/public/cpp/base/logfont_win_mojom_traits.h"
6 
7 #include <tchar.h>
8 
9 #include "base/logging.h"
10 #include "base/numerics/safe_conversions.h"
11 
12 namespace mojo {
13 
14 // static
15 base::span<const uint8_t>
bytes(const::LOGFONT & input)16 StructTraits<mojo_base::mojom::LOGFONTDataView, ::LOGFONT>::bytes(
17     const ::LOGFONT& input) {
18   return base::make_span(reinterpret_cast<const uint8_t*>(&input),
19                          sizeof(::LOGFONT));
20 }
21 
22 // static
Read(mojo_base::mojom::LOGFONTDataView data,::LOGFONT * out)23 bool StructTraits<mojo_base::mojom::LOGFONTDataView, ::LOGFONT>::Read(
24     mojo_base::mojom::LOGFONTDataView data,
25     ::LOGFONT* out) {
26   ArrayDataView<uint8_t> bytes_view;
27   data.GetBytesDataView(&bytes_view);
28   if (bytes_view.size() != sizeof(::LOGFONT))
29     return false;
30 
31   const ::LOGFONT* font = reinterpret_cast<const ::LOGFONT*>(bytes_view.data());
32   if (_tcsnlen(font->lfFaceName, LF_FACESIZE) >= LF_FACESIZE)
33     return false;
34 
35   memcpy(out, font, sizeof(::LOGFONT));
36   return true;
37 }
38 
39 }  // namespace mojo
40