Bug 1185236 - Add adjustPrintJobName in order to avoid IPP job name limit. r?karlt
MozReview-Commit-ID: n2k9lwfoyW
--- a/gfx/thebes/PrintTarget.cpp
+++ b/gfx/thebes/PrintTarget.cpp
@@ -10,16 +10,23 @@
#include "cairo-quartz.h"
#endif
#ifdef CAIRO_HAS_WIN32_SURFACE
#include "cairo-win32.h"
#endif
#include "mozilla/gfx/2D.h"
#include "mozilla/gfx/HelpersCairo.h"
#include "mozilla/gfx/Logging.h"
+#include "nsReadableUtils.h"
+#include "nsString.h"
+#include "nsUTF8Utils.h"
+
+// IPP spec disallow the job-name which is over 255 characters.
+// RFC: https://tools.ietf.org/html/rfc2911#section-4.1.2
+#define IPP_JOB_NAME_LIMIT_LENGTH 255
namespace mozilla {
namespace gfx {
PrintTarget::PrintTarget(cairo_surface_t* aCairoSurface, const IntSize& aSize)
: mCairoSurface(aCairoSurface)
, mSize(aSize)
, mIsFinished(false)
@@ -155,16 +162,32 @@ PrintTarget::GetReferenceDrawTarget(Draw
#endif
return do_AddRef(mRecordingRefDT);
}
return do_AddRef(mRefDT);
}
+/* static */
+void
+PrintTarget::AdjustPrintJobNameForIPP(const nsAString& aJobName,
+ nsCString& aAdjustedJobName)
+{
+ CopyUTF16toUTF8(aJobName, aAdjustedJobName);
+
+ if (aAdjustedJobName.Length() > IPP_JOB_NAME_LIMIT_LENGTH) {
+ uint32_t length =
+ RewindToPriorUTF8Codepoint(aAdjustedJobName.get(),
+ (IPP_JOB_NAME_LIMIT_LENGTH - 3U));
+ aAdjustedJobName.SetLength(length);
+ aAdjustedJobName.AppendLiteral("...");
+ }
+}
+
/* static */ already_AddRefed<DrawTarget>
PrintTarget::CreateWrapAndRecordDrawTarget(DrawEventRecorder* aRecorder,
DrawTarget* aDrawTarget)
{
MOZ_ASSERT(aRecorder);
MOZ_ASSERT(aDrawTarget);
RefPtr<DrawTarget> dt;
--- a/gfx/thebes/PrintTarget.h
+++ b/gfx/thebes/PrintTarget.h
@@ -131,16 +131,19 @@ public:
/**
* Returns a reference DrawTarget. Unlike MakeDrawTarget, this method is not
* restricted to being called between BeginPage()/EndPage() calls, and the
* returned DrawTarget it is still valid to use after EndPage() has been
* called.
*/
virtual already_AddRefed<DrawTarget> GetReferenceDrawTarget(DrawEventRecorder* aRecorder);
+ static void AdjustPrintJobNameForIPP(const nsAString& aJobName,
+ nsCString& aAdjustedJobName);
+
protected:
// Only created via subclass's constructors
explicit PrintTarget(cairo_surface_t* aCairoSurface, const IntSize& aSize);
// Protected because we're refcounted
virtual ~PrintTarget();