Code Coverage Statistics for Source File
c:\Tools\SD3\src\Libraries\ICSharpCode.TextEditor\Project\Src\Document\HighlightingStrategy\FontContainer.cs
|
Sequence Point Coverage
N/A
0 of 0
|
Branch Coverage
N/A
0 of 0
|
Lines
103
|
Highlight:
Uncovered Code
Covered Code
| L | V | Source |
|---|---|---|
1 |
// <file> |
|
2 |
// <copyright see="prj:///doc/copyright.txt"/> |
|
3 |
// <license see="prj:///doc/license.txt"/> |
|
4 |
// <owner name="Mike Krüger" email="mike@icsharpcode.net"/> |
|
5 |
// <version>$Revision: 2313 $</version> |
|
6 |
// </file> |
|
7 |
||
8 |
using System; |
|
9 |
using System.Drawing; |
|
10 |
||
11 |
namespace ICSharpCode.TextEditor.Document |
|
12 |
{ |
|
13 |
/// <summary> |
|
14 |
/// This class is used to generate bold, italic and bold/italic fonts out |
|
15 |
/// of a base font. |
|
16 |
/// </summary> |
|
17 |
public class FontContainer |
|
18 |
{ |
|
19 |
Font defaultFont; |
|
20 |
Font regularfont, boldfont, italicfont, bolditalicfont; |
|
21 |
||
22 |
/// <value> |
|
23 |
/// The scaled, regular version of the base font |
|
24 |
/// </value> |
|
25 |
public Font RegularFont { |
|
26 |
get { |
|
27 |
return regularfont; |
|
28 |
} |
|
29 |
} |
|
30 |
||
31 |
/// <value> |
|
32 |
/// The scaled, bold version of the base font |
|
33 |
/// </value> |
|
34 |
public Font BoldFont { |
|
35 |
get { |
|
36 |
return boldfont; |
|
37 |
} |
|
38 |
} |
|
39 |
||
40 |
/// <value> |
|
41 |
/// The scaled, italic version of the base font |
|
42 |
/// </value> |
|
43 |
public Font ItalicFont { |
|
44 |
get { |
|
45 |
return italicfont; |
|
46 |
} |
|
47 |
} |
|
48 |
||
49 |
/// <value> |
|
50 |
/// The scaled, bold/italic version of the base font |
|
51 |
/// </value> |
|
52 |
public Font BoldItalicFont { |
|
53 |
get { |
|
54 |
return bolditalicfont; |
|
55 |
} |
|
56 |
} |
|
57 |
||
58 |
static float twipsPerPixelY; |
|
59 |
||
60 |
public static float TwipsPerPixelY { |
|
61 |
get { |
|
62 |
if (twipsPerPixelY == 0) { |
|
63 |
using (Bitmap bmp = new Bitmap(1,1)) { |
|
64 |
using (Graphics g = Graphics.FromImage(bmp)) { |
|
65 |
twipsPerPixelY = 1440 / g.DpiY; |
|
66 |
} |
|
67 |
} |
|
68 |
} |
|
69 |
return twipsPerPixelY; |
|
70 |
} |
|
71 |
} |
|
72 |
||
73 |
/// <value> |
|
74 |
/// The base font |
|
75 |
/// </value> |
|
76 |
public Font DefaultFont { |
|
77 |
get { |
|
78 |
return defaultFont; |
|
79 |
} |
|
80 |
set { |
|
81 |
// 1440 twips is one inch |
|
82 |
int pixelSize = (int)(value.SizeInPoints * 20 / TwipsPerPixelY); |
|
83 |
||
84 |
defaultFont = value; |
|
85 |
regularfont = new Font(value.FontFamily, pixelSize * TwipsPerPixelY / 20f, FontStyle.Regular); |
|
86 |
boldfont = new Font(regularfont, FontStyle.Bold); |
|
87 |
italicfont = new Font(regularfont, FontStyle.Italic); |
|
88 |
bolditalicfont = new Font(regularfont, FontStyle.Bold | FontStyle.Italic); |
|
89 |
} |
|
90 |
} |
|
91 |
||
92 |
public static Font ParseFont(string font) |
|
93 |
{ |
|
94 |
string[] descr = font.Split(new char[]{',', '='}); |
|
95 |
return new Font(descr[1], Single.Parse(descr[3])); |
|
96 |
} |
|
97 |
||
98 |
public FontContainer(Font defaultFont) |
|
99 |
{ |
|
100 |
this.DefaultFont = defaultFont; |
|
101 |
} |
|
102 |
} |
|
103 |
} |