<commit_before>﻿//MIT, 2017, <NAME>(github/zwcloud)
//MIT, 2017, WinterDev (modified from Xamarin's Android code template)
using System;
using System.Collections.Generic;
using Android.Views;
using DrawingGL;
using DrawingGL.Text;

namespace Test_Android_Glyph
{


    class CustomApp
    {

        TypographyTextContext textContext;
        SimpleCanvas simpleCanvas;
        TextRun textRun;

        public void Setup(int canvasW, int canvasH)
        {

            simpleCanvas = new SimpleCanvas(canvasW, canvasH);
            var text = "Glyph";
            //optional ....
            //var directory = AndroidOS.Environment.ExternalStorageDirectory;
            //var fullFileName = Path.Combine(directory.ToString(), "TypographyTest.txt");
            //if (File.Exists(fullFileName))
            //{
            //    text = File.ReadAllText(fullFileName);
            //}
            //-------------------------------------------------------------------------- 
            //we want to create a prepared visual object ***
            textContext = new TypographyTextContext()
            {
                FontFamily = "DroidSans.ttf", //corresponding to font file Assets/DroidSans.ttf
                FontSize = 36,//size in Points
                FontStretch = FontStretch.Normal,
                FontStyle = FontStyle.Normal,
                FontWeight = FontWeight.Normal,
                Alignment = DrawingGL.Text.TextAlignment.Leading
            };
            //-------------------------------------------------------------------------- 
            //create blank text run 
            textRun = new TextRun();
            //generate glyph run inside text text run
            textContext.GenerateGlyphRuns(textRun, text);
            //-------------------------------------------------------------------------- 

        }

        public void RenderFrame()
        {
            simpleCanvas.PreRender();
            simpleCanvas.ClearCanvas();

            //-----------
            simpleCanvas.StrokeColor = Color.Black;
            simpleCanvas.DrawLine(0, 0, 700, 700);
            //
            simpleCanvas.FillTextRun(textRun, 0, 0);
            //-----------<commit_msg>9282.1<commit_after>﻿//MIT, 2017, <NAME>(github/zwcloud)
//MIT, 2017, WinterDev (modified from Xamarin's Android code template)

using System.IO;
using DrawingGL;
using DrawingGL.Text;

namespace Test_Android_Glyph
{
    class CustomApp
    {

        TypographyTextContext textContext;
        SimpleCanvas simpleCanvas;
        TextRun textRun;

        public void Setup(int canvasW, int canvasH)
        {
            //--------------------------------------
            //TODO: review here again

            DrawingGL.Text.Utility.SetLoadFontDel(
                fontfile =>
                {
                    using (Stream s = MainActivity.AssetManager.Open(fontfile))
                    using (var ms = new MemoryStream())// This is a simple hack because on Xamarin.Android, a `Stream` created by `AssetManager.Open` is not seekable.
                    {
                        s.CopyTo(ms);
                        return new MemoryStream(ms.ToArray());
                    }
                });

            //--------------------------------------
            simpleCanvas = new SimpleCanvas(canvasW, canvasH);
            var text = "Glyph";
            //optional ....
            //var directory = AndroidOS.Environment.ExternalStorageDirectory;
            //var fullFileName = Path.Combine(directory.ToString(), "TypographyTest.txt");
            //if (File.Exists(fullFileName))
            //{
            //    text = File.ReadAllText(fullFileName);
            //}
            //-------------------------------------------------------------------------- 
            //we want to create a prepared visual object ***
            textContext = new TypographyTextContext()
            {
                FontFamily = "DroidSans.ttf", //corresponding to font file Assets/DroidSans.ttf
                FontSize = 48,//size in Points
                FontStretch = FontStretch.Normal,
                FontStyle = FontStyle.Normal,
                FontWeight = FontWeight.Normal,
                Alignment = DrawingGL.Text.TextAlignment.Leading
            };
            //-------------------------------------------------------------------------- 
            //create blank text run 
            textRun = new TextRun();
            //generate glyph run inside text text run
            textContext.GenerateGlyphRuns(textRun, text);
            //-------------------------------------------------------------------------- 

        }

        public void RenderFrame()
        {
            simpleCanvas.PreRender();
            simpleCanvas.ClearCanvas();

            //-----------
            simpleCanvas.StrokeColor = Color.Black;
            simpleCanvas.DrawLine(0, 0, 700, 700);
            //
            for (int i = 0; i < 10; ++i)
            {
                simpleCanvas.FillTextRun(textRun, i * 100, i * 100);
            }
            //-----------
{'fraction_non_alphanumeric': 0.19485366332744058, 'fraction_numerical': 0.010214103319583579, 'mean_word_length': 1.1385972280554388, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, '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': '4438373', 'n_tokens_mistral': 1228, 'n_tokens_neox': 1128, 'n_words': 274}