TextAnalyzerHelper.cpp [plain text]
#include "config.h"
#include "TextAnalyzerHelper.h"
#if USE(DIRECT2D)
namespace WebCore {
TextAnalyzerHelper::TextAnalyzerHelper(WCHAR* localeName, WCHAR* buffer, unsigned bufferLength)
: m_localeName(localeName)
, m_buffer(buffer)
, m_bufferLength(bufferLength)
{
}
HRESULT TextAnalyzerHelper::QueryInterface(_In_ REFIID riid, _COM_Outptr_ void** ppvObject)
{
if (!ppvObject)
return E_POINTER;
*ppvObject = nullptr;
if (IsEqualGUID(riid, __uuidof(IDWriteTextAnalysisSink)))
*ppvObject = static_cast<IDWriteTextAnalysisSink*>(this);
else if (IsEqualGUID(riid, __uuidof(IDWriteTextAnalysisSource)))
*ppvObject = static_cast<IDWriteTextAnalysisSink*>(this);
else
return E_FAIL;
AddRef();
return S_OK;
}
ULONG TextAnalyzerHelper::AddRef()
{
return ++m_refCount;
}
ULONG TextAnalyzerHelper::Release()
{
ULONG newRef = --m_refCount;
if (!newRef)
delete(this);
return newRef;
}
HRESULT TextAnalyzerHelper::GetTextAtPosition(UINT32 textPosition, const WCHAR** textString, UINT32* textLength)
{
if (!textString || !textLength)
return E_POINTER;
if (textPosition >= m_bufferLength) {
*textString = nullptr;
*textLength = 0;
return S_OK;
}
*textString = &m_buffer[textPosition];
*textLength = m_bufferLength - textPosition;
return S_OK;
}
HRESULT TextAnalyzerHelper::GetTextBeforePosition(UINT32 textPosition, const WCHAR** textString, UINT32* textLength)
{
if (!textString || !textLength)
return E_POINTER;
if (!textPosition || textPosition > m_bufferLength) {
*textString = nullptr;
*textLength = 0;
return S_OK;
}
*textString = &m_buffer[0];
*textLength = textPosition;
return S_OK;
}
HRESULT TextAnalyzerHelper::GetLocaleName(UINT32 textPosition, UINT32* textLength, const WCHAR** localeName)
{
*localeName = m_localeName;
*textLength = m_bufferLength - textPosition;
return S_OK;
}
HRESULT TextAnalyzerHelper::GetNumberSubstitution(UINT32 textPosition, UINT32* textLength, IDWriteNumberSubstitution** numberSubstitution)
{
*textLength = m_bufferLength - textPosition;
return S_OK;
}
HRESULT TextAnalyzerHelper::SetLineBreakpoints(UINT32 textPosition, UINT32 textLength, const DWRITE_LINE_BREAKPOINT*)
{
return E_NOTIMPL;
}
HRESULT TextAnalyzerHelper::SetScriptAnalysis(UINT32 textPosition, UINT32 textLength, const DWRITE_SCRIPT_ANALYSIS* analysis)
{
m_analysis = *analysis;
return S_OK;
}
HRESULT TextAnalyzerHelper::SetBidiLevel(UINT32 textPosition, UINT32 textLength, UINT8 explicitLevel, UINT8 resolvedLevel)
{
return E_NOTIMPL;
}
HRESULT TextAnalyzerHelper::SetNumberSubstitution(UINT32 textPosition, UINT32 textLength, IDWriteNumberSubstitution*)
{
return E_NOTIMPL;
}
}
#endif