예제 #1
0
            public static int CalculateLineSpacing(this Typeface typeface, LineSpacingChoice choice)
            {
                switch (choice)
                {
                default:
                case LineSpacingChoice.Windows:
                    return(Calculate_BTBD_Windows(typeface));

                case LineSpacingChoice.Mac:
                    return(CalculateBTBD_Mac(typeface));

                case LineSpacingChoice.TypoMetric:
                    return(Calculate_TypoMetricLineSpacing(typeface));
                }
            }
예제 #2
0
 public static int CalculateRecommendLineSpacing(this Typeface typeface, out LineSpacingChoice choice)
 {
     if (RecommendToUseTypoMetricsForLineSpacing(typeface))
     {
         choice = LineSpacingChoice.TypoMetric;
         return(Calculate_TypoMetricLineSpacing(typeface));
     }
     else
     {
         //check if we are on Windows or mac
         if (CurrentEnv.CurrentOSName == CurrentOSName.Mac)
         {
             choice = LineSpacingChoice.Mac;
             return(CalculateBTBD_Mac(typeface));
         }
         else
         {
             choice = LineSpacingChoice.Windows;
             return(Calculate_BTBD_Windows(typeface));
         }
     }
 }
예제 #3
0
            public static int CalculateRecommendLineSpacing(this Typeface typeface, out LineSpacingChoice choice)
            {
                //from https://docs.microsoft.com/en-us/typography/opentype/spec/os2#wa
                //usWinAscent
                //Format:   uint16
                //Description:
                //The “Windows ascender” metric.
                //This should be used to specify the height above the baseline for a clipping region.

                //This is similar to the sTypoAscender field,
                //and also to the ascender field in the 'hhea' table.
                //There are important differences between these, however.

                //In the Windows GDI implementation,
                //the usWinAscent and usWinDescent values have been used to determine
                //the size of the bitmap surface in the TrueType rasterizer.
                //Windows GDI will clip any portion of a TrueType glyph outline that appears above the usWinAscent value.
                //If any clipping is unacceptable, then the value should be set greater than or equal to yMax.

                //Note: This pertains to the default position of glyphs,
                //not their final position in layout after data from the GPOS or 'kern' table has been applied.
                //Also, this clipping behavior also interacts with the VDMX table:
                //if a VDMX table is present and there is data for the current device aspect ratio and rasterization size,
                //then the VDMX data will supersede the usWinAscent and usWinDescent values.

                //****
                //Some legacy applications use the usWinAscent and usWinDescent values to determine default line spacing.
                //This is **strongly discouraged**. The sTypo* fields should be used for this purpose.

                //Note that some applications use either the usWin* values or the sTypo* values to determine default line spacing,
                //depending on whether the USE_TYPO_METRICS flag (bit 7) of the fsSelection field is set.
                //This may be useful to provide **compatibility with legacy documents using older fonts**,
                //while also providing better and more-portable layout using newer fonts.
                //See fsSelection for additional details.

                //Applications that use the sTypo* fields for default line spacing can use the usWin*
                //values to determine the size of a clipping region.
                //Some applications use a clipping region for editing scenarios to determine what portion of the display surface to re-draw when text is edited, or how large a selection rectangle to draw when text is selected. This is an appropriate use for the usWin* values.

                //Early versions of this specification suggested that the usWinAscent value be computed as the yMax
                //for all characters in the Windows “ANSI” character set.

                //For new fonts, the value should be determined based on the primary languages the font is designed to support,
                //and **should take into consideration additional height that may be required to accommodate tall glyphs or mark positioning.***

                //-----------------------------------------------------------------------------------
                //usWinDescent
                //Format:   uint16
                //Description:
                //The “Windows descender” metric.This should be used to specify the vertical extent
                //below the baseline for a clipping region.

                //This is similar to the sTypoDescender field,
                //and also to the descender field in the 'hhea' table.

                //***
                //There are important differences between these, however.
                //Some of these differences are described below.
                //In addition, the usWinDescent value treats distances below the baseline as positive values;
                //thus, usWinDescent is usually a positive value, while sTypoDescender and hhea.descender are usually negative.

                //In the Windows GDI implementation,
                //the usWinDescent and usWinAscent values have been used
                //to determine the size of the bitmap surface in the TrueType rasterizer.
                //Windows GDI will clip any portion of a TrueType glyph outline that appears below(-1 × usWinDescent).
                //If any clipping is unacceptable, then the value should be set greater than or equal to(-yMin).

                //Note: This pertains to the default position of glyphs,
                //not their final position in layout after data from the GPOS or 'kern' table has been applied.
                //Also, this clipping behavior also interacts with the VDMX table:
                //if a VDMX table is present and there is data for the current device aspect ratio and rasterization size,
                //***then the VDMX data will supersede the usWinAscent and usWinDescent values.****
                //-----------------------------------------------------------------------------------

                //so ...
                choice = LineSpacingChoice.TypoMetric;
                return(Calculate_TypoMetricLineSpacing(typeface));

                //if (RecommendToUseTypoMetricsForLineSpacing(typeface))
                //{
                //    choice = LineSpacingChoice.TypoMetric;
                //    return Calculate_TypoMetricLineSpacing(typeface);
                //}
                //else
                //{
                //    //check if we are on Windows or mac
                //    if (CurrentEnv.CurrentOSName == CurrentOSName.Mac)
                //    {
                //        choice = LineSpacingChoice.Mac;
                //        return CalculateBTBD_Mac(typeface);
                //    }
                //    else
                //    {
                //        choice = LineSpacingChoice.Windows;
                //        return Calculate_BTBD_Windows(typeface);
                //    }
                //}
            }