nsresult GDIFontEntry::CopyFontTable(uint32_t aTableTag, FallibleTArray<uint8_t>& aBuffer) { if (!IsTrueType()) { return NS_ERROR_FAILURE; } AutoDC dc; AutoSelectFont font(dc.GetDC(), &mLogFont); if (font.IsValid()) { uint32_t tableSize = ::GetFontData(dc.GetDC(), NativeEndian::swapToBigEndian(aTableTag), 0, nullptr, 0); if (tableSize != GDI_ERROR) { if (aBuffer.SetLength(tableSize)) { ::GetFontData(dc.GetDC(), NativeEndian::swapToBigEndian(aTableTag), 0, aBuffer.Elements(), tableSize); return NS_OK; } return NS_ERROR_OUT_OF_MEMORY; } } return NS_ERROR_FAILURE; }
already_AddRefed<DOMRequest> MobileMessageManager::Delete(const Sequence<OwningLongOrSmsMessageOrMmsMessage>& aParams, ErrorResult& aRv) { const uint32_t size = aParams.Length(); FallibleTArray<int32_t> idArray; if (!idArray.SetLength(size, fallible)) { aRv.Throw(NS_ERROR_OUT_OF_MEMORY); return nullptr; } DebugOnly<nsresult> rv; for (uint32_t i = 0; i < size; i++) { const OwningLongOrSmsMessageOrMmsMessage& element = aParams[i]; int32_t &id = idArray[i]; if (element.IsLong()) { id = element.GetAsLong(); } else if (element.IsMmsMessage()) { id = element.GetAsMmsMessage()->Id(); } else /*if (element.IsSmsMessage())*/ { id = element.GetAsSmsMessage()->Id(); } } return Delete(idArray.Elements(), size, aRv); }
nsresult FT2FontEntry::CopyFontTable(uint32_t aTableTag, FallibleTArray<uint8_t>& aBuffer) { AutoFTFace face(this); if (!face) { return NS_ERROR_FAILURE; } FT_Error status; FT_ULong len = 0; status = FT_Load_Sfnt_Table(face, aTableTag, 0, nullptr, &len); if (status != FT_Err_Ok || len == 0) { return NS_ERROR_FAILURE; } if (!aBuffer.SetLength(len)) { return NS_ERROR_OUT_OF_MEMORY; } uint8_t *buf = aBuffer.Elements(); status = FT_Load_Sfnt_Table(face, aTableTag, 0, buf, &len); NS_ENSURE_TRUE(status == FT_Err_Ok, NS_ERROR_FAILURE); return NS_OK; }
FileSystemResponseValue GetFilesTaskParent::GetSuccessRequestResult(ErrorResult& aRv) const { AssertIsOnBackgroundThread(); InfallibleTArray<PBlobParent*> blobs; FallibleTArray<FileSystemFileResponse> inputs; if (!inputs.SetLength(mTargetBlobImplArray.Length(), mozilla::fallible_t())) { aRv.Throw(NS_ERROR_OUT_OF_MEMORY); FileSystemFilesResponse response; return response; } for (unsigned i = 0; i < mTargetBlobImplArray.Length(); i++) { BlobParent* blobParent = BlobParent::GetOrCreate(mRequestParent->Manager(), mTargetBlobImplArray[i]); inputs[i] = FileSystemFileResponse(blobParent, nullptr); } FileSystemFilesResponse response; response.data().SwapElements(inputs); return response; }
bool gfxContext::CurrentDash(FallibleTArray<gfxFloat>& dashes, gfxFloat* offset) const { int count = cairo_get_dash_count(mCairo); if (count <= 0 || !dashes.SetLength(count)) { return false; } cairo_get_dash(mCairo, dashes.Elements(), offset); return true; }
bool gfxContext::CurrentDash(FallibleTArray<gfxFloat>& dashes, gfxFloat* offset) const { const AzureState &state = CurrentState(); int count = state.strokeOptions.mDashLength; if (count <= 0 || !dashes.SetLength(count, fallible)) { return false; } for (int i = 0; i < count; i++) { dashes[i] = state.dashPattern[i]; } *offset = state.strokeOptions.mDashOffset; return true; }
bool nsSVGGeometryFrame::GetStrokeDashData(FallibleTArray<gfxFloat>& dashes, gfxFloat *dashOffset) { PRUint32 count = GetStyleSVG()->mStrokeDasharrayLength; if (!count || !dashes.SetLength(count)) { return false; } gfxFloat pathScale = 1.0; if (mContent->Tag() == nsGkAtoms::path) { pathScale = static_cast<nsSVGPathElement*>(mContent)-> GetPathLengthScale(nsSVGPathElement::eForStroking); if (pathScale <= 0) { return false; } } nsSVGElement *ctx = static_cast<nsSVGElement*> (mContent->IsNodeOfType(nsINode::eTEXT) ? mContent->GetParent() : mContent); const nsStyleCoord *dasharray = GetStyleSVG()->mStrokeDasharray; nsPresContext *presContext = PresContext(); gfxFloat totalLength = 0.0; for (PRUint32 i = 0; i < count; i++) { dashes[i] = nsSVGUtils::CoordToFloat(presContext, ctx, dasharray[i]) * pathScale; if (dashes[i] < 0.0) { return false; } totalLength += dashes[i]; } *dashOffset = nsSVGUtils::CoordToFloat(presContext, ctx, GetStyleSVG()->mStrokeDashoffset); return (totalLength > 0.0); }
void StructuredCloneHelper::MoveBufferDataToArray(FallibleTArray<uint8_t>& aArray, ErrorResult& aRv) { MOZ_ASSERT(mBuffer, "MoveBuffer() cannot be called without a Write()."); if (NS_WARN_IF(!aArray.SetLength(BufferSize(), mozilla::fallible))) { aRv.Throw(NS_ERROR_OUT_OF_MEMORY); return; } uint64_t* buffer; size_t size; mBuffer->steal(&buffer, &size); mBuffer = nullptr; memcpy(aArray.Elements(), buffer, size); js_free(buffer); }
nsresult FT2FontEntry::GetFontTable(PRUint32 aTableTag, FallibleTArray<PRUint8>& aBuffer) { // Ensure existence of mFTFace CairoFontFace(); NS_ENSURE_TRUE(mFTFace, NS_ERROR_FAILURE); FT_Error status; FT_ULong len = 0; status = FT_Load_Sfnt_Table(mFTFace, aTableTag, 0, nsnull, &len); NS_ENSURE_TRUE(status == 0, NS_ERROR_FAILURE); NS_ENSURE_TRUE(len != 0, NS_ERROR_FAILURE); if (!aBuffer.SetLength(len)) { return NS_ERROR_OUT_OF_MEMORY; } PRUint8 *buf = aBuffer.Elements(); status = FT_Load_Sfnt_Table(mFTFace, aTableTag, 0, buf, &len); NS_ENSURE_TRUE(status == 0, NS_ERROR_FAILURE); return NS_OK; }
nsresult GDIFontEntry::GetFontTable(PRUint32 aTableTag, FallibleTArray<PRUint8>& aBuffer) { if (!IsTrueType()) { return NS_ERROR_FAILURE; } AutoDC dc; AutoSelectFont font(dc.GetDC(), &mLogFont); if (font.IsValid()) { PRInt32 tableSize = ::GetFontData(dc.GetDC(), NS_SWAP32(aTableTag), 0, NULL, NULL); if (tableSize != GDI_ERROR) { if (aBuffer.SetLength(tableSize)) { ::GetFontData(dc.GetDC(), NS_SWAP32(aTableTag), 0, aBuffer.Elements(), tableSize); return NS_OK; } return NS_ERROR_OUT_OF_MEMORY; } } return NS_ERROR_FAILURE; }
PRBool gfxFT2LockedFace::GetFontTable(PRUint32 aTag, FallibleTArray<PRUint8>& aBuffer) { if (!mFace || !FT_IS_SFNT(mFace)) return PR_FALSE; FT_ULong length = 0; // TRUETYPE_TAG is defined equivalent to FT_MAKE_TAG FT_Error error = FT_Load_Sfnt_Table(mFace, aTag, 0, NULL, &length); if (error != 0) return PR_FALSE; if (NS_UNLIKELY(length > static_cast<FallibleTArray<PRUint8>::size_type>(-1)) || NS_UNLIKELY(!aBuffer.SetLength(length))) return PR_FALSE; error = FT_Load_Sfnt_Table(mFace, aTag, 0, aBuffer.Elements(), &length); if (NS_UNLIKELY(error != 0)) { aBuffer.Clear(); return PR_FALSE; } return PR_TRUE; }
nsresult FT2FontEntry::GetFontTable(uint32_t aTableTag, FallibleTArray<uint8_t>& aBuffer) { // Ensure existence of mFTFace CairoFontFace(); NS_ENSURE_TRUE(mFTFace, NS_ERROR_FAILURE); FT_Error status; FT_ULong len = 0; status = FT_Load_Sfnt_Table(mFTFace, aTableTag, 0, nullptr, &len); if (status != FT_Err_Ok || len == 0) { return NS_ERROR_FAILURE; } if (!aBuffer.SetLength(len)) { return NS_ERROR_OUT_OF_MEMORY; } uint8_t *buf = aBuffer.Elements(); status = FT_Load_Sfnt_Table(mFTFace, aTableTag, 0, buf, &len); NS_ENSURE_TRUE(status == FT_Err_Ok, NS_ERROR_FAILURE); return NS_OK; }
bool gfxFT2LockedFace::GetFontTable(uint32_t aTag, FallibleTArray<uint8_t>& aBuffer) { if (!mFace || !FT_IS_SFNT(mFace)) return false; FT_ULong length = 0; // TRUETYPE_TAG is defined equivalent to FT_MAKE_TAG FT_Error error = FT_Load_Sfnt_Table(mFace, aTag, 0, NULL, &length); if (error != 0) return false; if (MOZ_UNLIKELY(length > static_cast<FallibleTArray<uint8_t>::size_type>(-1)) || MOZ_UNLIKELY(!aBuffer.SetLength(length))) return false; error = FT_Load_Sfnt_Table(mFace, aTag, 0, aBuffer.Elements(), &length); if (MOZ_UNLIKELY(error != 0)) { aBuffer.Clear(); return false; } return true; }
nsresult gfxDWriteFontEntry::CopyFontTable(uint32_t aTableTag, FallibleTArray<uint8_t> &aBuffer) { gfxDWriteFontList *pFontList = gfxDWriteFontList::PlatformFontList(); // Don't use GDI table loading for symbol fonts or for // italic fonts in Arabic-script system locales because of // potential cmap discrepancies, see bug 629386. // Ditto for Hebrew, bug 837498. if (mFont && pFontList->UseGDIFontTableAccess() && !(mItalic && UsingArabicOrHebrewScriptSystemLocale()) && !mFont->IsSymbolFont()) { LOGFONTW logfont = { 0 }; if (!InitLogFont(mFont, &logfont)) return NS_ERROR_FAILURE; AutoDC dc; AutoSelectFont font(dc.GetDC(), &logfont); if (font.IsValid()) { uint32_t tableSize = ::GetFontData(dc.GetDC(), NativeEndian::swapToBigEndian(aTableTag), 0, NULL, 0); if (tableSize != GDI_ERROR) { if (aBuffer.SetLength(tableSize)) { ::GetFontData(dc.GetDC(), NativeEndian::swapToBigEndian(aTableTag), 0, aBuffer.Elements(), aBuffer.Length()); return NS_OK; } return NS_ERROR_OUT_OF_MEMORY; } } return NS_ERROR_FAILURE; } nsRefPtr<IDWriteFontFace> fontFace; nsresult rv = CreateFontFace(getter_AddRefs(fontFace)); if (NS_FAILED(rv)) { return rv; } uint8_t *tableData; uint32_t len; void *tableContext = NULL; BOOL exists; HRESULT hr = fontFace->TryGetFontTable(NativeEndian::swapToBigEndian(aTableTag), (const void**)&tableData, &len, &tableContext, &exists); if (FAILED(hr) || !exists) { return NS_ERROR_FAILURE; } if (aBuffer.SetLength(len)) { memcpy(aBuffer.Elements(), tableData, len); rv = NS_OK; } else { rv = NS_ERROR_OUT_OF_MEMORY; } if (tableContext) { fontFace->ReleaseFontTable(&tableContext); } return rv; }
nsresult gfxDWriteFontEntry::GetFontTable(PRUint32 aTableTag, FallibleTArray<PRUint8> &aBuffer) { gfxDWriteFontList *pFontList = gfxDWriteFontList::PlatformFontList(); // don't use GDI table loading for symbol fonts or for // italic fonts in Arabic-script system locales because of // potential cmap discrepancies, see bug 629386 if (mFont && pFontList->UseGDIFontTableAccess() && !(mItalic && UsingArabicScriptSystemLocale()) && !mFont->IsSymbolFont()) { LOGFONTW logfont = { 0 }; if (!InitLogFont(mFont, &logfont)) return NS_ERROR_FAILURE; AutoDC dc; AutoSelectFont font(dc.GetDC(), &logfont); if (font.IsValid()) { PRInt32 tableSize = ::GetFontData(dc.GetDC(), NS_SWAP32(aTableTag), 0, NULL, NULL); if (tableSize != GDI_ERROR) { if (aBuffer.SetLength(tableSize)) { ::GetFontData(dc.GetDC(), NS_SWAP32(aTableTag), 0, aBuffer.Elements(), aBuffer.Length()); return NS_OK; } return NS_ERROR_OUT_OF_MEMORY; } } return NS_ERROR_FAILURE; } HRESULT hr; nsresult rv; nsRefPtr<IDWriteFontFace> fontFace; rv = CreateFontFace(getter_AddRefs(fontFace)); if (NS_FAILED(rv)) { return rv; } PRUint8 *tableData; PRUint32 len; void *tableContext = NULL; BOOL exists; hr = fontFace->TryGetFontTable(NS_SWAP32(aTableTag), (const void**)&tableData, &len, &tableContext, &exists); if (FAILED(hr) || !exists) { return NS_ERROR_FAILURE; } if (!aBuffer.SetLength(len)) { return NS_ERROR_OUT_OF_MEMORY; } memcpy(aBuffer.Elements(), tableData, len); if (tableContext) { fontFace->ReleaseFontTable(&tableContext); } return NS_OK; }