<commit_before>/*
 * THE UNICODE TEST SUITE FOR CINDER: https://github.com/arielm/Unicode
 * COPYRIGHT (C) 2013, <NAME> ALL RIGHTS RESERVED.
 *
 * THE FOLLOWING SOURCE-CODE IS DISTRIBUTED UNDER THE MODIFIED BSD LICENSE:
 * https://github.com/arielm/Unicode/blob/master/LICENSE.md
 */

#pragma once

#include "ActualFont.h"
#include "LineLayout.h"
#include "TextItemizer.h"

#include <set>
#include <map>

typedef std::vector<ActualFont*> FontSet;

class VirtualFont
{
public:
    typedef enum
    {
        STYLE_REGULAR,
        STYLE_BOLD,
        STYLE_ITALIC,
        STYLE_BOLD_ITALIC
    }
    Style;
    
    typedef enum
    {
        ALIGN_MIDDLE,
        ALIGN_LEFT,
        ALIGN_RIGHT,
        ALIGN_TOP,
        ALIGN_BASELINE,
        ALIGN_BOTTOM
    }
    Alignment;
    
    struct Key
    {
        std::string uri;
        float baseSize;
        bool useMipmap;
        
        Key(const std::string &uri, float baseSize, bool useMipmap)
        :
        uri(uri),
        baseSize(baseSize),
        useMipmap(useMipmap)
        {}
        
        bool operator<(const Key &rhs) const
        {
            return tie(uri, baseSize, useMipmap) < tie(rhs.uri, rhs.baseSize, rhs.useMipmap);
        }
    };
    
    TextItemizer &itemizer;
    float baseSize;
    
    VirtualFont(TextItemizer &itemizer, float baseSize);
    
    bool add(const std::string &lang, ActualFont *font);
    const FontSet& getFontSet(const std::string &lang) const;
    
    float getAscent(const LineLayout &layout) const;
    float getDescent(const LineLayout &layout) const;
    float getMiddleLine(const LineLayout &layout) const;
    
    float getOffsetX(const LineLayout &layout, Alignment align) const;
    float getOffsetY(const LineLayout &layout, Alignment align) const;

    float getAdvance(const LineLayout &layout) const;
    float getAdvance(const Cluster &cluster) const;

    ActualFont::Metrics getMetrics(const Cluster &cluster) const;
    ActualFont::Metrics getMetrics(const std::string &lang) const;

    /*
     * THE RETURNED LineLayout INSTANCES ARE NOT MANAGED AND SHOULD BE DELETED BY THE CALLER
     */
    LineLayout* createLineLayout(const std::string &text, const std::string &langHint = "", hb_direction_t overallDirection = HB_DIRECTION_INVALID);
    LineLayout* createLineLayout(const TextLine &line);
    
    void setSize(float size);
    void setColor(const ci::ColorA &color);
    
    void begin();
    void end();
    void drawCluster(const Cluster &cluster, const ci::Vec2f &position);

protected:
    float size;
    float sizeRatio;

    std::vector<ci::Vec2f> positions;
    std::vector<ci::Vec2f> coords;<commit_msg>Rendering PROJECT: TWEAKS AND DOCUMENTATION<commit_after>/*
 * THE UNICODE TEST SUITE FOR CINDER: https://github.com/arielm/Unicode
 * COPYRIGHT (C) 2013, <NAME> ALL RIGHTS RESERVED.
 *
 * THE FOLLOWING SOURCE-CODE IS DISTRIBUTED UNDER THE MODIFIED BSD LICENSE:
 * https://github.com/arielm/Unicode/blob/master/LICENSE.md
 */

#pragma once

#include "ActualFont.h"
#include "LineLayout.h"
#include "TextItemizer.h"

#include <set>
#include <map>

typedef std::vector<ActualFont*> FontSet;

class VirtualFont
{
public:
    typedef enum
    {
        STYLE_REGULAR,
        STYLE_BOLD,
        STYLE_ITALIC,
        STYLE_BOLD_ITALIC
    }
    Style;
    
    typedef enum
    {
        ALIGN_MIDDLE,
        ALIGN_LEFT,
        ALIGN_RIGHT,
        ALIGN_TOP,
        ALIGN_BASELINE,
        ALIGN_BOTTOM
    }
    Alignment;
    
    struct Key
    {
        std::string uri;
        float baseSize;
        bool useMipmap;
        
        Key(const std::string &uri, float baseSize, bool useMipmap)
        :
        uri(uri),
        baseSize(baseSize),
        useMipmap(useMipmap)
        {}
        
        bool operator<(const Key &rhs) const
        {
            return tie(uri, baseSize, useMipmap) < tie(rhs.uri, rhs.baseSize, rhs.useMipmap);
        }
    };
    
    TextItemizer &itemizer;
    float baseSize;
    
    VirtualFont(TextItemizer &itemizer, float baseSize);
    
    bool add(const std::string &lang, ActualFont *font);
    const FontSet& getFontSet(const std::string &lang) const;
    
    float getAscent(const LineLayout &layout) const;
    float getDescent(const LineLayout &layout) const;
    float getMiddleLine(const LineLayout &layout) const;
    
    float getOffsetX(const LineLayout &layout, Alignment align) const;
    float getOffsetY(const LineLayout &layout, Alignment align) const;

    float getAdvance(const LineLayout &layout) const;
    float getAdvance(const Cluster &cluster) const;

    ActualFont::Metrics getMetrics(const Cluster &cluster) const; // RETURNS THE SIZED METRICS OF THE ActualFont USED BY cluster
    ActualFont::Metrics getMetrics(const std::string &lang = "") const; // RETURNS THE SIZED METRICS OF THE FIRST ActualFont IN THE SET USED FOR lang

    /*
     * THE RETURNED LineLayout INSTANCES ARE NOT MANAGED AND SHOULD BE DELETED BY THE CALLER
     */
    LineLayout* createLineLayout(const std::string &text, const std::string &langHint = "", hb_direction_t overallDirection = HB_DIRECTION_INVALID);
    LineLayout* createLineLayout(const TextLine &line);
    
    void setSize(float size);
    void setColor(const ci::ColorA &color);
    
    void begin();
    void end();
    void drawCluster(const Cluster &cluster, const ci::Vec2f &position);

protected:
    float size;
    float sizeRatio;

    std::vector<ci::Vec2f> positions;
    std::vector<ci::Vec2f> coords;
{'fraction_non_alphanumeric': 0.0944424264438794, 'fraction_numerical': 0.0025426807119505995, 'mean_word_length': 2.897381457891012, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 15, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '653212', 'n_tokens_mistral': 1814, 'n_tokens_neox': 1758, 'n_words': 455}