Click here to Skip to main content
15,891,864 members
Articles / Operating Systems / Windows

WPF Chart Control With Pan, Zoom and More

Rate me:
Please Sign up or sign in to vote.
4.92/5 (42 votes)
10 Dec 2012Public Domain10 min read 387.3K   10.9K   174  
Chart Control for Microsoft .NET 3.0/WPF with pan, zoom, and offline rendering to the clipboard for custom sizes.
// Copyright (c) Microsoft Corporation.  All rights reserved.

#include "stdafx.h"
#include "DWriteFontFace.h"
#include "DWriteFontFamily.h"

FontFaceType FontFace::FaceType::get()
{
    return static_cast<FontFaceType>(GetInterface<IDWriteFontFace>()->GetType());
}

UINT32 FontFace::Index::get()
{
    return GetInterface<IDWriteFontFace>()->GetIndex();
}

FontSimulations FontFace::Simulations::get()
{
    return static_cast<FontSimulations>(GetInterface<IDWriteFontFace>()->GetSimulations());
}

Boolean FontFace::IsSymbolFont::get()
{
    return GetInterface<IDWriteFontFace>()->IsSymbolFont() != 0;
}

FontMetrics FontFace::Metrics::get()
{
    DWRITE_FONT_METRICS metrics;
    GetInterface<IDWriteFontFace>()->GetMetrics(&metrics);

    return FontMetrics(metrics);
}

UINT16 FontFace::GlyphCount::get()
{
    return GetInterface<IDWriteFontFace>()->GetGlyphCount();
}

array<GlyphMetrics>^ FontFace::GetDesignGlyphMetrics(array<UINT16>^ glyphIndices, BOOL isSideways)
{
    array<GlyphMetrics>^ glyphMetrics = gcnew array<GlyphMetrics>(glyphIndices->Length);
    pin_ptr<UINT16> glyphIndicesPtr = &glyphIndices[0];

    pin_ptr<GlyphMetrics> glyphMetricsPtr = &glyphMetrics[0];
    
    CommonUtils::VerifyResult(GetInterface<IDWriteFontFace>()->GetDesignGlyphMetrics(glyphIndicesPtr, glyphIndices->Length, (DWRITE_GLYPH_METRICS*)glyphMetricsPtr, isSideways ? 1 : 0));

    return glyphMetrics;
}

array<GlyphMetrics>^ FontFace::GetDesignGlyphMetrics(array<UINT16>^ glyphIndices)
{
    return GetDesignGlyphMetrics(glyphIndices, false);
}

array<UINT16>^ FontFace::GetGlyphIndices(array<UINT32>^ codePoints)
{
    array<UINT16>^ glyphIndices = gcnew array<UINT16>(codePoints->Length);
    pin_ptr<UINT16> glyphIndicesPtr = &glyphIndices[0];

    pin_ptr<UINT32> codePointsPtr = &codePoints[0];    
    CommonUtils::VerifyResult(GetInterface<IDWriteFontFace>()->GetGlyphIndicesW(codePointsPtr, codePoints->Length, glyphIndicesPtr));

    return glyphIndices;
}

array<UINT16>^ FontFace::GetGlyphIndices(array<System::Char>^ chars)
{
    array<UINT16>^ glyphIndices = gcnew array<UINT16>(chars->Length);
    pin_ptr<UINT16> glyphIndicesPtr = &glyphIndices[0];

    array<UINT32>^ codePoints = gcnew array<UINT32>(chars->Length);
    for (int i = 0; i < chars->Length; i++)
    {
        codePoints[i] = Convert::ToUInt32(chars[i]);
    }

    pin_ptr<UINT32> codePointsPtr = &codePoints[0];    
    CommonUtils::VerifyResult(GetInterface<IDWriteFontFace>()->GetGlyphIndicesW(codePointsPtr, codePoints->Length, glyphIndicesPtr));

    return glyphIndices;
}

array<UINT16>^ FontFace::GetGlyphIndices(System::String^ textString)
{
    array<UINT16>^ glyphIndices = gcnew array<UINT16>(textString->Length);
    pin_ptr<UINT16> glyphIndicesPtr = &glyphIndices[0];

    array<UINT32>^ codePoints = gcnew array<UINT32>(textString->Length);
    for (int i = 0; i < textString->Length; i++)
    {
        codePoints[i] = Convert::ToUInt32(textString[i]);
    }

    pin_ptr<UINT32> codePointsPtr = &codePoints[0];    
    CommonUtils::VerifyResult(GetInterface<IDWriteFontFace>()->GetGlyphIndicesW(codePointsPtr, codePoints->Length, glyphIndicesPtr));

    return glyphIndices;
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under A Public Domain dedication


Written By
Founder Cheesy Design
Taiwan Taiwan
John graduated from the University of South Australia in 1997 with a Bachelor of Electronic Engineering Degree, and since then he has worked on hardware and software in many fields including Aerospace, Defence, and Medical giving him over 10 of years experience in C++ and C# programming. In 2009 John Started his own contracting company doing business between Taiwan and Australia.

Comments and Discussions