resource.h
Go to the documentation of this file.
1 /****
2  * resource.h
3  *
4  * Copyright 2021 mikee47 <mike@sillyhouse.net>
5  *
6  * This file is part of the Sming-Graphics Library
7  *
8  * This library is free software: you can redistribute it and/or modify it under the terms of the
9  * GNU General Public License as published by the Free Software Foundation, version 3 or later.
10  *
11  * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
12  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13  * See the GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along with this library.
16  * If not, see <https://www.gnu.org/licenses/>.
17  *
18  * @author: May 2021 - mikee47 <mike@sillyhouse.net>
19  *
20  ****/
21 
22 #pragma once
23 
24 #include <FlashString/String.hpp>
25 #include "Types.h"
26 
27 namespace Graphics
28 {
29 namespace Resource
30 {
34 struct GlyphResource {
35  enum class Flag {
36  alpha,
37  };
39 
41  uint8_t width;
42  uint8_t height;
43  int8_t xOffset;
44  int8_t yOffset;
46  Flags flags;
47 
48  GlyphMetrics getMetrics() const
49  {
50  return GlyphMetrics{
51  .width = width,
52  .height = height,
53  .xOffset = xOffset,
54  .yOffset = yOffset,
55  .advance = xAdvance,
56  };
57  }
58 };
59 
63 struct GlyphBlock {
66 
67  uint16_t first() const
68  {
69  return codePoint;
70  }
71 
72  uint16_t last() const
73  {
74  return codePoint + length - 1;
75  }
76 
77  bool contains(uint16_t cp) const
78  {
79  return cp >= first() && cp <= last();
80  }
81 };
82 
83 struct TypefaceResource {
84  uint32_t bmOffset;
85  uint8_t style;
89  const GlyphResource* glyphs;
90  const GlyphBlock* blocks;
91 };
92 
93 struct FontResource {
94  const FSTR::String* name;
98  const TypefaceResource* faces[4]; // normal, italic, bold, boldItalic
99 
100  static const FontResource& empty()
101  {
102  static FontResource fontEmpty{};
103  return fontEmpty;
104  }
105 
106  explicit operator bool() const
107  {
108  return name != nullptr;
109  }
110 };
111 
112 struct ImageResource {
113  const FSTR::String* name;
114  uint32_t bmOffset;
115  uint32_t bmSize;
116  uint16_t width;
119 
120  Size getSize() const
121  {
123  }
124 
126  {
128  }
129 };
130 
131 } // namespace Resource
132 } // namespace Graphics
int8_t xOffset
X dist from cursor pos to UL corner.
Definition: resource.h:100
uint32_t bmOffset
Definition: resource.h:152
uint16_t first() const
Definition: resource.h:105
describes a counted string stored in flash memory
Definition: String.hpp:173
uint8_t yAdvance
Definition: resource.h:124
const TypefaceResource * faces[4]
Definition: resource.h:136
Flags flags
Definition: resource.h:103
uint16_t length
Number of consecutive characters.
Definition: resource.h:103
Flag
Definition: resource.h:92
uint16_t codePoint
First character code.
Definition: resource.h:102
const GlyphBlock * blocks
Definition: resource.h:128
Size getSize() const
Definition: resource.h:158
uint8_t yAdvance
Definition: resource.h:133
Definition: resource.h:131
Definition: resource.h:121
Size of rectangular area (width x height)
Definition: Libraries/Graphics/src/include/Graphics/Types.h:124
Definition: Virtual.h:30
uint8_t descent
Definition: resource.h:134
uint8_t xAdvance
Distance to advance cursor (x axis)
Definition: resource.h:102
uint8_t height
Bitmap dimensions in pixels.
Definition: resource.h:99
uint8_t padding[2]
Definition: resource.h:135
BitSet< uint8_t, Flag, 1 > Flags
Definition: resource.h:95
int8_t yOffset
Y dist from cursor pos to UL corner.
Definition: resource.h:101
std::enable_if< sizeof(T)==1, T >::type readValue(const T *ptr)
Read a typed value from flash memory ensuring correct alignment of access.
Definition: Utility.hpp:126
PixelFormat getFormat() const
Definition: resource.h:163
uint8_t style
Definition: resource.h:123
uint8_t width
Width of glyph.
Definition: Libraries/Graphics/src/include/Graphics/Types.h:858
const FSTR::String * name
Definition: resource.h:151
static const FontResource & empty()
Definition: resource.h:138
PixelFormat
Definition: Colors.h:295
uint16_t bmOffset
Offset relative to TypefaceResource::bmpOffset.
Definition: resource.h:97
uint8_t width
Bitmap dimensions in pixels.
Definition: resource.h:98
uint16_t width
Definition: resource.h:154
uint16_t height
Definition: resource.h:155
const FSTR::String * name
Definition: resource.h:132
const GlyphResource * glyphs
Definition: resource.h:127
uint32_t bmOffset
Start of bitmap data in resource stream.
Definition: resource.h:122
GlyphMetrics getMetrics() const
Definition: resource.h:105
PixelFormat format
Definition: resource.h:156
uint32_t bmSize
Definition: resource.h:153
bool contains(uint16_t cp) const
Definition: resource.h:115
uint16_t last() const
Definition: resource.h:110
uint8_t numBlocks
Definition: resource.h:126
Definition: resource.h:150
uint8_t descent
Definition: resource.h:125