Reduce 1D barcode DrawPath calls.

Draw vertical 1D barcodes as segments of lines, instead of as individual
pixels.

Change-Id: Ic260118660994514ce9023aacf13b16adfc8d362
Reviewed-on: https://pdfium-review.googlesource.com/4595
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
diff --git a/fxbarcode/oned/BC_OneDimWriter.cpp b/fxbarcode/oned/BC_OneDimWriter.cpp
index 14c5911..71f440f 100644
--- a/fxbarcode/oned/BC_OneDimWriter.cpp
+++ b/fxbarcode/oned/BC_OneDimWriter.cpp
@@ -268,21 +268,39 @@
 
   CFX_GraphStateData stateData;
   CFX_PathData path;
-  path.AppendRect(0, 0, (float)m_Width, (float)m_Height);
+  path.AppendRect(0, 0, static_cast<float>(m_Width),
+                  static_cast<float>(m_Height));
   device->DrawPath(&path, matrix, &stateData, m_backgroundColor,
                    m_backgroundColor, FXFILL_ALTERNATE);
-  CFX_Matrix matri(m_outputHScale, 0.0, 0.0, (float)m_Height, 0.0, 0.0);
+  CFX_Matrix matri(m_outputHScale, 0.0, 0.0, static_cast<float>(m_Height), 0.0,
+                   0.0);
   matri.Concat(*matrix);
   for (int32_t x = 0; x < m_output->GetWidth(); x++) {
+    int32_t yStart = 0;
+    bool drawing = false;
     for (int32_t y = 0; y < m_output->GetHeight(); y++) {
-      CFX_PathData rect;
-      rect.AppendRect((float)x, (float)y, (float)(x + 1), (float)(y + 1));
-      if (m_output->Get(x, y)) {
-        CFX_GraphStateData data;
-        device->DrawPath(&rect, &matri, &data, m_barColor, 0, FXFILL_WINDING);
+      bool draw = m_output->Get(x, y);
+      if (!drawing) {
+        if (draw) {
+          drawing = true;
+          yStart = y;
+        }
+        continue;
       }
+
+      if (draw && y != m_output->GetHeight() - 1)
+        continue;
+
+      drawing = false;
+      int32_t yEnd = draw ? y + 1 : y;
+      CFX_PathData rect;
+      rect.AppendRect(static_cast<float>(x), static_cast<float>(yStart),
+                      static_cast<float>((x + 1)), static_cast<float>(yEnd));
+      CFX_GraphStateData data;
+      device->DrawPath(&rect, &matri, &data, m_barColor, 0, FXFILL_WINDING);
     }
   }
+
   return m_locTextLoc == BC_TEXT_LOC_NONE || contents.Find(' ') == -1 ||
          ShowChars(contents, device, matrix, m_barWidth, m_multiple);
 }