Files
ppsspp/Common/Render/Text/draw_text_android.h
T
Henrik RydgårdandClaude Opus 5.5 dc1e9e50fc TextDrawer: Measure in a given style without switching fonts
Measuring took the current font and scale, so UIContext switched to the
style being measured and back. On first draw the font to switch back to
could be an empty one, which the UWP drawer asserts on.

MeasureString and MeasureStringRect now take the style and scale, and the
backends' MeasureStringInternal measures in the style it's given.
SetOrCreateFont, which sets the font drawing uses, is shared, and the
backends only implement EnsureFont, which creates a font if needed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 11:45:04 +01:00

45 lines
1.1 KiB
C++

#pragma once
#include "ppsspp_config.h"
#include <map>
#include "Common/Render/Text/draw_text.h"
#if PPSSPP_PLATFORM(ANDROID)
#include <jni.h>
struct AndroidFontEntry {
int font;
float size;
};
class TextDrawerAndroid : public TextDrawer {
public:
TextDrawerAndroid(Draw::DrawContext *draw);
~TextDrawerAndroid();
bool IsReady() const override;
bool DrawStringBitmap(std::vector<uint8_t> &bitmapData, TextStringEntry &entry, Draw::DataFormat texFormat, std::string_view str, int align, bool fullColor) override;
protected:
void EnsureFont(const FontStyle &style) override;
void MeasureStringInternal(const FontStyle &style, std::string_view str, float *w, float *h) override;
bool SupportsColorEmoji() const override { return true; }
void ClearFonts() override;
private:
// JNI functions
jclass cls_textRenderer = nullptr;
jmethodID method_allocFont = nullptr;
jmethodID method_freeAllFonts = nullptr;
jmethodID method_measureText = nullptr;
jmethodID method_renderText = nullptr;
std::map<FontStyle, AndroidFontEntry> fontMap_;
std::map<std::string, int> allocatedFonts_;
};
#endif