Hi,

Attached is a draft patch to do:

1) extend poppler's FontInfo object to hold writing mode info.

2) extend poppler-qt4's FontInfo object to provide an API to
   return writing mode info copied from poppler's FontInfo.

3) extend qt4/tests/poppler-fonts to show writing mode info.

Also I attached a sample PDF including vertical/horizontal
Japanese text, generated by MS Word + Adobe Acrobat.
poppler-fonts detects the writing mode aslike:

$ ./qt4/tests/poppler-fonts vert-horiz-ipa-std.pdf 
name                                 type         emb sub font file wmode
------------------------------------ ------------ --- --- --------- -----
LDGIFP+IPAMincho                     CID TrueType      yes yes  Vert
LDGIFP+IPAMincho                     CID TrueType      yes yes  Hori

I think the diff for poppler-fonts.cpp shows how to use the
extended API. Cobra, please check if the extended API can help
your application.

The extention for poppler-glib is work in progress.

Regards,
mpsuzuki

On Mon, 26 Jul 2010 16:31:04 +0800 (CST)
"cobra.yu" <[email protected]> wrote:

>Hi,
>
>Hmm, it seems that... 
>1) I'm only familiar with the poppler-qt4 binding for the present time. But, 
>for my application, I really needs some CJK-related information through 
>poppler.
>2) I can't exactly figure out all the necessary steps to accomplish what you 
>said. But, I think, I could try, of course, by your help.
>3) So, let's work it out. :-)
>
>       Cobra
>-----Original message-----
>From:[email protected]
>To:[email protected]
>Cc:[email protected]
>Date:Mon, 26 Jul 2010 17:07:30 +0900
>Subject:Re: [poppler] Vertical or horizontal writing?
>
>Hi,
>
>Hmm, it seems that...
>
>1) poppler-qt4 can access FontInfo object for a font used in PDF,
>but cannot access GfxFont object that poppler creates before FontInfo
>object internally.
>
>2) either poppler-glib can access FontInfo object for a font used
>in PDF, but cannot access GfxFont object that poppler creates before
>FontInfo object internally.
>
>3) according to FontInfo.h (and FontInfo.cc), FontInfo object does
>not have a method to obtain the writing mode of its source GfxFont
>object.
>
>Thus, glib binding does not help your work. If we are forced to use
>current poppler without modification, we will have to use both of
>poppler-qt4 and raw poppler library. I'm afraid it makes your software
>difficult to maintain. If we have sufficient time, I think, making
>a proposal patch to add writing mode info to FontInfo object, and
>extend poppler-{qt4,glib} to access the info is better.
>
>I think adding writing mode to FontInfo is not difficult (I can
>draft), but making poppler-qt4 to access it is not so easy for
>me because I have no experience in Qt4 development. If you have
>sufficient time, I will ask you to draft the patch for poppler-qt4.
>How do you think of?
>
>Regards,
>mpsuzuki
>
>On Mon, 26 Jul 2010 15:46:43 +0800 (CST)
>"cobra.yu" <[email protected]> wrote:
>
>>Hi,
>>
>>   Thanks a lot! I think it would be a great help to me. I'm only using 
>> poppler-qt4 binding for my application now. So, I guess, I would have to use 
>> both Qt4 and cpp/glib bindings in my application, right?
>>
>>         Cobra
>>-----Original message-----
>>From:[email protected]
>>To:[email protected]
>>Cc:[email protected]
>>Date:Mon, 26 Jul 2010 16:24:40 +0900
>>Subject:Re: [poppler] Vertical or horizontal writing?
>>
>>Hi,
>>
>>Yet I'm not sure how you use poppler in your application,
>>but GfxFont class has a method to obtain "writing mode"
>>in PDF terminology. Please see GfxFont.h, you can find:
>>
>>   /* this is default */
>>
>>   106  class GfxFont {
>>   107  public:
>>   108  
>>...
>>   206    // Return the writing mode (0=horizontal, 1=vertical).
>>   207    virtual int getWMode() { return 0; }
>>
>>   /* this is for CID-keyed font */
>>   321  class GfxCIDFont: public GfxFont {
>>   322  public:
>>...
>>   333    // Return the writing mode (0=horizontal, 1=vertical).
>>   334    virtual int getWMode();
>>
>>And, you can find how poppler identify the writing mode
>>in GfxFont.cc:
>>
>>  1763  int GfxCIDFont::getWMode() {
>>  1764    return cMap ? cMap->getWMode() : 0;
>>  1765  }
>>
>>Is this what you want?
>>
>>Regards,
>>mpsuzuki
>>
>>On Mon, 26 Jul 2010 14:49:38 +0800 (CST)
>>"cobra.yu" <[email protected]> wrote:
>>
>>>Hi,
>>>
>>>     Is there any way by poppler to acquire the correct writing mode for any 
>>> Document/Page/Paragraph? I'm writing some code for the vertical Chinese 
>>> writing mode text search, but finding that it seems no way to know the 
>>> exact mode by poppler.
>>>     Any suggestions are welcome! Thx.
>>>
>>>         Cobra
>>>_______________________________________________
>>>poppler mailing list
>>>[email protected]
>>>http://lists.freedesktop.org/mailman/listinfo/poppler
diff --git a/poppler/FontInfo.cc b/poppler/FontInfo.cc
index 0037e07..b4bfab6 100644
--- a/poppler/FontInfo.cc
+++ b/poppler/FontInfo.cc
@@ -243,6 +243,9 @@ FontInfo::FontInfo(GfxFont *font, PDFDoc *doc) {
     }
     subset = i > 0 && i < name->getLength() && name->getChar(i) == '+';
   }
+
+  // get writing mode info (0=horizontal, 1=vertical)
+  wMode = font->getWMode();
 }
 
 FontInfo::FontInfo(FontInfo& f) {
@@ -254,6 +257,7 @@ FontInfo::FontInfo(FontInfo& f) {
   hasToUnicode = f.hasToUnicode;
   fontRef = f.fontRef;
   embRef = f.embRef;
+  wMode = f.wMode;
 }
 
 FontInfo::~FontInfo() {
diff --git a/poppler/FontInfo.h b/poppler/FontInfo.h
index 79eafea..f44dc39 100644
--- a/poppler/FontInfo.h
+++ b/poppler/FontInfo.h
@@ -58,6 +58,7 @@ public:
   GBool      getToUnicode() { return hasToUnicode; };
   Ref        getRef()       { return fontRef; };
   Ref        getEmbRef()    { return embRef; };
+  int        getWMode()     { return wMode; };
 
 private:
   GooString *name;
@@ -68,6 +69,7 @@ private:
   GBool hasToUnicode;
   Ref fontRef;
   Ref embRef;
+  int wMode;
 };
 
 class FontInfoScanner {
diff --git a/qt4/src/poppler-fontinfo.cc b/qt4/src/poppler-fontinfo.cc
index 81aed71..401fea9 100644
--- a/qt4/src/poppler-fontinfo.cc
+++ b/qt4/src/poppler-fontinfo.cc
@@ -65,6 +65,11 @@ bool FontInfo::isSubset() const
 	return m_data->isSubset;
 }
 
+int FontInfo::wMode() const
+{
+	return m_data->wMode;
+}
+
 FontInfo::Type FontInfo::type() const
 {
 	return m_data->type;
diff --git a/qt4/src/poppler-private.h b/qt4/src/poppler-private.h
index f148dbc..5840ff8 100644
--- a/qt4/src/poppler-private.h
+++ b/qt4/src/poppler-private.h
@@ -215,6 +215,7 @@ namespace Poppler {
 			isEmbedded = false;
 			isSubset = false;
 			type = FontInfo::unknown;
+			wMode = 0;
 		}
 		
 		FontInfoData( const FontInfoData &fid )
@@ -225,6 +226,7 @@ namespace Poppler {
 			isSubset = fid.isSubset;
 			type = fid.type;
 			embRef = fid.embRef;
+			wMode = fid.wMode;
 		}
 		
 		FontInfoData( ::FontInfo* fi )
@@ -235,6 +237,7 @@ namespace Poppler {
 			isSubset = fi->getSubset();
 			type = (Poppler::FontInfo::Type)fi->getType();
 			embRef = fi->getEmbRef();
+			wMode = fi->getWMode();
 		}
 
 		QString fontName;
@@ -243,6 +246,7 @@ namespace Poppler {
 		bool isSubset : 1;
 		FontInfo::Type type;
 		Ref embRef;
+		int wMode;
     };
 
     class FontIteratorData
diff --git a/qt4/src/poppler-qt4.h b/qt4/src/poppler-qt4.h
index 117dc43..111e65d 100644
--- a/qt4/src/poppler-qt4.h
+++ b/qt4/src/poppler-qt4.h
@@ -191,6 +191,15 @@ namespace Poppler {
 	bool isSubset() const;
 
 	/**
+	   Return the WMode value in the font object.
+
+	   \return 0 if the font is horizontal mode,
+	   \return 1 if the font is vertical mode,
+	   \return other values when source GfxFont refers broken CMap.
+	*/
+	int wMode() const;
+
+	/**
 	   The type of font encoding
 
 	   \return a enumerated value corresponding to the font encoding used
diff --git a/qt4/tests/poppler-fonts.cpp b/qt4/tests/poppler-fonts.cpp
index 6b66ec4..5cb036b 100644
--- a/qt4/tests/poppler-fonts.cpp
+++ b/qt4/tests/poppler-fonts.cpp
@@ -22,9 +22,9 @@ int main( int argc, char **argv )
 	exit(1);
     }
 
-    std::cout << "name                                 type         emb sub font file";
+    std::cout << "name                                 type         emb sub font file wmode";
     std::cout << std::endl;
-    std::cout << "------------------------------------ ------------ --- --- ---------";
+    std::cout << "------------------------------------ ------------ --- --- --------- -----";
     std::cout << std::endl;
   
     foreach( const Poppler::FontInfo &font, doc->fonts() ) {
@@ -83,6 +83,11 @@ int main( int argc, char **argv )
 	    std::cout << "no  ";
 	}
 	std::cout << qPrintable( QString("%1").arg(font.file()) );
+	switch ( font.wMode() ) {
+	case 0:  std::cout << " Hori"; break;
+	case 1:  std::cout << " Vert"; break;
+	default: std::cout << " ????";
+	}
 	std::cout << std::endl;
     }
     delete doc;

Attachment: vert-horiz-ipa-std.pdf
Description: Adobe PDF document

_______________________________________________
poppler mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/poppler

Reply via email to