﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WPAppStudio.Services.Interfaces;

namespace WPAppStudio.Services
{
    public class WordWrapService
    {
        private readonly ITextMeasurementService _tms;

        public WordWrapService(ITextMeasurementService textMeasurementService)
        {
            _tms = textMeasurementService;
        }

        public string GetWords(string text, int wordCount)
        {

            StringBuilder result = new StringBuilder();

            for (int word = 0; word < wordCount; word++)
            {
                int space = text.IndexOf(' ', 1);
                //return text.Substring(0, space);
                if (space == -1)
                {
                    result.Append(text);
                    return result.ToString();
                }
                result.Append(text.Substring(0, space));
                text = text.Substring(space);
                
            }

            return result.ToString();
        }

        public string GetLine(string text, int lineLength)
        {
            for (int wordCount = 10; wordCount > 0; wordCount--)
            {
                string line = GetWords(text, wordCount);

                int width = _tms.GetTextWidth(line);

                if (width <= lineLength)
                {
                    return line;
                }
            }

            return GetWords(text, 1);
        }
    }
}

﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WPAppStudio.Services.Interfaces;

namespace WPAppStudio.Services
{
    public class WordWrapService
    {
        private readonly ITextMeasurementService _tms;

        public WordWrapService(ITextMeasurementService textMeasurementService)
        {
            _tms = textMeasurementService;
        }

        public string GetWords(string text, int wordCount)
        {

            StringBuilder result = new StringBuilder();

            for (int word = 0; word < wordCount; word++)
            {
                int space = text.IndexOf(' ', 1);
                //return text.Substring(0, space);
                if (space == -1)
                {
                    result.Append(text);
                    return result.ToString();
                }
                result.Append(text.Substring(0, space));
                text = text.Substring(space);
                
            }

            return result.ToString();
        }

        public string GetLine(string text, int lineLength)
        {
            string line = GetWords(text, 3);

            int width = _tms.GetTextWidth(line);

            if (width <= lineLength)
            {
                return line;
            }

            return GetWords(text, 1);
        }
    }
}

Revert "And we have the medium line working!"
Revert "And we have the medium line working!"

This reverts commit 2c642200074b3a3d882a95530f053656346ac05d.
