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

#include <touchgfx/TypedText.hpp>
<% get_font_class_names.each do |name| %>
#include <fonts/<%= name %>.hpp>
<% end %>
#include <texts/TypedTextDatabase.hpp>

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

const touchgfx::Font* touchgfx_fonts[] = {
<% if get_fonts.empty? %>
    0
<% else %>
<%   get_fonts.each_with_index do |font, index| %>
    &(<%= font %>())<%= index == get_fonts.length-1 ? '' : ',' %>
<%   end %>
<% end %>
};

<% 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 = {
<%   get_layouts.each do |layout| %>
<%     get_typed_texts(layout).each_with_index do |entry, index| %>
    0<%= ((index == get_typed_texts(layout).length-1) ? '': ',') %>
<%     end %>
<%     break %>
<%   end %>
};

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

TEXT_LOCATION_FLASH_PRAGMA
const touchgfx::TypedText::TypedTextData typedText_database_EMPTY[] TEXT_LOCATION_FLASH_ATTRIBUTE = {
<%   get_layouts.each do |layout| %>
<%     get_typed_texts(layout).each_with_index do |entry, index| %>
    <%= ('{ 0, touchgfx::LEFT, touchgfx::TEXT_DIRECTION_LTR }').to_s %><%= ((index == get_typed_texts(layout).length-1) ? '': ',') %>
<%     end %>
<%     break %>
<%   end %>
};
<% else %>
<%   get_layouts.each do |layout| %>
TEXT_LOCATION_FLASH_PRAGMA
const touchgfx::TypedText::TypedTextData typedText_database_<%= layout %>[] TEXT_LOCATION_FLASH_ATTRIBUTE = {
<%     if get_typed_texts(layout).empty? %>
    { 0, touchgfx::LEFT, touchgfx::TEXT_DIRECTION_LTR }
<%     else %>
<%       get_typed_texts(layout).each_with_index do |typed_text, index| %>
<%         fontIdx = get_font_index(typed_text.typography) %>
<%         alignment = get_touchgfx_aligment(typed_text.alignment) %>
<%         direction = get_touchgfx_direction(typed_text.direction) %>
    { <%= fontIdx %>, <%= alignment %>, <%= direction %> }<%= index == get_typed_texts(layout).length-1 ? '' : ',' %>
<%       end %>
<%     end %>
};
<%   end %>
<% end %>

TEXT_LOCATION_FLASH_PRAGMA
const touchgfx::TypedText::TypedTextData* const typedTextDatabaseArray[] TEXT_LOCATION_FLASH_ATTRIBUTE = {
<% if generate_binary_files? %>
<%   get_languages.each_with_index do |entry,index| %>
    typedText_database_EMPTY<%= index == get_languages.length-1 ? '' : ',' %>
<%   end %>
<% elsif languages.empty? %>
    typedText_database_DEFAULT
<% else %>
<%   get_languages.each_with_index do |language, index| %>
    typedText_database_<%= get_layouts.find { |l| l == language } || 'DEFAULT' %><%= index == get_languages.length-1 ? '' : ',' %>
<%   end %>
<% end %>
};

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

uint16_t getInstanceSize()
{
<% if has_text_entries? %>
<%   if generate_binary_files? %>
    return sizeof(typedText_database_EMPTY) / sizeof(touchgfx::TypedText::TypedTextData);
<%   else %>
    return sizeof(typedText_database_DEFAULT) / sizeof(touchgfx::TypedText::TypedTextData);
<%   end %>
<% else %>
    return 0;
<% 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 !get_fonts.empty? %>
    switch (fontId)
    {
<%   get_fonts.each_with_index do |font, index| %>
    case <%= index %>:
        touchgfx_fonts[<%= index %>] = &(<%= font %>());
        break;
<%   end %>
    }
<% end %>
}
} // namespace TypedTextDatabase
