<commit_before>/*******************************************************
 * Copyright (c) 2015-2019, ArrayFire
 * All rights reserved.
 *
 * This file is distributed under 3-clause BSD license.
 * The complete license agreement can be obtained at:
 * http://arrayfire.com/licenses/BSD-3-Clause
 ********************************************************/

#include <font.hpp>

#include <common.hpp>
#include <err_opengl.hpp>
#include <font_impl.hpp>
#include <chart_impl.hpp>
#include <image_impl.hpp>
#include <histogram_impl.hpp>
#include <plot_impl.hpp>
#include <surface_impl.hpp>
#include <window_impl.hpp>
#include <shader_headers/chart_vs.hpp>
#include <shader_headers/chart_fs.hpp>
#include <shader_headers/tick_fs.hpp>

#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>

#include <cmath>
#include <mutex>
#include <sstream>
#include <algorithm>

using namespace gl;
using namespace std;

typedef std::vector<std::string>::const_iterator StringIter;

static const int CHART2D_FONT_SIZE = 16;

const std::shared_ptr<forge::opengl::font_impl>& getChartFont()
{
    static forge::common::Font gChartFont;
    static std::once_flag flag;

    std::call_once(flag, []() {
#if defined(OS_WIN)
        gChartFont.loadSystemFont("Calibri");
#else
        gChartFont.loadSystemFont("Vera");
#endif
    });

    return gChartFont.impl();
}

template<typename T>
void pushPoint(vector<T> &points, T x, T y)
{
    points.push_back(x);
    points.push_back(y);
}

template<typename T>
void pushPoint(vector<T> &points, T x, T y, T z)
{
    points.push_back(x);
    points.push_back(y);
    points.push_back(z);
}

