webgpu support
This commit is contained in:
parent
5352ef69a2
commit
dedf6b0467
22 changed files with 1656 additions and 324 deletions
|
|
@ -19,13 +19,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|||
*/
|
||||
|
||||
module;
|
||||
|
||||
#ifndef CRAFTER_GRAPHICS_WINDOW_DOM
|
||||
#include "../lib/stb_truetype.h"
|
||||
|
||||
#endif // !CRAFTER_GRAPHICS_WINDOW_DOM
|
||||
export module Crafter.Graphics:Font;
|
||||
#ifndef CRAFTER_GRAPHICS_WINDOW_DOM
|
||||
import std;
|
||||
|
||||
namespace Crafter {
|
||||
|
|
@ -36,7 +31,6 @@ namespace Crafter {
|
|||
if (i >= text.size()) return 0;
|
||||
std::uint8_t b0 = static_cast<std::uint8_t>(text[i]);
|
||||
|
||||
// Single-byte ASCII is the common path.
|
||||
if (b0 < 0x80) { ++i; return b0; }
|
||||
|
||||
int extra;
|
||||
|
|
@ -44,13 +38,13 @@ namespace Crafter {
|
|||
if ((b0 & 0xE0) == 0xC0) { extra = 1; cp = b0 & 0x1F; }
|
||||
else if ((b0 & 0xF0) == 0xE0) { extra = 2; cp = b0 & 0x0F; }
|
||||
else if ((b0 & 0xF8) == 0xF0) { extra = 3; cp = b0 & 0x07; }
|
||||
else { ++i; return 0xFFFD; } // continuation byte at start, or 5+-byte leader
|
||||
else { ++i; return 0xFFFD; }
|
||||
|
||||
++i;
|
||||
for (int k = 0; k < extra; ++k) {
|
||||
if (i >= text.size()) return 0xFFFD;
|
||||
std::uint8_t b = static_cast<std::uint8_t>(text[i]);
|
||||
if ((b & 0xC0) != 0x80) return 0xFFFD; // missing continuation
|
||||
if ((b & 0xC0) != 0x80) return 0xFFFD;
|
||||
cp = (cp << 6) | (b & 0x3Fu);
|
||||
++i;
|
||||
}
|
||||
|
|
@ -67,8 +61,7 @@ namespace Crafter {
|
|||
Font(const std::filesystem::path& font);
|
||||
std::uint32_t GetLineWidth(const std::string_view text, float size);
|
||||
float LineHeight(float size);
|
||||
float AscentPx(float size); // baseline offset from line-top
|
||||
float ScaleForSize(float size); // stb's pixel-units-per-em factor
|
||||
float AscentPx(float size);
|
||||
float ScaleForSize(float size);
|
||||
};
|
||||
}
|
||||
#endif // !CRAFTER_GRAPHICS_WINDOW_DOM
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue