/* DO NOT EDIT THIS FILE */
/* This file is autogenerated by the text-database code generator */

#include <touchgfx/TypedText.hpp>
#include <fonts/<%= font_class_name%>.hpp>
#include <texts/TypedTextDatabase.hpp>

<% fonts.each do |font| %>
extern touchgfx::<%= font_class_name%>& <%= font%>();
<% end %>

const touchgfx::Font* touchgfx_fonts[] =
{
<% if fonts.empty? %>
    0
<% end %>
<%= fonts.map { |font| "    &(#{font}())" } * ",\n"
%>
};

<% if generate_binary_files? %>
extern const touchgfx::TypedText::TypedTextData typedText_database_EMPTY[];
<% else %>
extern const touchgfx::TypedText::TypedTextData typedText_database_DEFAULT[];
<% end %>
extern const touchgfx::TypedText::TypedTextData* const typedTextDatabaseArray[];

<% if generate_binary_files? %>
TEXT_LOCATION_FLASH_PRAGMA
KEEP extern const touchgfx::Unicode::UnicodeChar EmptyLanguageTexts[] TEXT_LOCATION_FLASH_ATTRIBUTE =
{
<% layouts.each do |layout| %>
<% typed_texts(layout).each_with_index do |entry, index| %>
    <%= '0' << ((index==typed_texts(layout).length-1) ? ' ': ',') %>
<% end %>
<% break %>
<% end %>
};

TEXT_LOCATION_FLASH_PRAGMA
KEEP extern const uint32_t EmptyLanguageIndices[] TEXT_LOCATION_FLASH_ATTRIBUTE =
{
<% layouts.each do |layout| %>
<% index_acc = 0 %><% typed_texts(layout).each_with_index do |entry, index| %>
    <%= index_acc.to_s << ((index==typed_texts(layout).length-1) ? ' ': ',') %><% index_acc += 1 %>
<% end %>
<% break %>
<% end %>
};

TEXT_LOCATION_FLASH_PRAGMA
const touchgfx::TypedText::TypedTextData typedText_database_EMPTY[] TEXT_LOCATION_FLASH_ATTRIBUTE =
{
<% layouts.each do |layout| %>
<% typed_texts(layout).each_with_index do |entry, index| %>
    <%= ('{ 0, touchgfx::LEFT, touchgfx::TEXT_DIRECTION_LTR }').to_s << ((index==typed_texts(layout).length-1) ? ' ': ',') %>
<% end %>
<% break %>
<% end %>
};
<% else %>
<% layouts.each do |layout| %>
TEXT_LOCATION_FLASH_PRAGMA
const touchgfx::TypedText::TypedTextData typedText_database_<%= layout %>[] TEXT_LOCATION_FLASH_ATTRIBUTE =
{
<% if typed_texts(layout).empty?%>
    { 0, touchgfx::LEFT, touchgfx::TEXT_DIRECTION_LTR }
<% end %>
<%= typed_texts(layout).map { |typed_text|
     fontIdx = fontmap["getFont_#{typed_text.typography.cpp_name}_#{typed_text.typography.font_size}_#{typed_text.typography.bpp}bpp"]
     alignment = "touchgfx::#{typed_text.alignment.upcase}"
     direction = "touchgfx::TEXT_DIRECTION_#{typed_text.direction.upcase}"
     "    { #{fontIdx}, #{alignment}, #{direction} }"
   } * ",\n"
%>
};
<% end %>
<% end %>

TEXT_LOCATION_FLASH_PRAGMA
const touchgfx::TypedText::TypedTextData* const typedTextDatabaseArray[] TEXT_LOCATION_FLASH_ATTRIBUTE =
{
<% if generate_binary_files? %>
<% text_entries.languages.each_with_index do |entry,index| %>
<% if (index==text_entries.languages.length-1) %>
    typedText_database_EMPTY
<% else %>
    typedText_database_EMPTY,
<% end %>
<% end %>
<% else %>
<% if text_entries.languages.empty? %>
    typedText_database_DEFAULT
<% end %>
<%= text_entries.languages.map { |language|
      "    typedText_database_#{layouts.find { |l| l == language } || 'DEFAULT'}"
    } * ",\n"
%>
<% end %>
};

namespace TypedTextDatabase
{
const touchgfx::TypedText::TypedTextData* getInstance(touchgfx::LanguageId id)
{
    return typedTextDatabaseArray[id];
}

uint16_t getInstanceSize()
{
<% if generate_binary_files? %>
    return sizeof(typedText_database_EMPTY) / sizeof(touchgfx::TypedText::TypedTextData);
<% else %>
    return sizeof(typedText_database_DEFAULT) / sizeof(touchgfx::TypedText::TypedTextData);
<% end %>
}

const touchgfx::Font** getFonts()
{
    return touchgfx_fonts;
}

const touchgfx::Font* setFont(touchgfx::FontId fontId, const touchgfx::Font* font)
{
    const touchgfx::Font* old = touchgfx_fonts[fontId];
    touchgfx_fonts[fontId] = font;
    return old;
}

void resetFont(touchgfx::FontId fontId)
{
<% if fonts.empty? %>
    return;
<% else %>
    switch (fontId)
    {
<% fonts.each_with_index do |font, index| %>
    case <%= index %>:
        touchgfx_fonts[<%= index %>] = &(<%= font %>());
        break;
<% end %>
    }
<% end %>
}
}  // namespace TypedTextDatabase
