2016-01-05 10:08:57 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_layout_PrintTranslator_h
|
|
|
|
#define mozilla_layout_PrintTranslator_h
|
|
|
|
|
|
|
|
#include <istream>
|
|
|
|
|
|
|
|
#include "mozilla/gfx/2D.h"
|
|
|
|
#include "mozilla/gfx/Filters.h"
|
|
|
|
#include "mozilla/gfx/RecordedEvent.h"
|
|
|
|
#include "nsRefPtrHashtable.h"
|
|
|
|
|
|
|
|
class nsDeviceContext;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace layout {
|
|
|
|
|
|
|
|
using gfx::Translator;
|
|
|
|
using gfx::ReferencePtr;
|
|
|
|
using gfx::DrawTarget;
|
|
|
|
using gfx::Path;
|
|
|
|
using gfx::SourceSurface;
|
|
|
|
using gfx::FilterNode;
|
|
|
|
using gfx::GradientStops;
|
|
|
|
using gfx::ScaledFont;
|
2016-01-05 10:08:58 +00:00
|
|
|
using gfx::NativeFontResource;
|
2016-01-05 10:08:57 +00:00
|
|
|
|
|
|
|
class PrintTranslator final : public Translator
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit PrintTranslator(nsDeviceContext* aDeviceContext);
|
|
|
|
|
|
|
|
bool TranslateRecording(std::istream& aRecording);
|
|
|
|
|
|
|
|
DrawTarget* LookupDrawTarget(ReferencePtr aRefPtr) final
|
|
|
|
{
|
2016-01-05 10:08:58 +00:00
|
|
|
DrawTarget* result = mDrawTargets.GetWeak(aRefPtr);
|
|
|
|
MOZ_ASSERT(result);
|
|
|
|
return result;
|
2016-01-05 10:08:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Path* LookupPath(ReferencePtr aRefPtr) final
|
|
|
|
{
|
2016-01-05 10:08:58 +00:00
|
|
|
Path* result = mPaths.GetWeak(aRefPtr);
|
|
|
|
MOZ_ASSERT(result);
|
|
|
|
return result;
|
2016-01-05 10:08:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SourceSurface* LookupSourceSurface(ReferencePtr aRefPtr) final
|
|
|
|
{
|
2016-01-05 10:08:58 +00:00
|
|
|
SourceSurface* result = mSourceSurfaces.GetWeak(aRefPtr);
|
|
|
|
MOZ_ASSERT(result);
|
|
|
|
return result;
|
2016-01-05 10:08:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
FilterNode* LookupFilterNode(ReferencePtr aRefPtr) final
|
|
|
|
{
|
2016-01-05 10:08:58 +00:00
|
|
|
FilterNode* result = mFilterNodes.GetWeak(aRefPtr);
|
|
|
|
MOZ_ASSERT(result);
|
|
|
|
return result;
|
2016-01-05 10:08:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GradientStops* LookupGradientStops(ReferencePtr aRefPtr) final
|
|
|
|
{
|
2016-01-05 10:08:58 +00:00
|
|
|
GradientStops* result = mGradientStops.GetWeak(aRefPtr);
|
|
|
|
MOZ_ASSERT(result);
|
|
|
|
return result;
|
2016-01-05 10:08:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ScaledFont* LookupScaledFont(ReferencePtr aRefPtr) final
|
|
|
|
{
|
2016-01-05 10:08:58 +00:00
|
|
|
ScaledFont* result = mScaledFonts.GetWeak(aRefPtr);
|
|
|
|
MOZ_ASSERT(result);
|
|
|
|
return result;
|
2016-01-05 10:08:57 +00:00
|
|
|
}
|
|
|
|
|
2016-01-05 10:08:58 +00:00
|
|
|
NativeFontResource* LookupNativeFontResource(uint64_t aKey) final
|
|
|
|
{
|
|
|
|
NativeFontResource* result = mNativeFontResources.GetWeak(aKey);
|
|
|
|
MOZ_ASSERT(result);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-01-05 10:08:57 +00:00
|
|
|
void AddDrawTarget(ReferencePtr aRefPtr, DrawTarget *aDT) final
|
|
|
|
{
|
|
|
|
mDrawTargets.Put(aRefPtr, aDT);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AddPath(ReferencePtr aRefPtr, Path *aPath) final
|
|
|
|
{
|
|
|
|
mPaths.Put(aRefPtr, aPath);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AddSourceSurface(ReferencePtr aRefPtr, SourceSurface *aSurface) final
|
|
|
|
{
|
|
|
|
mSourceSurfaces.Put(aRefPtr, aSurface);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AddFilterNode(ReferencePtr aRefPtr, FilterNode *aFilter) final
|
|
|
|
{
|
|
|
|
mFilterNodes.Put(aRefPtr, aFilter);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AddGradientStops(ReferencePtr aRefPtr, GradientStops *aStops) final
|
|
|
|
{
|
|
|
|
mGradientStops.Put(aRefPtr, aStops);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AddScaledFont(ReferencePtr aRefPtr, ScaledFont *aScaledFont) final
|
|
|
|
{
|
|
|
|
mScaledFonts.Put(aRefPtr, aScaledFont);
|
2016-01-05 10:08:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AddNativeFontResource(uint64_t aKey,
|
|
|
|
NativeFontResource *aScaledFontResouce) final
|
|
|
|
{
|
|
|
|
mNativeFontResources.Put(aKey, aScaledFontResouce);
|
2016-01-05 10:08:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RemoveDrawTarget(ReferencePtr aRefPtr) final
|
|
|
|
{
|
|
|
|
mDrawTargets.Remove(aRefPtr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RemovePath(ReferencePtr aRefPtr) final
|
|
|
|
{
|
|
|
|
mPaths.Remove(aRefPtr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RemoveSourceSurface(ReferencePtr aRefPtr) final
|
|
|
|
{
|
|
|
|
mSourceSurfaces.Remove(aRefPtr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RemoveFilterNode(ReferencePtr aRefPtr) final
|
|
|
|
{
|
|
|
|
mFilterNodes.Remove(aRefPtr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RemoveGradientStops(ReferencePtr aRefPtr) final
|
|
|
|
{
|
|
|
|
mGradientStops.Remove(aRefPtr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RemoveScaledFont(ReferencePtr aRefPtr) final
|
|
|
|
{
|
|
|
|
mScaledFonts.Remove(aRefPtr);
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<DrawTarget> CreateDrawTarget(ReferencePtr aRefPtr,
|
|
|
|
const gfx::IntSize &aSize,
|
|
|
|
gfx::SurfaceFormat aFormat) final;
|
|
|
|
|
|
|
|
mozilla::gfx::DrawTarget* GetReferenceDrawTarget() final { return mBaseDT; }
|
|
|
|
|
|
|
|
mozilla::gfx::FontType GetDesiredFontType() final;
|
|
|
|
|
|
|
|
private:
|
|
|
|
RefPtr<nsDeviceContext> mDeviceContext;
|
|
|
|
RefPtr<DrawTarget> mBaseDT;
|
|
|
|
|
|
|
|
nsRefPtrHashtable<nsPtrHashKey<void>, DrawTarget> mDrawTargets;
|
|
|
|
nsRefPtrHashtable<nsPtrHashKey<void>, Path> mPaths;
|
|
|
|
nsRefPtrHashtable<nsPtrHashKey<void>, SourceSurface> mSourceSurfaces;
|
|
|
|
nsRefPtrHashtable<nsPtrHashKey<void>, FilterNode> mFilterNodes;
|
|
|
|
nsRefPtrHashtable<nsPtrHashKey<void>, GradientStops> mGradientStops;
|
|
|
|
nsRefPtrHashtable<nsPtrHashKey<void>, ScaledFont> mScaledFonts;
|
2016-01-05 10:08:58 +00:00
|
|
|
nsRefPtrHashtable<nsUint64HashKey, NativeFontResource> mNativeFontResources;
|
2016-01-05 10:08:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace layout
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_layout_PrintTranslator_h
|