~ubuntu-branches/ubuntu/natty/pdfmod/natty

« back to all changes in this revision

Viewing changes to lib/PdfSharp/PdfSharp.Drawing/XTypeFace.cs

  • Committer: Bazaar Package Importer
  • Author(s): Chow Loong Jin
  • Date: 2010-09-29 17:34:49 UTC
  • mfrom: (2.1.1 experimental)
  • Revision ID: james.westby@ubuntu.com-20100929173449-4ezagrzettatjk36
Tags: 0.9.0-1
* New upstream release
* debian/copyright: Document PdfSharp.SharpZipLib/*
* Drop all patches: committed upstream
* No change bump of Standards-Version from 3.8.4 to 3.9.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#region PDFsharp - A .NET library for processing PDF
 
2
//
 
3
// Authors:
 
4
//   Stefan Lange (mailto:Stefan.Lange@pdfsharp.com)
 
5
//
 
6
// Copyright (c) 2005-2009 empira Software GmbH, Cologne (Germany)
 
7
//
 
8
// http://www.pdfsharp.com
 
9
// http://sourceforge.net/projects/pdfsharp
 
10
//
 
11
// Permission is hereby granted, free of charge, to any person obtaining a
 
12
// copy of this software and associated documentation files (the "Software"),
 
13
// to deal in the Software without restriction, including without limitation
 
14
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
 
15
// and/or sell copies of the Software, and to permit persons to whom the
 
16
// Software is furnished to do so, subject to the following conditions:
 
17
//
 
18
// The above copyright notice and this permission notice shall be included
 
19
// in all copies or substantial portions of the Software.
 
20
//
 
21
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
22
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
23
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 
24
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 
25
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 
26
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
 
27
// DEALINGS IN THE SOFTWARE.
 
28
#endregion
 
29
 
 
30
using System;
 
31
using System.Diagnostics;
 
32
using System.Runtime.InteropServices;
 
33
using System.ComponentModel;
 
34
using System.IO;
 
35
#if GDI
 
36
using System.Drawing;
 
37
using System.Drawing.Drawing2D;
 
38
#endif
 
39
#if WPF
 
40
using System.Windows;
 
41
using System.Windows.Media;
 
42
#endif
 
43
using PdfSharp.Internal;
 
44
using PdfSharp.Fonts.OpenType;
 
45
using PdfSharp.Pdf;
 
46
using PdfSharp.Pdf.Advanced;
 
47
 
 
48
namespace PdfSharp.Drawing
 
49
{
 
50
  /// <summary>
 
51
  /// Temporary hack to implement PrivateFontCollection.
 
52
  /// </summary>
 
53
  class XTypefaceHack
 
54
  {
 
55
    public XTypefaceHack(string typefaceName)
 
56
      : this(typefaceName, XFontStyle.Regular, XFontWeights.Normal, new XFontStretch())
 
57
    { }
 
58
 
 
59
    public XTypefaceHack(string typefaceName, XFontStyle style, XFontWeight weight)
 
60
      : this(typefaceName, style, weight, new XFontStretch())
 
61
    { }
 
62
 
 
63
    public XTypefaceHack(string fontFamilyName, XFontStyle style, XFontWeight weight, XFontStretch stretch)
 
64
    {
 
65
      if (String.IsNullOrEmpty(fontFamilyName))
 
66
        throw new ArgumentNullException("fontFamilyName");
 
67
 
 
68
      this.fontFamilyName = fontFamilyName;
 
69
      this.style = style;
 
70
      this.weight = weight;
 
71
      this.stretch = stretch;
 
72
    }
 
73
 
 
74
    public string FontFamilyName
 
75
    {
 
76
      get { return this.fontFamilyName; }
 
77
    }
 
78
    string fontFamilyName;
 
79
 
 
80
    public XFontWeight Weight
 
81
    {
 
82
      get { return this.weight; }
 
83
    }
 
84
    private XFontWeight weight;
 
85
 
 
86
    public XFontStyle Style
 
87
    {
 
88
      get { return this.style; }
 
89
    }
 
90
    private XFontStyle style;
 
91
 
 
92
    public XFontStretch Stretch
 
93
    {
 
94
      get { return this.stretch; }
 
95
    }
 
96
    private XFontStretch stretch;
 
97
  }
 
98
 
 
99
 
 
100
  /// <summary>
 
101
  /// NYI
 
102
  /// </summary>
 
103
  internal class XTypeface
 
104
  {
 
105
    //  /// <summary>
 
106
    //  /// Construct a typeface 
 
107
    //  /// </summary>
 
108
    //  /// <param name="typefaceName">font typeface name</param>
 
109
    //  public Typeface(
 
110
    //      string typefaceName
 
111
    //      )
 
112
    //    // assume face name is family name until we get face name resolved properly. 
 
113
    //    : this(
 
114
    //        new FontFamily(typefaceName),
 
115
    //        FontStyles.Normal,
 
116
    //        FontWeights.Normal,
 
117
    //        FontStretches.Normal
 
118
    //        )
 
119
    //  { }
 
120
 
 
121
 
 
122
 
 
123
    //  /// <summary>
 
124
    //  /// Construct a typeface 
 
125
    //  /// </summary>
 
126
    //  /// <param name="fontFamily">Font family</param>
 
127
    //  /// <param name="style">Font style</param>
 
128
    //  /// <param name="weight">Boldness of font</param> 
 
129
    //  /// <param name="stretch">Width of characters</param>
 
130
    //  public Typeface(
 
131
    //      FontFamily fontFamily,
 
132
    //      FontStyle style,
 
133
    //      FontWeight weight,
 
134
    //      FontStretch stretch
 
135
    //      )
 
136
    //    : this(
 
137
    //        fontFamily,
 
138
    //        style,
 
139
    //        weight,
 
140
    //        stretch,
 
141
    //        FontFamily.FontFamilyGlobalUI
 
142
    //        )
 
143
    //  { }
 
144
 
 
145
 
 
146
 
 
147
    //  /// <summary>
 
148
    //  /// Construct a typeface 
 
149
    //  /// </summary> 
 
150
    //  /// <param name="fontFamily">Font family</param>
 
151
    //  /// <param name="style">Font style</param> 
 
152
    //  /// <param name="weight">Boldness of font</param>
 
153
    //  /// <param name="stretch">Width of characters</param>
 
154
    //  /// <param name="fallbackFontFamily">fallback font family</param>
 
155
    //  public Typeface(
 
156
    //      FontFamily fontFamily,
 
157
    //      FontStyle style,
 
158
    //      FontWeight weight,
 
159
    //      FontStretch stretch,
 
160
    //      FontFamily fallbackFontFamily
 
161
    //      )
 
162
    //  {
 
163
    //    if (fontFamily == null)
 
164
    //    {
 
165
    //      throw new ArgumentNullException("fontFamily");
 
166
    //    }
 
167
 
 
168
    //    _fontFamily = fontFamily;
 
169
    //    _style = style;
 
170
    //    _weight = weight;
 
171
    //    _stretch = stretch;
 
172
    //    _fallbackFontFamily = fallbackFontFamily;
 
173
    //  }
 
174
 
 
175
 
 
176
 
 
177
 
 
178
    //  private FontFamily _fontFamily;
 
179
 
 
180
    //  // these _style, _weight and _stretch are only used for storing what was passed into the constructor.
 
181
    //  // Since FontFamily may change these values when it includes a style name implicitly, 
 
182
    //  private FontStyle _style;
 
183
    //  private FontWeight _weight;
 
184
    //  private FontStretch _stretch;
 
185
 
 
186
 
 
187
    //  /// <summary>
 
188
    //  /// Font family 
 
189
    //  /// </summary>
 
190
    //  public FontFamily FontFamily
 
191
    //  {
 
192
    //    get { return _fontFamily; }
 
193
    //  }
 
194
 
 
195
 
 
196
    //  /// <summary>
 
197
    //  /// Font weight (light, bold, etc.) 
 
198
    //  /// </summary>
 
199
    //  public FontWeight Weight
 
200
    //  {
 
201
    //    get { return _weight; }
 
202
    //  }
 
203
 
 
204
 
 
205
    //  /// <summary>
 
206
    //  /// Font style (italic, oblique) 
 
207
    //  /// </summary>
 
208
    //  public FontStyle Style
 
209
    //  {
 
210
    //    get { return _style; }
 
211
    //  }
 
212
 
 
213
 
 
214
    //  /// <summary>
 
215
    //  /// Font Stretch (narrow, wide, etc.) 
 
216
    //  /// </summary>
 
217
    //  public FontStretch Stretch
 
218
    //  {
 
219
    //    get { return _stretch; }
 
220
    //  }
 
221
 
 
222
 
 
223
 
 
224
 
 
225
    //  private FontFamily _fallbackFontFamily;
 
226
 
 
227
    //  // Cached canonical values of the typeface. 
 
228
    //  private CachedTypeface _cachedTypeface;
 
229
 
 
230
 
 
231
    //  /// <summary> 
 
232
    //  /// Returns true if FontStyle.Oblique is algorithmically simulated by
 
233
    //  /// slanting glyphs. Returns false otherwise. 
 
234
    //  /// </summary>
 
235
    //  public bool IsObliqueSimulated
 
236
    //  {
 
237
    //    get
 
238
    //    {
 
239
    //      return (CachedTypeface.TypefaceMetrics.StyleSimulations & StyleSimulations.ItalicSimulation) != 0;
 
240
    //    }
 
241
    //  }
 
242
 
 
243
    //  /// <summary>
 
244
    //  /// Returns true if FontStyle.Bold is algorithmically simulated by
 
245
    //  /// thickening glyphs. Returns false otherwise.
 
246
    //  /// </summary> 
 
247
    //  public bool IsBoldSimulated
 
248
    //  {
 
249
    //    get
 
250
    //    {
 
251
    //      return (CachedTypeface.TypefaceMetrics.StyleSimulations & StyleSimulations.BoldSimulation) != 0;
 
252
    //    }
 
253
    //  }
 
254
 
 
255
    //  /// <summary> 
 
256
    //  /// Obtain a glyph typeface that corresponds to the Typeface object constructed from an OpenType font family.
 
257
    //  /// If the Typeface was constructed from a composite font family, returns null. 
 
258
    //  /// </summary> 
 
259
    //  /// <param name="glyphTypeface">GlyphTypeface object that corresponds to this Typeface, or null if the Typeface
 
260
    //  /// was constructed from a composite font.</param> 
 
261
    //  /// <returns>Whether glyphTypeface is not null.</returns>
 
262
    //  public bool TryGetGlyphTypeface(out GlyphTypeface glyphTypeface)
 
263
    //  {
 
264
    //    glyphTypeface = CachedTypeface.TypefaceMetrics as GlyphTypeface;
 
265
    //    return glyphTypeface != null;
 
266
    //  }
 
267
 
 
268
 
 
269
    //  /// <summary> 
 
270
    //  /// Fallback font family
 
271
    //  /// </summary>
 
272
    //  internal FontFamily FallbackFontFamily
 
273
    //  {
 
274
    //    get { return _fallbackFontFamily; }
 
275
    //  }
 
276
 
 
277
    //  /// <summary>
 
278
    //  /// (Western) x-height relative to em size. 
 
279
    //  /// </summary>
 
280
    //  public double XHeight
 
281
    //  {
 
282
    //    get
 
283
    //    {
 
284
    //      return CachedTypeface.TypefaceMetrics.XHeight;
 
285
    //    }
 
286
    //  }
 
287
 
 
288
 
 
289
    //  /// <summary>
 
290
    //  /// Distance from baseline to top of English capital, relative to em size.
 
291
    //  /// </summary> 
 
292
    //  public double CapsHeight
 
293
    //  {
 
294
    //    get
 
295
    //    {
 
296
    //      return CachedTypeface.TypefaceMetrics.CapsHeight;
 
297
    //    }
 
298
    //  }
 
299
 
 
300
 
 
301
    //  /// <summary>
 
302
    //  /// Distance from baseline to underline position 
 
303
    //  /// </summary> 
 
304
    //  public double UnderlinePosition
 
305
    //  {
 
306
    //    get
 
307
    //    {
 
308
    //      return CachedTypeface.TypefaceMetrics.UnderlinePosition;
 
309
    //    }
 
310
    //  }
 
311
 
 
312
 
 
313
    //  /// <summary>
 
314
    //  /// Underline thickness 
 
315
    //  /// </summary>
 
316
    //  public double UnderlineThickness
 
317
    //  {
 
318
    //    get
 
319
    //    {
 
320
    //      return CachedTypeface.TypefaceMetrics.UnderlineThickness;
 
321
    //    }
 
322
    //  }
 
323
 
 
324
 
 
325
    //  /// <summary>
 
326
    //  /// Distance from baseline to strike-through position
 
327
    //  /// </summary> 
 
328
    //  public double StrikethroughPosition
 
329
    //  {
 
330
    //    get
 
331
    //    {
 
332
    //      return CachedTypeface.TypefaceMetrics.StrikethroughPosition;
 
333
    //    }
 
334
    //  }
 
335
 
 
336
 
 
337
    //  /// <summary>
 
338
    //  /// strike-through thickness 
 
339
    //  /// </summary> 
 
340
    //  public double StrikethroughThickness
 
341
    //  {
 
342
    //    get
 
343
    //    {
 
344
    //      return CachedTypeface.TypefaceMetrics.StrikethroughThickness;
 
345
    //    }
 
346
    //  }
 
347
 
 
348
    //  /// <summary> 
 
349
    //  /// Collection of culture-dependant face names.
 
350
    //  /// </summary> 
 
351
    //  public LanguageSpecificStringDictionary FaceNames
 
352
    //  {
 
353
    //    get
 
354
    //    {
 
355
    //      return new LanguageSpecificStringDictionary(CachedTypeface.TypefaceMetrics.AdjustedFaceNames);
 
356
    //    }
 
357
    //  }
 
358
 
 
359
    //  /// <summary> 
 
360
    //  /// Distance from character cell top to English baseline relative to em size.
 
361
    //  /// </summary>
 
362
    //  internal double Baseline
 
363
    //  {
 
364
    //    get
 
365
    //    {
 
366
    //      return CachedTypeface.FirstFontFamily.Baseline;
 
367
    //    }
 
368
    //  }
 
369
 
 
370
    //  /// <summary>
 
371
    //  /// Baseline to baseline distance relative to em size
 
372
    //  /// </summary> 
 
373
    //  internal double LineSpacing
 
374
    //  {
 
375
    //    get
 
376
    //    {
 
377
    //      return CachedTypeface.FirstFontFamily.LineSpacing;
 
378
    //    }
 
379
    //  }
 
380
 
 
381
    //  /// <summary> 
 
382
    //  /// Flag indicating if the typeface is of symbol type
 
383
    //  /// </summary> 
 
384
    //  internal bool Symbol
 
385
    //  {
 
386
    //    get
 
387
    //    {
 
388
    //      return CachedTypeface.TypefaceMetrics.Symbol;
 
389
    //    }
 
390
    //  }
 
391
 
 
392
    //  internal bool NullFont
 
393
    //  {
 
394
    //    get
 
395
    //    {
 
396
    //      return CachedTypeface.NullFont;
 
397
    //    }
 
398
    //  }
 
399
 
 
400
    //  // Tries to get a GlyphTypeface based on the Typeface properties. The
 
401
    //  // return value can be null. However, if CheckFastPathNominalGlyphs 
 
402
    //  // returns true, then one can expect this function to return a valid 
 
403
    //  // GlyphTypeface that maps all the specified text.
 
404
    //  internal GlyphTypeface TryGetGlyphTypeface()
 
405
    //  {
 
406
    //    return CachedTypeface.TypefaceMetrics as GlyphTypeface;
 
407
    //  }
 
408
 
 
409
    //  internal FontStyle CanonicalStyle
 
410
    //  {
 
411
    //    get
 
412
    //    {
 
413
    //      return CachedTypeface.CanonicalStyle;
 
414
    //    }
 
415
    //  }
 
416
 
 
417
    //  internal FontWeight CanonicalWeight
 
418
    //  {
 
419
    //    get
 
420
    //    {
 
421
    //      return CachedTypeface.CanonicalWeight;
 
422
    //    }
 
423
    //  }
 
424
 
 
425
    //  internal FontStretch CanonicalStretch
 
426
    //  {
 
427
    //    get
 
428
    //    {
 
429
    //      return CachedTypeface.CanonicalStretch;
 
430
    //    }
 
431
    //  }
 
432
 
 
433
 
 
434
    //  /// <summary>
 
435
    //  /// Scan through specified character string checking for valid character 
 
436
    //  /// nominal glyph.
 
437
    //  /// </summary> 
 
438
    //  /// <param name="charBufferRange">character buffer range</param> 
 
439
    //  /// <param name="emSize">height of Em</param>
 
440
    //  /// <param name="widthMax">maximum width allowed</param> 
 
441
    //  /// <param name="keepAWord">do not stop arbitrarily in the middle of a word</param>
 
442
    //  /// <param name="numberSubstitution">digits require complex shaping</param>
 
443
    //  /// <param name="cultureInfo">CultureInfo of the text</param>
 
444
    //  /// <param name="stringLengthFit">number of character fit in given width</param> 
 
445
    //  /// <returns>whether the specified string can be optimized by nominal glyph lookup</returns>
 
446
    //  internal bool CheckFastPathNominalGlyphs(
 
447
    //      CharacterBufferRange charBufferRange,
 
448
    //      double emSize,
 
449
    //      double widthMax,
 
450
    //      bool keepAWord,
 
451
    //      bool numberSubstitution,
 
452
    //      CultureInfo cultureInfo,
 
453
    //      out int stringLengthFit
 
454
    //      )
 
455
    //  {
 
456
    //    stringLengthFit = 0;
 
457
 
 
458
    //    if (CachedTypeface.NullFont) return false;
 
459
 
 
460
    //    GlyphTypeface glyphTypeface = TryGetGlyphTypeface();
 
461
 
 
462
    //    if (glyphTypeface == null) return false;
 
463
 
 
464
 
 
465
    //    stringLengthFit = 0;
 
466
    //    IDictionary<int, ushort> cmap = glyphTypeface.CharacterToGlyphMap;
 
467
 
 
468
    //    double totalWidth = 0;
 
469
    //    int i = 0;
 
470
 
 
471
    //    ushort blankGlyph = glyphTypeface.BlankGlyphIndex;
 
472
    //    ushort glyph = blankGlyph;
 
473
 
 
474
    //    ushort charFlagsMask = numberSubstitution ?
 
475
    //        (ushort)(CharacterAttributeFlags.CharacterComplex | CharacterAttributeFlags.CharacterDigit) :
 
476
    //        (ushort)CharacterAttributeFlags.CharacterComplex;
 
477
    //    ushort charFlags = 0;
 
478
    //    ushort charFastTextCheck = (ushort)(CharacterAttributeFlags.CharacterFastText | CharacterAttributeFlags.CharacterIdeo);
 
479
 
 
480
    //    bool symbolTypeface = glyphTypeface.Symbol;
 
481
    //    if (symbolTypeface)
 
482
    //    {
 
483
    //      // we don't care what code points are present if it's a non-Unicode font such as Symbol or Wingdings; 
 
484
    //      // the code points don't have any standardized meanings, and we always want to bypass shaping
 
485
    //      charFlagsMask = 0;
 
486
    //    }
 
487
 
 
488
    //    if (keepAWord)
 
489
    //    {
 
490
    //      do
 
491
    //      {
 
492
    //        char ch = charBufferRange[i++];
 
493
    //        int charClass = (int)Classification.GetUnicodeClassUTF16(ch);
 
494
    //        charFlags = Classification.CharAttributeOf(charClass).Flags;
 
495
    //        charFastTextCheck &= charFlags;
 
496
    //        cmap.TryGetValue(ch, out glyph);
 
497
 
 
498
    //        totalWidth += emSize * glyphTypeface.GetAdvanceWidth(glyph);
 
499
 
 
500
    //      } while (
 
501
    //              i < charBufferRange.Length
 
502
    //          && ((charFlags & charFlagsMask) == 0)
 
503
    //          && (glyph != 0 || symbolTypeface)
 
504
    //          && glyph != blankGlyph
 
505
    //          );
 
506
 
 
507
    //      // i is now at a character immediately following a leading blank 
 
508
    //    }
 
509
 
 
510
    //    while (
 
511
    //            i < charBufferRange.Length
 
512
    //        && totalWidth <= widthMax
 
513
    //        && ((charFlags & charFlagsMask) == 0)
 
514
    //        && (glyph != 0 || symbolTypeface)
 
515
    //        )
 
516
    //    {
 
517
    //      char ch = charBufferRange[i++];
 
518
    //      int charClass = (int)Classification.GetUnicodeClassUTF16(ch);
 
519
    //      charFlags = Classification.CharAttributeOf(charClass).Flags;
 
520
    //      charFastTextCheck &= charFlags;
 
521
    //      cmap.TryGetValue(ch, out glyph);
 
522
    //      totalWidth += emSize * glyphTypeface.GetAdvanceWidth(glyph);
 
523
    //    }
 
524
 
 
525
    //    if (symbolTypeface)
 
526
    //    {
 
527
    //      // always optimize for non-Unicode font as we don't support shaping or typographic features; 
 
528
    //      // we also don't fall back from non-Unicode fonts so we don't care if there are missing glyphs 
 
529
    //      stringLengthFit = i;
 
530
    //      return true;
 
531
    //    }
 
532
 
 
533
    //    if (glyph == 0)
 
534
    //    {
 
535
    //      // character is not supported by the font
 
536
    //      return false;
 
537
    //    }
 
538
 
 
539
    //    if ((charFlags & charFlagsMask) != 0)
 
540
    //    {
 
541
    //      // complex character encountered, exclude it
 
542
    //      Debug.Assert(i > 0);
 
543
 
 
544
    //      if (--i <= 0)
 
545
    //      {
 
546
    //        // first char is complex, fail the call 
 
547
    //        return false;
 
548
    //      }
 
549
    //    }
 
550
 
 
551
    //    stringLengthFit = i;
 
552
    //    TypographyAvailabilities typography = glyphTypeface.FontFaceLayoutInfo.TypographyAvailabilities;
 
553
 
 
554
    //    if ((charFastTextCheck & (byte)CharacterAttributeFlags.CharacterFastText) != 0)
 
555
    //    {
 
556
    //      // all input code points are Fast Text
 
557
    //      if ((typography &
 
558
    //               (TypographyAvailabilities.FastTextTypographyAvailable
 
559
    //                | TypographyAvailabilities.FastTextMajorLanguageLocalizedFormAvailable
 
560
    //               )
 
561
    //           ) != 0
 
562
    //         )
 
563
    //      {
 
564
    //        // Considered too risky to optimize. It is either because the font 
 
565
    //        // has required features or the font has 'locl' lookup for major languages.
 
566
    //        return false;
 
567
    //      }
 
568
    //      else if ((typography & TypographyAvailabilities.FastTextExtraLanguageLocalizedFormAvailable) != 0)
 
569
    //      {
 
570
    //        // The font has 'locl' lookup for FastText code points for non major languages. 
 
571
    //        // Check whether the input is major langauge. If it is, we are still good to optimize.
 
572
    //        return MajorLanguages.Contains(cultureInfo);
 
573
    //      }
 
574
    //      else
 
575
    //      {
 
576
    //        // No FastText flags are present, safe to optimize
 
577
    //        return true;
 
578
    //      }
 
579
    //    }
 
580
    //    else if ((charFastTextCheck & (byte)CharacterAttributeFlags.CharacterIdeo) != 0)
 
581
    //    {
 
582
    //      // The input are all ideographs, check the IdeoTypographyAvailable bit. It is safe if 
 
583
    //      // the bit is not set.
 
584
    //      return ((typography & TypographyAvailabilities.IdeoTypographyAvailable) == 0);
 
585
    //    }
 
586
    //    else
 
587
    //    {
 
588
    //      // for all the rest of the cases, just check whether there is any required typography 
 
589
    //      // present at all. If none exists, it is optimizable. We might under-optimize here but
 
590
    //      // it will be non-major languages. 
 
591
    //      return ((typography & TypographyAvailabilities.Available) == 0);
 
592
    //    }
 
593
    //  }
 
594
 
 
595
 
 
596
    //  /// <summary>
 
597
    //  /// Lookup characters nominal glyphs and width 
 
598
    //  /// </summary>
 
599
    //  /// <param name="charBufferRange">character buffer range</param> 
 
600
    //  /// <param name="emSize">height of Em</param> 
 
601
    //  /// <param name="toIdeal"> scaling factor from real to ideal unit </param>
 
602
    //  /// <param name="nominalWidths">glyph nominal advances in ideal units</param> 
 
603
    //  /// <param name="idealWidth">total width in ideal units</param>
 
604
    //  /// <returns>true for success</returns>
 
605
    //  /// <remarks>This function is only used in fast path, and can only be called
 
606
    //  /// if CheckFastPathNominalGlyphs has previously returned true.</remarks> 
 
607
    //  internal void GetCharacterNominalWidthsAndIdealWidth(
 
608
    //      CharacterBufferRange charBufferRange,
 
609
    //      double emSize,
 
610
    //      double toIdeal,
 
611
    //      out int[] nominalWidths,
 
612
    //      out int idealWidth
 
613
    //      )
 
614
    //  {
 
615
    //    // This function should only be called if CheckFastPathNominalGlyphs has 
 
616
    //    // returned true so we can assume the ITypefaceMetrics is a GlyphTypeface.
 
617
    //    GlyphTypeface glyphTypeface = TryGetGlyphTypeface();
 
618
    //    Invariant.Assert(glyphTypeface != null);
 
619
 
 
620
    //    IDictionary<int, ushort> cmap = glyphTypeface.CharacterToGlyphMap;
 
621
    //    nominalWidths = new int[charBufferRange.Length];
 
622
    //    idealWidth = 0;
 
623
 
 
624
    //    for (int i = 0; i < charBufferRange.Length; i++)
 
625
    //    {
 
626
    //      ushort glyphIndex;
 
627
    //      cmap.TryGetValue(charBufferRange[i], out glyphIndex);
 
628
    //      double advance = emSize * glyphTypeface.GetAdvanceWidth(glyphIndex);
 
629
 
 
630
    //      nominalWidths[i] = (int)Math.Round(advance * toIdeal);
 
631
    //      idealWidth += nominalWidths[i];
 
632
    //    }
 
633
 
 
634
    //  }
 
635
 
 
636
 
 
637
 
 
638
    //  /// <summary> 
 
639
    //  /// Create correspondent hash code for the object
 
640
    //  /// </summary>
 
641
    //  /// <returns>object hash code</returns>
 
642
    //  public override int GetHashCode()
 
643
    //  {
 
644
    //    int hash = _fontFamily.GetHashCode();
 
645
 
 
646
    //    if (_fallbackFontFamily != null)
 
647
    //      hash = HashFn.HashMultiply(hash) + _fallbackFontFamily.GetHashCode();
 
648
 
 
649
    //    hash = HashFn.HashMultiply(hash) + _style.GetHashCode();
 
650
    //    hash = HashFn.HashMultiply(hash) + _weight.GetHashCode();
 
651
    //    hash = HashFn.HashMultiply(hash) + _stretch.GetHashCode();
 
652
    //    return HashFn.HashScramble(hash);
 
653
    //  }
 
654
 
 
655
 
 
656
 
 
657
    //  /// <summary>
 
658
    //  /// Equality check
 
659
    //  /// </summary>
 
660
    //  public override bool Equals(object o)
 
661
    //  {
 
662
    //    Typeface t = o as Typeface;
 
663
    //    if (t == null)
 
664
    //      return false;
 
665
 
 
666
    //    return _style == t._style
 
667
    //        && _weight == t._weight
 
668
    //        && _stretch == t._stretch
 
669
    //        && _fontFamily.Equals(t._fontFamily)
 
670
    //        && CompareFallbackFontFamily(t._fallbackFontFamily);
 
671
    //  }
 
672
 
 
673
 
 
674
    //  internal bool CompareFallbackFontFamily(FontFamily fallbackFontFamily)
 
675
    //  {
 
676
    //    if (fallbackFontFamily == null || _fallbackFontFamily == null)
 
677
    //      return fallbackFontFamily == _fallbackFontFamily;
 
678
 
 
679
    //    return _fallbackFontFamily.Equals(fallbackFontFamily);
 
680
    //  }
 
681
 
 
682
    //  //----------------------------------------
 
683
    //  // Private method 
 
684
    //  //----------------------------------------
 
685
    //  private CachedTypeface CachedTypeface
 
686
    //  {
 
687
    //    get
 
688
    //    {
 
689
    //      if (_cachedTypeface == null)
 
690
    //      {
 
691
    //        CachedTypeface cachedTypeface = TypefaceMetricsCache.ReadonlyLookup(this) as CachedTypeface;
 
692
 
 
693
    //        if (cachedTypeface == null)
 
694
    //        {
 
695
    //          cachedTypeface = ConstructCachedTypeface();
 
696
    //          TypefaceMetricsCache.Add(this, cachedTypeface);
 
697
    //        }
 
698
 
 
699
    //        // For thread-safety, set the _cachedTypeface field only after we have a fully 
 
700
    //        // initialized CachedTypeface object.
 
701
    //        _cachedTypeface = cachedTypeface;
 
702
    //      }
 
703
 
 
704
    //      return _cachedTypeface;
 
705
    //    }
 
706
    //  }
 
707
 
 
708
    //  private CachedTypeface ConstructCachedTypeface()
 
709
    //  {
 
710
    //    FontStyle canonicalStyle = _style;
 
711
    //    FontWeight canonicalWeight = _weight;
 
712
    //    FontStretch canonicalStretch = _stretch;
 
713
 
 
714
    //    // 
 
715
    //    // We always call FontFamily.FindFirstFontFamilyAndFace() method to resolve the
 
716
    //    // canonical styles since the implied styles in FontFamily name will override 
 
717
    //    // the given styles in the Typeface. But we don't always use the IFontFamily 
 
718
    //    // instance returned from this method because an equal instance might already be
 
719
    //    // cached. 
 
720
    //    //
 
721
    //    FontFamily sourceFontFamily = FontFamily;
 
722
 
 
723
    //    IFontFamily firstFontFamily = sourceFontFamily.FindFirstFontFamilyAndFace(
 
724
    //        ref canonicalStyle,
 
725
    //        ref canonicalWeight,
 
726
    //        ref canonicalStretch
 
727
    //        );
 
728
 
 
729
    //    if (firstFontFamily == null)
 
730
    //    {
 
731
    //      if (FallbackFontFamily != null)
 
732
    //      {
 
733
    //        sourceFontFamily = FallbackFontFamily;
 
734
    //        firstFontFamily = sourceFontFamily.FindFirstFontFamilyAndFace(
 
735
    //            ref canonicalStyle,
 
736
    //            ref canonicalWeight,
 
737
    //            ref canonicalStretch
 
738
    //            );
 
739
    //      }
 
740
 
 
741
    //      if (firstFontFamily == null)
 
742
    //      {
 
743
    //        sourceFontFamily = null;
 
744
    //        firstFontFamily = FontFamily.LookupFontFamily(FontFamily.NullFontFamilyCanonicalName);
 
745
    //      }
 
746
    //    }
 
747
 
 
748
    //    // If it's a named font, map all occurrences of the same name to one cached IFontFamily.
 
749
    //    if (sourceFontFamily != null && sourceFontFamily.Source != null)
 
750
    //    {
 
751
    //      // We lookup in the cache to see if there is cached IFontFamily instance of the source FontFamily. Otherwise,
 
752
    //      // this IFontFamily value is added to the TypefaceMetrics cache. 
 
753
    //      IFontFamily cachedValue = TypefaceMetricsCache.ReadonlyLookup(sourceFontFamily.FamilyIdentifier) as IFontFamily;
 
754
 
 
755
    //      if (cachedValue != null)
 
756
    //      {
 
757
    //        firstFontFamily = cachedValue;
 
758
    //      }
 
759
    //      else
 
760
    //      {
 
761
    //        TypefaceMetricsCache.Add(sourceFontFamily.FamilyIdentifier, firstFontFamily);
 
762
    //      }
 
763
    //    }
 
764
 
 
765
    //    ITypefaceMetrics typefaceMetrics = firstFontFamily.GetTypefaceMetrics(canonicalStyle, canonicalWeight, canonicalStretch);
 
766
 
 
767
    //    return new CachedTypeface(
 
768
    //        canonicalStyle,
 
769
    //        canonicalWeight,
 
770
    //        canonicalStretch,
 
771
    //        firstFontFamily,
 
772
    //        typefaceMetrics,
 
773
    //        sourceFontFamily == null
 
774
    //        );
 
775
    //  }
 
776
    //}
 
777
  }
 
778
}