namespace forge
{
namespace opengl
{

/********************* BEGIN-AbstractChart *********************/

void AbstractChart::renderTickLabels(
        const int pWindowId, const uint pW, const uint pH,
        const std::vector<std::string> &pTexts,
        const glm::mat4 &pTransformation, const int pCoordsOffset,
        const bool pUseZoffset) const
{
    auto &fonter = getChartFont();
    fonter->setOthro2D(int(pW), int(pH));

    float pos[2];
    for (StringIter it = pTexts.begin(); it!=pTexts.end(); ++it) {
        int idx = int(it - pTexts.begin());
        glm::vec4 p = glm::vec4(mTickTextX[idx+pCoordsOffset],
                                mTickTextY[idx+pCoordsOffset],
                                (pUseZoffset ? mTickTextZ[idx+pCoordsOffset] : 0), 1);
        glm::vec4 res = pTransformation * p;

        /* convert text position from [-1,1] range to
         * [0, 1) range and then offset horizontally
         * to compensate for margins and ticksize */
        pos[0] = pW * (res.x/res.w+1.0f)/2.0f;
        pos[1] = pH * (res.y/res.w+1.0f)/2.0f;

        /* offset based on text size to align
         * text center with tick mark position */
        if(pCoordsOffset < mTickCount) {
            // offset for y axis labels
            pos[0] -= (CHART2D_FONT_SIZE*it->length()/2.0f+mTickSize);
            pos[1] -= (CHART2D_FONT_SIZE*.36);
        } else if(pCoordsOffset >= mTickCount && pCoordsOffset < 2*mTickCount) {
            // offset for x axis labels
            pos[0] -= (CHART2D_FONT_SIZE*it->length()/4.0f);
            pos[1] -= (CHART2D_FONT_SIZE*1.32);
        } else {
            // offsets for 3d chart axes ticks
            pos[0] -= (CHART2D_FONT_SIZE*it->length()/2.0f);<commit_msg>fix string offset values to signed type(int) for font<commit_after>/*******************************************************
 * Copyright (c) 2015-2019, ArrayFire
 * All rights reserved.
 *
 * This file is distributed under 3-clause BSD license.
 * The complete license agreement can be obtained at:
 * http://arrayfire.com/licenses/BSD-3-Clause
 ********************************************************/

#include <font.hpp>

#include <common.hpp>
#include <err_opengl.hpp>
#include <font_impl.hpp>
#include <chart_impl.hpp>
#include <image_impl.hpp>
#include <histogram_impl.hpp>
#include <plot_impl.hpp>
#include <surface_impl.hpp>
#include <window_impl.hpp>
#include <shader_headers/chart_vs.hpp>
#include <shader_headers/chart_fs.hpp>
#include <shader_headers/tick_fs.hpp>

#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>

#include <cmath>
#include <mutex>
#include <sstream>
#include <algorithm>

using namespace gl;
using namespace std;

typedef std::vector<std::string>::const_iterator StringIter;

static const int CHART2D_FONT_SIZE = 16;

const std::shared_ptr<forge::opengl::font_impl>& getChartFont()
{
    static forge::common::Font gChartFont;
    static std::once_flag flag;

    std::call_once(flag, []() {
#if defined(OS_WIN)
        gChartFont.loadSystemFont("Calibri");
#else
        gChartFont.loadSystemFont("Vera");
#endif
    });

    return gChartFont.impl();
}

template<typename T>
void pushPoint(vector<T> &points, T x, T y)
{
    points.push_back(x);
    points.push_back(y);
}

template<typename T>
void pushPoint(vector<T> &points, T x, T y, T z)
{
    points.push_back(x);
    points.push_back(y);
    points.push_back(z);
}

namespace forge
{
namespace opengl
{

/********************* BEGIN-AbstractChart *********************/

void AbstractChart::renderTickLabels(
        const int pWindowId, const uint pW, const uint pH,
        const std::vector<std::string> &pTexts,
        const glm::mat4 &pTransformation, const int pCoordsOffset,
        const bool pUseZoffset) const
{
    auto &fonter = getChartFont();
    fonter->setOthro2D(int(pW), int(pH));

    float pos[2];
    for (StringIter it = pTexts.begin(); it!=pTexts.end(); ++it) {
        int idx = int(it - pTexts.begin());
        glm::vec4 p = glm::vec4(mTickTextX[idx+pCoordsOffset],
                                mTickTextY[idx+pCoordsOffset],
                                (pUseZoffset ? mTickTextZ[idx+pCoordsOffset] : 0), 1);
        glm::vec4 res = pTransformation * p;

        /* convert text position from [-1,1] range to
         * [0, 1) range and then offset horizontally
         * to compensate for margins and ticksize */
        pos[0] = pW * (res.x/res.w+1.0f)/2.0f;
        pos[1] = pH * (res.y/res.w+1.0f)/2.0f;

        const float strHalfLen = it->length() / 2.0f;
        /* offset based on text size to align
         * text center with tick mark position */
        if(pCoordsOffset < mTickCount) {
            // offset for y axis labels
            pos[0] -= (CHART2D_FONT_SIZE*strHalfLen+mTickSize);
            pos[1] -= (CHART2D_FONT_SIZE*.36);
        } else if(pCoordsOffset >= mTickCount && pCoordsOffset < 2*mTickCount) {
            // offset for x axis labels
            pos[0] -= (CHART2D_FONT_SIZE*strHalfLen/2.0f);
            pos[1] -= (CHART2D_FONT_SIZE*1.32);
        } else {
            // offsets for 3d chart axes ticks
            pos[0] -= (CHART2D_FONT_SIZE*strHalfLen);
{'fraction_non_alphanumeric': 0.17410323709536307, 'fraction_numerical': 0.016622922134733157, 'mean_word_length': 3.2339506172839507, 'pattern_counts': {'":': 0, '<': 61, '<?xml version=': 0, '>': 65, 'https://': 0, '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': '7537301', 'n_tokens_mistral': 2404, 'n_tokens_neox': 2310, 'n_words': 518}