PSOutputDev: Fix wrong text generation

This patch moves the code to update the max valid glyph hash into its
own function and updates the max valid glyph only if the new value is
higher than the previous value.
This fixes a problem with pages that have multiple copies of the same
font with different glyph counts. If poppler processed the font with the
smaller count last, and then the PDF wrote text in the font with the
larger count, pdftops would not show the glyphs above the maximum of the
smaller font.

Bug #102760
diff --git a/poppler/PSOutputDev.cc b/poppler/PSOutputDev.cc
index b2d6d3a..17f31b3 100644
--- a/poppler/PSOutputDev.cc
+++ b/poppler/PSOutputDev.cc
@@ -2544,6 +2544,14 @@
   writePS("%%EndResource\n");
 }
 
+void PSOutputDev::updateFontMaxValidGlyph(GfxFont *font, int maxValidGlyph) {
+  if (maxValidGlyph >= 0 && font->getName()) {
+    if (maxValidGlyph > fontMaxValidGlyph->lookupInt(font->getName())) {
+      fontMaxValidGlyph->replace(font->getName()->copy(), maxValidGlyph);
+    }
+  }
+}
+
 void PSOutputDev::setupExternalCIDTrueTypeFont(GfxFont *font,
 					       GooString *fileName,
 					       GooString *psName,
@@ -2594,9 +2602,7 @@
 		needVerticalMetrics,
 		&maxValidGlyph,
 		outputFunc, outputStream);
-	if (maxValidGlyph >= 0 && font->getName()) {
-	  fontMaxValidGlyph->replace(font->getName()->copy(), maxValidGlyph);
-	}
+	updateFontMaxValidGlyph(font, maxValidGlyph);
       }
       gfree(codeToGID);
     } else {
@@ -2696,9 +2702,7 @@
 			     needVerticalMetrics,
 			     &maxValidGlyph,
 			     outputFunc, outputStream);
-	if (maxValidGlyph > 0 && font->getName()) {
-	  fontMaxValidGlyph->replace(font->getName()->copy(), maxValidGlyph);
-	}
+	updateFontMaxValidGlyph(font, maxValidGlyph);
       }
       delete ffTT;
     }
diff --git a/poppler/PSOutputDev.h b/poppler/PSOutputDev.h
index 833f686..2d92b81 100644
--- a/poppler/PSOutputDev.h
+++ b/poppler/PSOutputDev.h
@@ -355,6 +355,7 @@
   void setupFonts(Dict *resDict);
   void setupFont(GfxFont *font, Dict *parentResDict);
   void setupEmbeddedType1Font(Ref *id, GooString *psName);
+  void updateFontMaxValidGlyph(GfxFont *font, int maxValidGlyph);
   void setupExternalType1Font(GooString *fileName, GooString *psName);
   void setupEmbeddedType1CFont(GfxFont *font, Ref *id, GooString *psName);
   void setupEmbeddedOpenTypeT1CFont(GfxFont *font, Ref *id, GooString *psName);