#!/usr/bin/python3
# coding: utf-8

# Copyright (C) 2017-present Robert Griesel
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>

import sys, os.path, gettext

from lemma.infrastructure.font_manager import FontManager
from lemma.infrastructure.service_locator import ServiceLocator
import lemma.workspace.workspace as workspace
import lemma.ui.application as application
import lemma.storage.storage as storage

# setup gettext
gettext.install('lemma', names=('ngettext',), localedir='/usr/share/locale')

# get settings
settings = ServiceLocator.get_settings()

# init static variables
ServiceLocator.init_lemma_version('15')
ServiceLocator.init_resources_path('/usr/share/Lemma/resources')

# setup fonts
font_path = os.path.join(ServiceLocator.get_resources_path(), 'fonts')
FontManager.add_font('book', os.path.join(font_path, 'newcomputermodern/otf/NewCM10-Book.otf'), size=19.407, line_height=28, ascend=19, descend=5)
FontManager.add_font('bold', os.path.join(font_path, 'newcomputermodern/otf/NewCM10-Bold.otf'), size=19.407, line_height=28, ascend=19, descend=5)
FontManager.add_font('bolditalic', os.path.join(font_path, 'newcomputermodern/otf/NewCM10-BoldItalic.otf'), size=19.407, line_height=28, ascend=19, descend=5)
FontManager.add_font('italic', os.path.join(font_path, 'newcomputermodern/otf/NewCM10-Italic.otf'), size=19.407, line_height=28, ascend=19, descend=5)
FontManager.add_font('math', os.path.join(font_path, 'newcomputermodern/otf/NewCMMath-Book.otf'), size=19.407, line_height=28, ascend=19, descend=5)
FontManager.add_font('teaser', os.path.join(font_path, 'newcomputermodern/otf/NewCM08-Book.otf'), size=14, line_height=28, ascend=19, descend=5)

workspace = workspace.Workspace()

storage = storage.Storage(workspace)
storage.populate_documents()
storage.populate_workspace()
storage.init_writer()

view = application.Application(workspace)

exit_status = view.run(sys.argv)
sys.exit(exit_status)
