mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-24 10:12:25 -05:00
LibDraw: Introduce an Emoji class
This class can locate and load emojis, which are expected to be stored as regular PNG images at /res/emoji/U+XXXX.png, where XXXX is the character codepoint. https://github.com/SerenityOS/serenity/issues/490
This commit is contained in:
parent
55197ed4ef
commit
9d64c60e01
Notes:
sideshowbarker
2024-07-19 12:16:13 +09:00
Author: https://github.com/bugaevc Commit: https://github.com/SerenityOS/serenity/commit/9d64c60e011 Pull-request: https://github.com/SerenityOS/serenity/pull/520 Reviewed-by: https://github.com/awesomekling
3 changed files with 48 additions and 1 deletions
27
Libraries/LibDraw/Emoji.cpp
Normal file
27
Libraries/LibDraw/Emoji.cpp
Normal file
|
@ -0,0 +1,27 @@
|
|||
#include "Emoji.h"
|
||||
#include "GraphicsBitmap.h"
|
||||
#include <AK/AKString.h>
|
||||
#include <AK/HashMap.h>
|
||||
|
||||
static HashMap<u32, Emoji> s_emojis;
|
||||
|
||||
Emoji::Emoji(NonnullRefPtr<GraphicsBitmap> bitmap)
|
||||
: m_bitmap(move(bitmap))
|
||||
{
|
||||
}
|
||||
|
||||
const Emoji* Emoji::emoji_for_codepoint(u32 codepoint)
|
||||
{
|
||||
auto it = s_emojis.find(codepoint);
|
||||
if (it != s_emojis.end())
|
||||
return &(*it).value;
|
||||
|
||||
String path = String::format("/res/emoji/U+%X.png", codepoint);
|
||||
|
||||
auto bitmap = GraphicsBitmap::load_from_file(path);
|
||||
if (!bitmap)
|
||||
return nullptr;
|
||||
|
||||
s_emojis.set(codepoint, Emoji { bitmap.release_nonnull() });
|
||||
return &(*s_emojis.find(codepoint)).value;
|
||||
}
|
19
Libraries/LibDraw/Emoji.h
Normal file
19
Libraries/LibDraw/Emoji.h
Normal file
|
@ -0,0 +1,19 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/Types.h>
|
||||
#include <AK/NonnullRefPtr.h>
|
||||
|
||||
class GraphicsBitmap;
|
||||
|
||||
class Emoji {
|
||||
public:
|
||||
~Emoji() {}
|
||||
|
||||
static const Emoji* emoji_for_codepoint(u32 codepoint);
|
||||
const GraphicsBitmap& bitmap() const { return m_bitmap; }
|
||||
|
||||
private:
|
||||
explicit Emoji(NonnullRefPtr<GraphicsBitmap>);
|
||||
|
||||
NonnullRefPtr<GraphicsBitmap> m_bitmap;
|
||||
};
|
|
@ -9,7 +9,8 @@ OBJS = \
|
|||
Painter.o \
|
||||
PNGLoader.o \
|
||||
Rect.o \
|
||||
StylePainter.o
|
||||
StylePainter.o \
|
||||
Emoji.o
|
||||
|
||||
LIBRARY = libdraw.a
|
||||
DEFINES += -DUSERLAND
|
||||
|
|
Loading…
Add table
Reference in a new issue