xref: /aosp_15_r20/external/pdfium/core/fxge/text_glyph_pos.cpp (revision 3ac0a46f773bac49fa9476ec2b1cf3f8da5ec3a4)
1 // Copyright 2019 The PDFium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 
7 #include "core/fxge/text_glyph_pos.h"
8 
9 #include "core/fxcrt/fx_safe_types.h"
10 #include "core/fxge/cfx_glyphbitmap.h"
11 
12 TextGlyphPos::TextGlyphPos() = default;
13 
14 TextGlyphPos::TextGlyphPos(const TextGlyphPos&) = default;
15 
16 TextGlyphPos::~TextGlyphPos() = default;
17 
GetOrigin(const CFX_Point & offset) const18 absl::optional<CFX_Point> TextGlyphPos::GetOrigin(
19     const CFX_Point& offset) const {
20   FX_SAFE_INT32 left = m_Origin.x;
21   left += m_pGlyph->left();
22   left -= offset.x;
23   if (!left.IsValid())
24     return absl::nullopt;
25 
26   FX_SAFE_INT32 top = m_Origin.y;
27   top -= m_pGlyph->top();
28   top -= offset.y;
29   if (!top.IsValid())
30     return absl::nullopt;
31 
32   return CFX_Point(left.ValueOrDie(), top.ValueOrDie());
33 }
34