~wpf-math-dev/wpf-math/devel

« back to all changes in this revision

Viewing changes to WpfMath/DelimiterFactory.cs

  • Committer: Alex Regueiro
  • Date: 2010-06-05 23:00:18 UTC
  • Revision ID: alexreg@gmail.com-20100605230018-wk0jl38tjcla09yh
Put all classes in library in WpfMath namespace.
Added RenderToBitmap method on TexRenderer.

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
using System.Linq;
4
4
using System.Text;
5
5
 
6
 
// Creates boxes containing delimeter symbol that exists in different sizes.
7
 
internal static class DelimiterFactory
 
6
namespace WpfMath
8
7
{
9
 
    public static Box CreateBox(string symbol, double minHeight, TexEnvironment environment)
 
8
    // Creates boxes containing delimeter symbol that exists in different sizes.
 
9
    internal static class DelimiterFactory
10
10
    {
11
 
        var texFont = environment.TexFont;
12
 
        var style = environment.Style;
13
 
        var charInfo = texFont.GetCharInfo(symbol, style);
14
 
 
15
 
        // Find first version of character that has at least minimum height.
16
 
        var metrics = charInfo.Metrics;
17
 
        var totalHeight = metrics.Height + metrics.Depth;
18
 
        while (totalHeight < minHeight && texFont.HasNextLarger(charInfo))
19
 
        {
20
 
            charInfo = texFont.GetNextLargerCharInfo(charInfo, style);
21
 
            metrics = charInfo.Metrics;
22
 
            totalHeight = metrics.Height + metrics.Depth;
23
 
        }
24
 
 
25
 
        if (totalHeight >= minHeight)
26
 
        {
27
 
            // Character of sufficient height was found.
28
 
            return new CharBox(environment, charInfo);
29
 
        }
30
 
        else if (texFont.IsExtensionChar(charInfo))
31
 
        {
32
 
            var resultBox = new VerticalBox();
33
 
 
34
 
            // Construct box from extension character.
35
 
            var extension = texFont.GetExtension(charInfo, style);
36
 
            if (extension.Top != null)
37
 
                resultBox.Add(new CharBox(environment, extension.Top));
38
 
            if (extension.Middle != null)
39
 
                resultBox.Add(new CharBox(environment, extension.Middle));
40
 
            if (extension.Bottom != null)
41
 
                resultBox.Add(new CharBox(environment, extension.Bottom));
42
 
 
43
 
            // Insert repeatable part multiple times until box is high enough.
44
 
            var repeatBox = new CharBox(environment, extension.Repeat);
45
 
            do
46
 
            {
47
 
                if (extension.Top != null && extension.Bottom != null)
48
 
                {
49
 
                    resultBox.Add(1, repeatBox);
50
 
                    if (extension.Middle != null)
51
 
                        resultBox.Add(resultBox.Children.Count - 1, repeatBox);
52
 
                }
53
 
                else if (extension.Bottom != null)
54
 
                {
55
 
                    resultBox.Add(0, repeatBox);
56
 
                }
57
 
                else
58
 
                {
59
 
                    resultBox.Add(repeatBox);
60
 
                }
61
 
            } while (resultBox.Height + resultBox.Depth < minHeight);
62
 
 
63
 
            return resultBox;
64
 
        }
65
 
        else
66
 
        {
67
 
            // No extensions available, so use tallest available version of character.
68
 
            return new CharBox(environment, charInfo);
 
11
        public static Box CreateBox(string symbol, double minHeight, WpfMath.TexEnvironment environment)
 
12
        {
 
13
            var texFont = environment.TexFont;
 
14
            var style = environment.Style;
 
15
            var charInfo = texFont.GetCharInfo(symbol, style);
 
16
 
 
17
            // Find first version of character that has at least minimum height.
 
18
            var metrics = charInfo.Metrics;
 
19
            var totalHeight = metrics.Height + metrics.Depth;
 
20
            while (totalHeight < minHeight && texFont.HasNextLarger(charInfo))
 
21
            {
 
22
                charInfo = texFont.GetNextLargerCharInfo(charInfo, style);
 
23
                metrics = charInfo.Metrics;
 
24
                totalHeight = metrics.Height + metrics.Depth;
 
25
            }
 
26
 
 
27
            if (totalHeight >= minHeight)
 
28
            {
 
29
                // Character of sufficient height was found.
 
30
                return new CharBox(environment, charInfo);
 
31
            }
 
32
            else if (texFont.IsExtensionChar(charInfo))
 
33
            {
 
34
                var resultBox = new WpfMath.VerticalBox();
 
35
 
 
36
                // Construct box from extension character.
 
37
                var extension = texFont.GetExtension(charInfo, style);
 
38
                if (extension.Top != null)
 
39
                    resultBox.Add(new CharBox(environment, extension.Top));
 
40
                if (extension.Middle != null)
 
41
                    resultBox.Add(new CharBox(environment, extension.Middle));
 
42
                if (extension.Bottom != null)
 
43
                    resultBox.Add(new CharBox(environment, extension.Bottom));
 
44
 
 
45
                // Insert repeatable part multiple times until box is high enough.
 
46
                var repeatBox = new CharBox(environment, extension.Repeat);
 
47
                do
 
48
                {
 
49
                    if (extension.Top != null && extension.Bottom != null)
 
50
                    {
 
51
                        resultBox.Add(1, repeatBox);
 
52
                        if (extension.Middle != null)
 
53
                            resultBox.Add(resultBox.Children.Count - 1, repeatBox);
 
54
                    }
 
55
                    else if (extension.Bottom != null)
 
56
                    {
 
57
                        resultBox.Add(0, repeatBox);
 
58
                    }
 
59
                    else
 
60
                    {
 
61
                        resultBox.Add(repeatBox);
 
62
                    }
 
63
                } while (resultBox.Height + resultBox.Depth < minHeight);
 
64
 
 
65
                return resultBox;
 
66
            }
 
67
            else
 
68
            {
 
69
                // No extensions available, so use tallest available version of character.
 
70
                return new CharBox(environment, charInfo);
 
71
            }
69
72
        }
70
73
    }
71
74
}