1

カスタム フォントを使用して、グラフにプロットする道路標識と形状を表します。

最初はすべてをキャンバスにプロットしましたが、うまくいきましたが、水平方向のスクロールが遅かったです。

次に、次のように、WriteableBitmap を使用してキャンバスを画像に変換することで、スクロールの問題を修正しました。

#if SILVERLIGHT
    ImageSource ConvertCanvas(Canvas canvas) {

        WriteableBitmap Source = new WriteableBitmap(canvas, /* transform = */ null);

        Source.Invalidate();

        return Source;
    }
#endif

この変換は、カスタム フォントを使用する TextBlocks を除いて、キャンバス上のほとんどの要素に対して正常に機能します。

したがって、適切な「カスタム フォント」画像 (文字) の代わりに、「p」、「q」などの通常の Arial 文字を取得します...

変換された画像の代わりにキャンバスを再度表示すると、カスタム フォントが機能し、テキストブロックが正しくレンダリングされることを確認できるため、読み込みの問題ではないようです...

私が調べることができるいくつかの指針を助けてください...

前もって感謝します

編集:

OK、ここで解決策を見つけました。これは、1.変換を行う前にフォントを使用する非表示のテキストブロックを作成するか、2.FontSource を作成することです。

今のところは最初の方が簡単だったので、最初のものを使用しました。

コントロール内に、次を追加しました。

void Grid_Loaded(object sender, RoutedEventArgs e) {
#if SILVERLIGHT
        Grid Grid = (Grid)sender;
        AddFontLoaderTextBox(Grid, "Signs Road Features");
        AddFontLoaderTextBox(Grid, "Signs G Old");
        AddFontLoaderTextBox(Grid, "Signs G");
        AddFontLoaderTextBox(Grid, "Signs G1");
        AddFontLoaderTextBox(Grid, "Signs G2");
        AddFontLoaderTextBox(Grid, "Signs G3");
        AddFontLoaderTextBox(Grid, "Signs Info");
        AddFontLoaderTextBox(Grid, "Signs Regulatory");
        AddFontLoaderTextBox(Grid, "Signs Regulatory1");
        AddFontLoaderTextBox(Grid, "Road Manager");
        AddFontLoaderTextBox(Grid, "Signs Temporary");
        AddFontLoaderTextBox(Grid, "Road Manager");
        AddFontLoaderTextBox(Grid, "Signs Warning");
        AddFontLoaderTextBox(Grid, "Signs Warning1");
#endif
    }

#if SILVERLIGHT
    void AddFontLoaderTextBox(Grid Grid, string fontName) {

        TextBlock TextBlock = new TextBlock();
        TextBlock.FontFamily = new FontFamily(string.Format(
            "pack://application:,,,/ITIS.Controls.LinearViewer.Silverlight;component/Fonts/{0}.ttf#{0}", fontName));
        TextBlock.Opacity = 0; /* hide the text block, we only load it for the font to be cached */
        Grid.SetRowSpan(TextBlock, 3); /* just to ensure the text block doesn't affect the size of the first row */
        Grid.Children.Insert(0, TextBlock); /* keep underneath other children */
    }
#endif
4

0 に答える 0