locked
Problem with CreateEllipsisTrimmingSign

    Question

  • Hi all,

    I'm trying to trim some text I'm drawing on a SurfaceImageSource.
    I do this by using this piece of code.

    IDWriteInlineObject* inlineObject = NULL; m_dwriteFactory->CreateEllipsisTrimmingSign( m_textLayout.Get(), &inlineObject );

    const static DWRITE_TRIMMING trimming = { DWRITE_TRIMMING_GRANULARITY_NONE, 0, 0 }; if(inlineObject!=nullptr) { m_textLayout->SetTrimming(&trimming, inlineObject); }

    Unfortunately, the inlineObject is always null.
    Am I doing something wrong?

    Kind regards,
    Annihil8

    Saturday, April 13, 2013 10:58 PM

Answers

  • I'll fix up the code error above shortly. Using the DWriteInlineObject sample from the official Windows 8 Apps samples as a starting point, I could not replicate the error except when I passed in an m_textLayout that was null. All other attempts succeeded, even ones where I used a character that did not exist in Segoe UI within the text layout string.

    Before the call to CreateEllipsisTrimmingSign, try adding the following:

    	if (m_textLayout == nullptr)
    	{
    		throw ref new Platform::NullReferenceException(L"m_textLayout is null.\n");
    	}
    

    See if it gives you a NullReferenceException with that message. It could be that either something is inadvertently setting m_textLayout to null or else that m_textLayout is only being created later in the program's execution such that it is still null when you try to use it for CreateEllipsisTrimmingSign.

    If that's not it, can you post the value that's assigned to the "content" Platform::String which you are creating m_textLayout with? That might help me replicate the error. Or else if you could create a repro project, zip it up, upload it to your SkyDrive and post a link to it here so I could try to figure out what's going on.


    Visual C++ MVP | Website | Blog | @mikebmcl | Windows Store DirectX Game Template

    • Marked as answer by Jesse Jiang Monday, May 6, 2013 7:13 AM
    Monday, April 15, 2013 4:33 AM

All replies

  • IDWriteFactory::CreateEllipsisTrimmingSign returns an HRESULT which will be S_OK if it succeeded or otherwise will be a failure HRESULT value which will indicate better what might have gone wrong. Your code is ignoring that value.

    Also, you should strong consider using a ComPtr (from wrl.h) to hold a COM object just as IDWriteInlineObject, e.g.:

    Microsoft::WRL::ComPtr<IDWriteInlineObject> inlineObject;
    
    HRESULT hr = m_dwriteFactory->CreateEllipsisTrimmingSign(
        m_textLayout.Get(),
        &inlineObject
        );
    
    if (FAILED(hr))
    {
        throw Platform::Exception::CreateException(hr);
    }
    
    const static DWRITE_TRIMMING trimming = { DWRITE_TRIMMING_GRANULARITY_NONE, 0, 0 };
    
    if (inlineObject != nullptr)
    {
        hr = m_textLayout->SetTrimming(&trimming, inlineObject.Get());
        if (FAILED(hr))
        {
            throw Platform::Exception::CreateException(hr);
        }
    }

    Knowing what HRESULT you are getting back might provide more input into what is going wrong. Have you checked to ensure that m_textLayout.Get() != nullptr ?

    Visual C++ MVP | Website | Blog | @mikebmcl | Windows Store DirectX Game Template


    • Edited by MikeBMcLMVP Monday, April 15, 2013 4:34 AM Fixed omission of .Get() in code sample
    Sunday, April 14, 2013 5:41 AM
  • Hi Mike,

    Thank you for your quick response!

    I had to change the next line of code to make it compile:

    hr = m_textLayout->SetTrimming(&trimming, inlineObject.Get());
    The thrown exception now is:

    A first chance exception of type 'System.ArgumentException' occurred in SurfaceImageSource.exe

    WinRT information: The parameter is incorrect.

    Don't know which of the two failed as the error is thrown now at the code behind of the mainwindows.xaml where the Draw method is called on the c++ component.

    EDIT: Forget that last line due to a stupidity of me ;)

    It is the CreateEllipsisTrimmingSign call that fails...

    The parameter &m_textLayout  =

    m_dwriteFactory->CreateTextLayout( content->Data(), content->Length(), nameTextFormat.Get(), rect.Width-20-startTextPosition, 20, &m_textLayout );

    Format creation

    DX::ThrowIfFailed(
    		m_dwriteFactory->CreateTextFormat(
    		L"Segoe UI",
    		nullptr,
    		DWRITE_FONT_WEIGHT_DEMI_BOLD,
    		DWRITE_FONT_STYLE_NORMAL,
    		DWRITE_FONT_STRETCH_NORMAL,
    		14.0f,
    		L"en-US",
    		&nameTextFormat
    		)
    		);
    
    	DX::ThrowIfFailed(
    		nameTextFormat->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_LEADING)
    		);
    
    	DX::ThrowIfFailed(
    		nameTextFormat->SetParagraphAlignment(DWRITE_PARAGRAPH_ALIGNMENT_NEAR)
    		);
    
    	DX::ThrowIfFailed(
    		nameTextFormat->SetWordWrapping(DWRITE_WORD_WRAPPING_WRAP)
    		);

    Regards,

    Annihil8





    • Edited by Annihil8 Sunday, April 14, 2013 8:03 AM wrong info provided
    Sunday, April 14, 2013 7:54 AM
  • I'll fix up the code error above shortly. Using the DWriteInlineObject sample from the official Windows 8 Apps samples as a starting point, I could not replicate the error except when I passed in an m_textLayout that was null. All other attempts succeeded, even ones where I used a character that did not exist in Segoe UI within the text layout string.

    Before the call to CreateEllipsisTrimmingSign, try adding the following:

    	if (m_textLayout == nullptr)
    	{
    		throw ref new Platform::NullReferenceException(L"m_textLayout is null.\n");
    	}
    

    See if it gives you a NullReferenceException with that message. It could be that either something is inadvertently setting m_textLayout to null or else that m_textLayout is only being created later in the program's execution such that it is still null when you try to use it for CreateEllipsisTrimmingSign.

    If that's not it, can you post the value that's assigned to the "content" Platform::String which you are creating m_textLayout with? That might help me replicate the error. Or else if you could create a repro project, zip it up, upload it to your SkyDrive and post a link to it here so I could try to figure out what's going on.


    Visual C++ MVP | Website | Blog | @mikebmcl | Windows Store DirectX Game Template

    • Marked as answer by Jesse Jiang Monday, May 6, 2013 7:13 AM
    Monday, April 15, 2013 4:33 AM