Bug 1185236 - Add adjustPrintJobName in order to avoid IPP job name limit. r=karlt
☠☠ backed out by 7ec4ec57761e ☠ ☠
authorMantaroh Yoshinaga <mantaroh@gmail.com>
Fri, 13 Oct 2017 08:55:08 +0900
changeset 385978 445f1e6fc862f32dc126085c01452dd0e3a03fb6
parent 385977 f290517125dc8b2e64ebd0dc0a76fe60bd33c966
child 385979 0466471b9f67aa6a60bf3fb98515532e8a53095d
push id32672
push userarchaeopteryx@coole-files.de
push dateFri, 13 Oct 2017 09:00:05 +0000
treeherdermozilla-central@3efcb26e5f37 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskarlt
bugs1185236
milestone58.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1185236 - Add adjustPrintJobName in order to avoid IPP job name limit. r=karlt MozReview-Commit-ID: n2k9lwfoyW
gfx/thebes/PrintTarget.cpp
gfx/thebes/PrintTarget.h
--- a/gfx/thebes/PrintTarget.cpp
+++ b/gfx/thebes/PrintTarget.cpp
@@ -10,16 +10,21 @@
 #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 "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 +160,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();