#if WITHOUT_UNISCRIBE && !SKIA
using System;
using System.Collections.Generic;
using System.Drawing;
using FastReport.Fonts;
using FastReport.Utils;

namespace FastReport.Export.TTF
{
    internal partial class ExportTTFFont
    {
        private TrueTypeFont GetTrueTypeFont(Font sourceFont)
        {
            return Config.FontCollection[sourceFont];
        }

        public void FillOutlineTextMetrix()
        {
            if (sourceFont != null)
            {
                TrueTypeFont font = GetTrueTypeFont(sourceFont);
                if (font != null)
                    font.GetOutlineTextMetrics(ref textMetric);
            }
        }

        // libgdiplus version has no support for font fallback and returns one run.
        // Also support of complex scripts is almost non-existing.
        private List<RunInfo> LayoutString(string str, bool rtl, Font originalFont)
        {
            int maxGlyphs = str.Length * 3;

            var run = new RunInfo(maxGlyphs)
            {
                Font = originalFont,
            };
            
            for (int i = 0; i < str.Length; i++)
            {
                run.GlyphToUnicode[i] = str[i].ToString();
            }
            
            TrueTypeFont font = Config.FontCollection[sourceFont];
            if (rtl)
                font.Script = "arab";
            
            int actualLength = font.GetGlyphIndices(str, sourceFont.Size / 0.75f, out run.Glyphs, out run.Widths, out run.Kernings, rtl);
            Array.Resize<ushort>(ref run.Glyphs, actualLength);
            Array.Resize<string>(ref run.GlyphToUnicode, actualLength);
            Array.Resize<float>(ref run.Widths, actualLength);
            Array.Resize<float>(ref run.Kernings, actualLength);

            List<RunInfo> result = new List<RunInfo>();
            result.Add(run);
            return result;
        }

        private void InternalInit()
        {
            dpiFX = 1;
        }

        partial void InternalDispose();
    }
}
#endif