ã¬ããŒãã¯è€æ°ã®ã¹ããããããªãããã»ã¹ã§ãã ã¬ããŒãããŒã«ã¯ãã¬ããŒãã®äœæãããŒã¿ããŒã¹ã®æäœããã£ã«ã¿ãŒæ¡ä»¶ã®ç®¡çãšå€ã®èšç®ãæââçµããã¥ã¡ã³ããžã®åºåã®ããŸããŸãªæ®µéãèªååã§ããŸãã åŸè ã«ã€ããŠèª¬æããŸãã
ã¯ããã«
çŸæç¹ã§ã¯ããgolang odfããšããæ€çŽ¢ã¯ãšãªã®çµæã«ã¯ãå€ãã®èŠæããããŸãã ãã¡ããããgolang pdfãã®ãªã¯ãšã¹ãã§ã¯ããã¹ãŠãã¯ããã«ãã©è²ã§ãã ãããããªãã£ã¹ããã¥ã¡ã³ãã®åœ¢åŒã§ç¹å®ã®ã¬ããŒããçæããããžãã¹ã¢ããªã±ãŒã·ã§ã³ã®éçºã«ãããç§èªèº«ã®çµéšã«åºã¥ããŠãçŸããPDFããŠãŒã¶ãŒã®ã³ã³ãã¥ãŒã¿ãŒã«å±ããšãå€ãã®å Žåãæ°åããã§ãã¯ããäžäžèŽã確èªããŠãåŒã³åºããŸãã¬ããŒãã¯ããã§ã«æšæ¥ãå¿ èŠã§ãããããåä¿¡ãããã¡ã€ã«ã®å³ãä¿®æ£ããèŠæ±ã§ãµããŒãããŸãã
解決çã¯ãWord / RTF / ODF / etc圢åŒã®ããã¥ã¡ã³ããçæããããPDFãç·šéããããšã§ãïŒãã®ããã®æ¢è£œã®ããŒã«ããããŸãã®ã§ãããã¯ããã°ã©ãã§ã¯ãªã管çè ã«ãšã£ãŠããèå³æ·±ãã§ãïŒã ãŸããç¬èªã®åœ¢åŒã§ã³ã¡ã³ãã«ã³ã¡ã³ãããæ©äŒãæ®ããŸãããããã§ã¯ODFçæã«ã€ããŠèª¬æããŸãã
ODFãã©ãŒããã
ãªãŒãã³ããã¥ã¡ã³ã圢åŒã¯ãç·šéå¯èœãªãªãã£ã¹ããã¥ã¡ã³ãçšã®ãªãŒãã³åœ¢åŒã§ãã ããããµããŒãããæåãªãªãã£ã¹ã¹ã€ãŒãã®ãã¡ãOpenOfficeãšLibreOfficeã¯åºå¥ã§ããŸãã çŸåšãããŒãžã§ã³1.2ã®åœ¢åŒã®æšæºã¯æå¹ã§ãããããŒãžã§ã³1.0ãšã®éãã¯ã»ãšãã©ãªãããããã¯äž»ã«çµç¹çãªé åºã§ãã ãã®èŠæ Œã¯ãã§ã«æ°å¹Žåã®ãã®ã§ãããããå®å®ããŠãããšèŠãªãããšãã§ãããã®äœæ¥ã«äŸåããããšãã§ããŸãã ãã®åœ¢åŒã¯ãããŸããŸãªçš®é¡ã®ææžãããã¹ãææžãã¹ãã¬ããã·ãŒãããã¬ãŒã³ããŒã·ã§ã³ãªã©ãæäŸããŸãã ã¬ããŒããä¿åããããã®åªå 圢åŒã¯ãç§ã®çµéšã§ã¯ãããã¹ãïŒodtïŒããã³è¡šïŒodsïŒããã¥ã¡ã³ãã§ãã
ãã®èŠæ Œã§ã¯ãããã¥ã¡ã³ãã¢ãã«ãæ§é åãããã®ã¢ãã«ãXML圢åŒã§ä¿åããããã®ã«ãŒã«ã«ã€ããŠèª¬æããŠããŸãã æè¡çã«ã¯ãããã¥ã¡ã³ããã¡ã€ã«ã¯1ã€ã®å€§ããªXMLããããã€ãã®å¿ èŠãªãã¡ã€ã«ãšç¡å¶éã®æ°ã®ãã®ä»ã®ãã¡ã€ã«ãå«ãzipã¢ãŒã«ã€ãã®ããããã§ãªããã°ãªããŸããã ãã®åœ¢åŒã¯ç»åããã®ä»ã®ãã¡ã€ã«ãåã蟌ãã®ã«äŸ¿å©ãªã®ã§ãzipã¢ãŒã«ã€ã圢åŒã®ããã¥ã¡ã³ãã®ã¿ãæ€èšããŸãã
ãŸããODFããã·ã¢é£éŠã®åœå®¶æšæºã§ããããšã«æ³šæããããšãäžå¿ èŠã§ã¯ãããŸããã ãŸããMicrosoft Officeã¯çµç¹å ã§ç¢ºåºããå°äœã«ãããŸãããOpen Officeã¯å€ãã®å Žåè¿ãã«é 眮ããã代æ¿ã®é£è¡å ŽãšããŠæ©èœããŸãã
ãªãè¡ãã®ïŒ
ã©ãããŠïŒ ã·ã³ãã«ãªèšèªãGoogleãµããŒãã掻æ°ããã³ãã¥ããã£ã空ããŠãããããã ãããŠãããã¯ãã 楜ããã§ãã ãŸããä¿¡é Œæ§ã®é«ãã³ãŒããjavascriptã§ã³ã³ãã€ã«ã§ãããããå Žåã«ãã£ãŠã¯ãã¬ããŒããçæããã¡ã«ããºã ãã¯ã©ã€ã¢ã³ãã«äžè¬çã«è»¢éã§ãããããWebãµãŒãã¹ã®æè»æ§ãåäžããŸãã ããã«ãè€éãªãã«ãã¬ãã«ã¬ããŒããªã©ã®é£ããããšã«é«éã®ãã€ãã£ãã³ãŒãã䜿çšããªãããšã¯çœªã§ãã
å³æžé€š
ODFã¬ããŒããšãã©ãŒã ãžã§ãã¬ãŒã¿ãŒãå®è£ ããå¿ èŠããã£ã2008幎以æ¥ãç§ã¯ããªãé·ãéODFãã©ãŒãããã䜿çšããŠããŸãã 次ã«ãããã°ã©ã ã®ããã¥ã¡ã³ãã䟿å©ã«ïŒèŠããšããïŒçæããããã«ãå¥ã®èšèªã§ã³ã³ããŒãã³ããå®è£ ããŸããã äžè¬ã«ãçµæã¯æºè¶³ã®ãããã®ã§ãç§ã®ã³ã³ããŒãã³ãã¯ãŸã æ©èœããŠããŸãã
æ°å¹Žã®äœ¿çšåŸãéåžžã¯å€ãã®ã³ã¡ã³ããèç©ãããŸããããããæ ¹æ¬çã«ä¿®æ£ããã©ã€ãã©ãªå šäœããŒãããæžãçŽãããšã«ããŸããã ä»ã¯æéãèå³æ·±ãã®ã§ãåµé çãªããã¿ã®å®è£ ã«Goãšã³ã·ã¹ãã ãéžæããŸããã ããããäžè¬çã«ã¯ã以åã®ããŒãžã§ã³ã®ã€ã³ã¿ãŒãã§ã€ã¹ãœãªã¥ãŒã·ã§ã³ãå®çžŸã®ãããã®ãšããŠç¶æããããšããŸããã
次ã«ã圢åŒã«ã€ããŠããå ·äœçãªããšã説æããŸãã ããã«æ £ããããã«ãODFæšæºã®æŠèŠãèªãããšãã§ããŸãã
ããã°ã©ããŒã®èŠ³ç¹ããODFãæäœããéã®äž»ãªå°é£ã¯äœã§ããïŒ ããã¯ãããã¥ã¡ã³ãã®å¯èŠã³ã³ãã³ãã®å€æŽãæé»çã«ããã¥ã¡ã³ãã¢ãã«ã®ããã€ãã®é åã®å€æŽã«ã€ãªãããšããäºå®ã«ãããŸãã å€æŽã¯ãã³ã³ãã³ãé åãã¹ã¿ã€ã«ã®èª¬æé åãzipããã±ãŒãžã®ã³ã³ãã³ãã«åœ±é¿ããŸãã åæã«ãXMLã®ç¹æ§ã«ãããç®ã«èŠããªãæåãšæŠãããã®ããã€ãã®æ段ãODF圢åŒã«å°å ¥ãããçæããŒã«ã«è¿œå ã®è²¬ä»»ã課ããããŸããã
ãã1ã€ã®éèŠãªãã€ã³ãã¯ãã¹ã¿ã€ã«ã®åå©çšã§ãã ã³ã³ããŒãã³ãã¯ããŠãŒã¶ãŒãäœæããã¹ã¿ã€ã«ã«åŸã£ãŠãéè€ããããšãªãæé©ã«ä¿åããå¿ èŠããããŸããã
å®è£
ãã®ã¡ã«ããºã ããã¹ãŠå®è£ ããããã«ãFormatterã®æŠå¿µãèæ¡ïŒã¹ãã€ïŒãããŸããã ãã©ãŒããã¿ã¯ãããã¥ã¡ã³ãã¢ãã«ãããã¥ã¡ã³ãã¢ãã«èªäœãããã³ã¯ã©ã€ã¢ã³ãã³ãŒãããé ãããŠããããã¯ã©ã€ã¢ã³ãã³ãŒãã®ã¢ã¯ã·ã§ã³ãäœããã®æ¹æ³ã§å¶åŸ¡ããã³æ€èšŒã§ããäžé£ã®è£å©ããŒã¿æ§é ã«é¢ããæ å ±ãå«ãéåäœã§ãã
ããã¥ã¡ã³ãã¢ãã«ã®å Žåã以åã®ããŒãžã§ã³ã§ã¯åé·ãªçŽç²ãªDOMã䜿çšãããŠãããããæ°ããããŒãžã§ã³ã§ã¯DOMãªã©ã®åçŽåãããããŒã¿æ§é ã䜿çšãããGoæšæºã©ã€ãã©ãªããã®åæåããŒã·ã£ãªã³ã°ã«ãã£ãŠXMLã«å€æãããŸãã ããã¥ã¡ã³ãã¢ãã«ãæäœããã«ã¯ãCarrier-Rider-MapperïŒCRMïŒãã¿ãŒã³ã䜿çšãããŸãã ãã£ãªã¢ã¯èšæ¶åªäœã§ããããã®å Žåã¯ããŒãããªãŒã§ãã ã©ã€ããŒã¯ãããªãŒãšãã®å€æŽãå®è¡ããããã«äœ¿çšãããŸã-ã©ã³ããŒãæšè£œããŒã¿æ§é ã§ã¯ãã¹ã©ã€ããŒãããŒãã®äœçœ®ãååŸããåå«ã®ãªã¹ããšãã®ããŒãã®å±æ§ãå®è¡ããããšãç¹åŸŽã§ãã ãã®ã¹ããŒã ã®ããããŒã¯ãã¹ã©ã€ããŒã®å©ããåããŠãããã¥ã¡ã³ãã¢ãã«ã§åäœããé«ã¬ãã«ã®ã¡ã«ããºã ã§ãããæ³åã®ãšããããã®ã¹ããŒã ã§ã¯ãã©ãŒããã¿ãŒã§ãã
ããã¥ã¡ã³ãèªäœã®ã³ã³ãã³ãã¯ãç®çã®ããŒã ã¹ããŒã¹ããã®ç¹å¥ãªååãæã€ããŒãã®åœ¢åŒã§èšè¿°ãããŸãã ããŒãå±æ§ãç¹å¥ãªåå空éã«å±ããŸãã ããã¹ããšãã£ã¿ãéããšãçŸããããã¹ããã¿ãã¬ããã§ãããããŒããšå±æ§ã®ã»ããã解éãããŸãã ãããã£ãŠããã©ãŒããã¿ã®äž»ãªã¿ã¹ã¯ã¯ãããŒããšãã®å±æ§ãèšé²ããé©åãªå Žæã«æ£ããèšé²ããããšã§ãããã®ååãšæå³ã¯æšæºã§èª¬æãããŠããŸãã äŸïŒ
<textïŒp>èŠçŽ ã¯æ®µèœãè¡šããŸããããã¯ãOpenDocumentãã¡ã€ã«å ã®ããã¹ãã®åºæ¬åäœã§ãã段èœèŠçŽ ãèšè¿°ããŸãããã®å 容ã¯ã段èœã¹ã¿ã€ã«ãé©çšããã段èœãšããŠè¡šç€ºãããŸãïŒããŒãžäžã®é 眮ãè¡ééãªã©ã
çŸæç¹ã§ã¯ãæ¢è£œã®ããã¥ã¡ã³ããèªãã§å€æŽããã¿ã¹ã¯ãèªåã§èšå®ããŠããŸããã§ãããããã®ããŒã¿ã¢ãã«ã¯ãããå¯èœã«ããŸããããã¯å®è£ ã®åé¡ã§ãã
æ¡åŒµæ§ãé«ããããã«ãåœåã¢ããªã·ãã¯ãªãã©ãŒããã¿ã¯ããã€ãã®çããã®ã«åå²ãããããã¥ã¡ã³ãã®ç¹å®ã®ã»ã¯ã·ã§ã³ïŒããªãŒããŒãïŒãèšé²ããæ©èœãå®è¡ããŸããã ParaMapperã¯æ®µèœã®å 容ãèšé²ããTableMapperã¯ããŒãã«ãšãã®å 容ãèšé²ããParaMapperã¯ããã¹ããã»ã«ã«èšé²ããŸãã ãã®ã¢ãããŒãã«ãããèšå€§ãªæšæºã®å¿ èŠãªæ©èœããã€ã³ãã®åªåã§å®è£ ã§ããæéãšãããžã§ã¯ããªãœãŒã¹ãç¯çŽã§ããŸãã
ããã¹ãå±æ§ãæåããã¹ããããŒãžäžã®æ®µèœã®é 眮ãããã³ãã®ä»ã®å¿ èŠãªå±æ§ã¯ãäžè¬åãããå±æ§çæã¡ã«ããºã ã䜿çšããŠèšå®ãããŸãã
ãã®å±æ§ãŸãã¯ãã®å±æ§ãã¡ããªã«ã¯ãç®çã®ã¹ã¿ã€ã«ãèšå®ã§ããç¹å¥ãªãã«ããŒãå®è£ ãããŠããŸãã
ãã®äœæ¥ã®éèŠãªç¹åŸŽã¯ãå±æ§ãèšå®ããŠããå®éã«ææžã«æžã蟌ãŸããããšãæå³ããªãããšã§ãã å®éã«ã¯ãããã¯æ¬¡ã®ãããªäœæ¥ã¹ããŒã ã«ã€ãªãããŸãã
- èšé²çšã«æºåãããããŒã¿
- å°æ¥ã®ã³ã³ãã³ãå±æ§ãèšå®ãã
- èšå®ãããå±æ§ãåãåãèšé²ãããã³ã³ãã³ã
- ããã¥ã¡ã³ãã«æžã蟌ãŸããå±æ§
æ°ããå±æ§ãèšè¿°ããããªã»ãããããŸã§ãé£ç¶ããåã³ã³ãã³ãã¯ãããã®å±æ§ã«é¢é£ä»ããããŸãã ç¹å¥ãªãŠãŒã¶ãŒå±æ§ãå²ãåœãŠãããŠããªãã³ã³ãã³ãã«èµ·å ãããããã¥ã¡ã³ãã®ããã©ã«ãå±æ§ãèšå®ããè¿œå ã®æ©äŒã
ODFæšæºã¯éåžžã«èšå€§ã§ãããããç§ã®äœæ¥ã§ã¯ãã¬ããŒãã®çæã«å¿ èŠãªæå°éã®æ©èœã®ã¿ãå®è£ ããŸããã ãããã®æ©èœã«ã¯ãããã¹ãå±æ§ïŒè²ããã©ã³ãããµã€ãºïŒã段èœå±æ§ïŒé 眮ïŒãããŒãã«ããã³ã»ã«å±æ§ïŒå¢çç·å±æ§ãè²ãç·ã®å€ªãïŒãç»åã®åã蟌ã¿ããããŸãã
äž»ãªåªåã¯ãæ¡åŒµå¯èœãªãã¬ãŒã ã¯ãŒã¯ã®åœ¢æã«è²»ããããŸãããããã«ãããå¿ èŠãªå±æ§ãæ°ããèŠçŽ ããã©ã€ãã©ãªã³ãŒããå€æŽããªããŠãå®è£ ã§ããŸãïŒæ°ããã³ãŒããèšè¿°ããå¿ èŠããããŸãïŒã èå³æ·±ãããšã«ãããã°ã©ããŒã®ã¹ãã¬ããã·ãŒã圢åŒã¯ãããã¹ãææžã®åœ¢åŒãšã»ãšãã©åãã«èŠããŸãã MIMEã¿ã€ãã®ã¿ãå€æŽãããããã¥ã¡ã³ãã®ã«ãŒãèŠçŽ ãããã¹ãã§ã¯ãªããšããäºå®ã®ã¿ãå€æŽãããŸãã ããŒãã«æžã蟌ã¿ãšã³ãžã³ã¯ãã©ã¡ãã®å Žåã§ãåãããã«æ©èœããŸãã ããã¯ã odf_test.goã¢ãžã¥ãŒã«ã®äŸã§ç¢ºèªã§ããŸãã
äŸ
å¥åº·ç¶æ ãšãã®äœ¿çšæ¹æ³ã瀺ãç°¡åãªäŸã
package main import ( "odf/generators" "odf/mappers" "odf/model" _ "odf/model/stub" // "odf/xmlns" "os" ) func main() { if output, err := os.Create("demo2.odf"); err == nil { // defer output.Close() // m := model.ModelFactory() // fm := &mappers.Formatter{} // fm.ConnectTo(m) // , fm.MimeType = xmlns.MimeText // fm.Init() // fm.WriteString("Hello, Habrahabr!") // generators.GeneratePackage(m, nil, output, fm.MimeType) } }
ããè€éãªäŸã¯ããããžã§ã¯ããªããžããªã®odf_test.goãã¡ã€ã«ãdemo / report.goã«ãããŸãã
æ¬æ ŒçãªäŸã§ã¯ã ãã¢ã¬ããŒããçæãããŸããã
Yandex-diskããã¡ã€ã«ã®æäŸãåæ¢ããå Žå
ãããã«
æåŸã«ãODFããã¥ã¡ã³ãã®åœ¢æèªäœã¯è€éãªãã®ã§ã¯ãªãããšã«æ³šæããŠãã ããã ã©ã€ãã©ãªã®æåã®ããŒãžã§ã³ãš2çªç®ã®ããŒãžã§ã³ã®äž»ãªç®æšã¯ãã¬ããŒããšãã©ãŒã ãçæããã¿ã¹ã¯ã§ããã«äœ¿çšã§ãã䟿å©ãªããã°ã©ã ã€ã³ã¿ãŒãã§ã€ã¹ãæäŸããããšã§ããã ãŸãããã®ãããªã€ã³ã¿ãŒãã§ã€ã¹ã®åºæ¬ã¬ãã«ã¯ãWebã¢ããªã±ãŒã·ã§ã³ã®ã¬ããŒããçæãããããšãå€ãåçŽãªHTMLãªã©ãä»ã®åœ¢åŒããã³ã³ããŒã¿ãŒãæ§ç¯ããå¯èœæ§ãéããŸãã
ãã®ã¢ãããŒãã®æ¬ ç¹ã®1ã€ã¯ãã¯ã©ã€ã¢ã³ãã³ãŒãçšã®äŸ¿å©ãªã€ã³ã¿ãŒãã§ã€ã¹ãèæ¡ããããã«ãæšæºãã³ãŒãã«å€æããããã®èšå€§ãªæåäœæ¥ãå¿ èŠãªããšã§ãã ç§ã¯ãODFæšæºå šäœã®RelaxNGåŠçã¹ããŒã ã䜿çšããŠãã®äœæ¥ã®èªååãèŠãããšã¯çã«ããªã£ãŠãããšå®å šã«èªããŠããŸããããã¯ãèªååã«äŸ¿å©ãªåœ¢åŒã§åœ¢åŒã®æ©èœãšå¶éãèšè¿°ããŸãã
Goã§æžããŠã¬ããŒããå¿ èŠãªå Žåã¯ãããã«ãããŸãã ãªãŒãã³ãœãŒã¹ãšããŒã éçºã®ç²Ÿç¥ã¯ãã©ã€ãã©ãªãåºå€§ãªãããã«ããããšãã§ããŸãã ãŸããODFãããããã¢ãŒãã§PDFãååŸã§ãããããæ°åãç·šéãããã¬ããŒããããã¯ãããããæ©èœãå€§å¹ ã«åŒ·åã§ããŸãã
åç §è³æ
ODF圢åŒã®èª¬æïŒ docs.oasis-open.org/office/v1.2/OpenDocument-v1.2.html
ãããžã§ã¯ããªããžããªïŒ github.com/kpmy/odf
ãã¢ïŒ yadi.sk/i/RghkBDHIgcey2