view libclient/malikania/font.hpp @ 36:9af360f34c7d

Misc: use raw duktape API
author David Demelier <markand@malikania.fr>
date Wed, 10 Aug 2016 14:30:51 +0200
parents d4f5f7231b84
children a47a4477f347
line wrap: on
line source

/*
 * font.hpp -- font object
 *
 * Copyright (c) 2013-2016 Malikania Authors
 *
 * Permission to use, copy, modify, and/or distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#ifndef MALIKANIA_FONT_HPP
#define MALIKANIA_FONT_HPP

/**
 * \file Font.hpp
 * \brief Fonts.
 */

#include <memory>
#include <string>

#include "size.hpp"

namespace malikania {

/**
 * \class Font
 * \brief Font object.
 */
class Font {
private:
    class Backend;

    std::unique_ptr<Backend> m_backend;
    unsigned m_size;

public:
    /**
     * Construct a font from binary data.
     *
     * \param data the raw data
     * \param size the size
     */
    Font(std::string data, unsigned size);

    /**
     * Default move constructor.
     *
     * \param other the other font
     */
    Font(Font &&other) noexcept;

    /**
     * Default destructor.
     */
    virtual ~Font() noexcept;

    /**
     * Get the font size.
     *
     * \return the font size
     */
    inline unsigned size() const noexcept
    {
        return m_size;
    }

    /**
     * Get the underlying backend.
     *
     * \return the backend
     */
    inline const Backend &backend() const noexcept
    {
        return *m_backend;
    }

    /**
     * Overloaded function.
     *
     * \return the backend
     */
    inline Backend &backend() noexcept
    {
        return *m_backend;
    }

    /**
     * Get the clipping size required to draw the given text.
     *
     * \param text the text to clip
     * \return the required size
     */
    Size clip(const std::string &text) const;

    /**
     * Default move assignment operator.
     *
     * \param other the other font
     * \return this
     */
    Font &operator=(Font &&other) noexcept;
};

} // !malikania

#endif // MALIKANIA_FONT_HPP