예제 #1
0
        private void AddFontFamily(FontFamily family)
        {
            string      familyName;
            CultureInfo familyCulture;

            // First try getting a name in the user's language.
            familyCulture = CultureInfo.CurrentUICulture;
            family.FamilyNames.TryGetValue(familyCulture, out familyName);

            if (familyName == null)
            {
                // Fall back to en-US culture. This is somewhat arbitrary, but most fonts have English
                // strings so this at least yields predictable fallback behavior in most cases.
                familyCulture = enUSCulture;
                family.FamilyNames.TryGetValue(familyCulture, out familyName);
            }

            if (familyName == null)
            {
                // As a last resort, use the first name we find. This will just be the name associated
                // with whatever locale name sorts first alphabetically.
                foreach (KeyValuePair <CultureInfo, string> entry in family.FamilyNames)
                {
                    familyCulture = entry.Key;
                    familyName    = entry.Value;
                }
            }

            if (familyName == null)
            {
                return;
            }

            //add info to list of structs used as a cache of text layouts
            var displayFormats = new List <TextLayout>();
            var format         = dwriteFactory.CreateTextFormat(
                family.Fonts[0].IsSymbolFont ? Font.FontFamily.Name : familyName,
                DropDownFontSize,
                FontWeight.Normal,
                FontStyle.Normal,
                FontStretch.Normal,
                familyCulture);

            format.WordWrapping = WordWrapping.NoWrap;
            var layout = dwriteFactory.CreateTextLayout(
                familyName,
                format,
                10000,
                10000);

            DropDownWidth = Math.Max(DropDownWidth, (int)layout.Metrics.Width);
            maxHeight     = Math.Max(maxHeight, layout.Metrics.Height);
            displayFormats.Add(layout);
            //add name to list
            primaryNames.Add(familyName);
            layouts.Add(familyName, layout);
        }
예제 #2
0
        private void CreateDeviceIndependentResources()
        {
            // Create the D2D Factory
            d2dFactory = D2DFactory.CreateFactory(D2DFactoryType.SingleThreaded);

            // Create the DWrite Factory
            dwriteFactory = DWriteFactory.CreateFactory();

            wicFactory = new ImagingFactory();

            string text = "Inline Object * Sample";

            textFormat = dwriteFactory.CreateTextFormat("Gabriola", 72);

            textFormat.TextAlignment = DWrite.TextAlignment.Center;
            textFormat.ParagraphAlignment = DWrite.ParagraphAlignment.Center;
    
            textLayout = dwriteFactory.CreateTextLayout(
                text,
                textFormat,
                (float) host.ActualWidth,
                (float) host.ActualHeight);
        }
예제 #3
0
        private void CreateDeviceIndependentResources()
        {
            // Create the D2D Factory
            d2dFactory = D2DFactory.CreateFactory(D2DFactoryType.SingleThreaded);

            // Create the DWrite Factory
            dwriteFactory = DWriteFactory.CreateFactory();

            wicFactory = ImagingFactory.Create();

            string text = "Inline Object * Sample";

            textFormat = dwriteFactory.CreateTextFormat("Gabriola", 72);

            textFormat.TextAlignment      = DWrite.TextAlignment.Center;
            textFormat.ParagraphAlignment = DWrite.ParagraphAlignment.Center;

            textLayout = dwriteFactory.CreateTextLayout(
                text,
                textFormat,
                (float)host.ActualWidth,
                (float)host.ActualHeight);
        }
예제 #4
0
        private void Render()
        {
            CreateDeviceResources();

            if (renderTarget.IsOccluded)
            {
                return;
            }

            SizeF renderTargetSize = renderTarget.Size;

            renderTarget.BeginDraw();

            renderTarget.Clear(new ColorF(1, 1, 1, 0));

            // Paint a grid background.
            RectF rf = new RectF(0.0f, 0.0f, renderTargetSize.Width, renderTargetSize.Height);

            renderTarget.FillRectangle(rf, gridPatternBitmapBrush);

            float curLeft = 0;

            rf = new RectF(
                curLeft,
                renderTargetSize.Height,
                (curLeft + renderTargetSize.Width / 5.0F),
                renderTargetSize.Height - renderTargetSize.Height * ((float)x1 / 100.0F));

            renderTarget.FillRectangle(rf, solidBrush1);

            textLayout = dwriteFactory.CreateTextLayout(String.Format("  {0}%", x1), textFormat, renderTargetSize.Width / 5.0F, 30);

            renderTarget.DrawTextLayout(
                new Point2F(curLeft, renderTargetSize.Height - 30),
                textLayout,
                blackBrush);

            curLeft = (curLeft + renderTargetSize.Width / 5.0F);
            rf      = new RectF(
                curLeft,
                renderTargetSize.Height,
                (curLeft + renderTargetSize.Width / 5.0F),
                renderTargetSize.Height - renderTargetSize.Height * ((float)x2 / 100.0F));
            renderTarget.FillRectangle(rf, radialGradientBrush);
            renderTarget.DrawText(
                String.Format("  {0}%", x2),
                textFormat,
                new RectF(curLeft, renderTargetSize.Height - 30, (curLeft + renderTargetSize.Width / 5.0F), renderTargetSize.Height), blackBrush);

            curLeft = (curLeft + renderTargetSize.Width / 5.0F);
            rf      = new RectF(
                curLeft,
                renderTargetSize.Height,
                (curLeft + renderTargetSize.Width / 5.0F),
                renderTargetSize.Height - renderTargetSize.Height * ((float)x3 / 100.0F));
            renderTarget.FillRectangle(rf, solidBrush3);
            renderTarget.DrawText(
                String.Format("  {0}%", x3),
                textFormat,
                new RectF(curLeft, renderTargetSize.Height - 30, (curLeft + renderTargetSize.Width / 5.0F), renderTargetSize.Height), blackBrush);

            curLeft = (curLeft + renderTargetSize.Width / 5.0F);
            rf      = new RectF(
                curLeft,
                renderTargetSize.Height,
                (curLeft + renderTargetSize.Width / 5.0F),
                renderTargetSize.Height - renderTargetSize.Height * ((float)x4 / 100.0F));
            renderTarget.FillRectangle(rf, linearGradientBrush);
            renderTarget.DrawText(
                String.Format("  {0}%", x4),
                textFormat,
                new RectF(curLeft, renderTargetSize.Height - 30, (curLeft + renderTargetSize.Width / 5.0F), renderTargetSize.Height), blackBrush);


            curLeft = (curLeft + renderTargetSize.Width / 5.0F);
            rf      = new RectF(
                curLeft,
                renderTargetSize.Height,
                (curLeft + renderTargetSize.Width / 5.0F),
                renderTargetSize.Height - renderTargetSize.Height * ((float)x5 / 100.0F));
            renderTarget.FillRectangle(rf, solidBrush2);
            renderTarget.DrawText(
                String.Format("  {0}%", x5),
                textFormat,
                new RectF(curLeft, renderTargetSize.Height - 30, (curLeft + renderTargetSize.Width / 5.0F), renderTargetSize.Height), blackBrush);

            renderTarget.EndDraw();
        }