// Ported from https://github.com/kiwi515/ogws/blob/master/src/nw4r/ut/ut_TagProcessorBase.cpp #include "nw4r/ut.h" namespace nw4r { namespace ut { template TagProcessorBase::TagProcessorBase() {} template TagProcessorBase::~TagProcessorBase() {} template Operation TagProcessorBase::Process(u16 ch, PrintContext *ctx) { switch (ch) { case '\n': ProcessLinefeed(ctx); return OPERATION_NEXT_LINE; case '\t': ProcessTab(ctx); return OPERATION_NO_CHAR_SPACE; } return OPERATION_DEFAULT; } template Operation TagProcessorBase::CalcRect(Rect *rect, u16 ch, PrintContext *ctx) { switch (ch) { case '\n': { const TextWriterBase &writer = *ctx->writer; rect->right = writer.GetCursorX(); rect->top = writer.GetCursorY(); ProcessLinefeed(ctx); rect->left = writer.GetCursorX(); rect->bottom = writer.GetCursorY() + ctx->writer->GetFontHeight(); rect->Normalize(); return OPERATION_NEXT_LINE; } case '\t': { const TextWriterBase &writer = *ctx->writer; rect->left = writer.GetCursorX(); ProcessTab(ctx); rect->right = writer.GetCursorX(); rect->top = writer.GetCursorY(); rect->bottom = rect->top + writer.GetFontHeight(); rect->Normalize(); return OPERATION_NO_CHAR_SPACE; } } return OPERATION_DEFAULT; } template void TagProcessorBase::ProcessTab(PrintContext *ctx) { TextWriterBase &writer = *ctx->writer; int tabWidth = writer.GetTabWidth(); if (tabWidth <= 0) { return; } f32 charWidth = writer.IsWidthFixed() ? writer.GetFixedWidth() : writer.GetFontWidth(); f32 dx = writer.GetCursorX() - ctx->x; f32 tabPixel = tabWidth * charWidth; int numTab = static_cast(dx / tabPixel) + 1; f32 x = ctx->x + (tabPixel * numTab); writer.SetCursorX(x); } template void TagProcessorBase::ProcessLinefeed(PrintContext *ctx) { TextWriterBase &writer = *ctx->writer; f32 x = ctx->x; f32 y = writer.GetCursorY() + writer.GetLineHeight(); writer.SetCursorX(x); writer.SetCursorY(y); } template class TagProcessorBase; template class TagProcessorBase; } // namespace ut } // namespace nw4r