public void SetFontProperties(string family, float lineHeight, float size, string style, string variant, int weight)
        {
            _fontFamily  = new System.Windows.Media.FontFamily(FontMetricsProvider.toPlatformFontFamily(family, style));
            _fontStyle   = FontStyles.Normal;
            _fontStretch = FontStretches.Normal;

            if (style == "oblique")
            {
                _fontStyle = FontStyles.Oblique;
            }
            else if (style == "italic")
            {
                _fontStyle = FontStyles.Italic;
            }
            else //if (style == "normal")
            {
                _fontStyle = FontStyles.Normal;
            }

            if (weight >= 700)
            {
                _fontWeight = FontWeights.Bold;
            }
            else if (weight >= 400)
            {
                _fontWeight = FontWeights.Normal;
            }
            else
            {
                _fontWeight = FontWeights.Light;
            }

            _fontSize = size;
        }
Пример #2
0
        public void SetFontProperties(string family, float lineHeight, float size, string style, string variant, int weight)
        {
            _fontProperties.FontFamily = FontMetricsProvider.toPlatformFontFamily(family, style);

            switch (style)
            {
            case "oblique":
                _fontProperties.FontStyle = Windows.UI.Text.FontStyle.Oblique;
                break;

            case "italic":
                _fontProperties.FontStyle = Windows.UI.Text.FontStyle.Italic;
                break;

            default:     // "normal"
                _fontProperties.FontStyle = Windows.UI.Text.FontStyle.Normal;
                break;
            }

            if (weight >= 700)
            {
                _fontProperties.FontWeight = Windows.UI.Text.FontWeights.Bold;
            }
            else if (weight >= 400)
            {
                _fontProperties.FontWeight = Windows.UI.Text.FontWeights.Normal;
            }
            else
            {
                _fontProperties.FontWeight = Windows.UI.Text.FontWeights.Light;
            }

            _fontProperties.FontSize = size;

            using (var canvasTextLayout = new CanvasTextLayout(_session.Device, "k", _fontProperties, float.MaxValue, float.MaxValue))
            {
                _baseline = canvasTextLayout.LineMetrics[0].Baseline;
            }
        }