Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

GD with JIS-mapped Japanese Font Support #4206

Closed
anonymous-piwik-user opened this Issue · 6 comments

3 participants

@anonymous-piwik-user

Description

If you compile PHP with option "--enable-gd-jis-conv" and "JIS-mapped Japanese font support" in GD is enabled, characters that are embedded in the graph image by the function imagettftext() are unintelligible sequence of characters.

Reproduce

URL to reproduce such bug:

  • create a scheduled reports, pick few reports, select SHOW graph in all reports, "show historical top 5"
  • in Japanese language
  • download; index.php?module=API&action=index&idSite=1&period=week&date=2013-11-05&updated=2&token_auth=XXXXXXX&method=PDFReports.generateReport&idReport=1&outputType=3&language=ja

Error:

Warning: imagettfbbox(): any2eucjp(): invalid code in input string in /var/www/html/piwik/libs/pChart2.1.3/class/pImage.class.php on line 211

Backtrace -->

#0 Piwik_ErrorHandler(...) called at [:]
#1 imagettfbbox(...) called at [/var/www/html/piwik/libs/pChart2.1.3/class/pImage.class.php:211]
#2 pImage->getTextBox(...) called at [/var/www/html/piwik/libs/pChart2.1.3/class/pDraw.class.php:988]
#3 pDraw->drawText(...) called at [/var/www/html/piwik/plugins/ImageGraph/StaticGraph.php:290]
#4 Piwik_ImageGraph_StaticGraph->getTextWidthHeight(...) called at [/var/www/html/piwik/plugins/ImageGraph/StaticGraph.php:305]
#5 Piwik_ImageGraph_StaticGraph->getMaximumTextWidthHeight(...) called at [/var/www/html/piwik/plugins/ImageGraph/StaticGraph/GridGraph.php:382]
#6 Piwik_ImageGraph_StaticGraph_GridGraph->getGridBottomMargin(...) called at [/var/www/html/piwik/plugins/ImageGraph/StaticGraph/GridGraph.php:401]
#7 Piwik_ImageGraph_StaticGraph_GridGraph->getGraphBottom(...) called at [/var/www/html/piwik/plugins/ImageGraph/StaticGraph/GridGraph.php:84]
#8 Piwik_ImageGraph_StaticGraph_GridGraph->initGridChart(...) called at [/var/www/html/piwik/plugins/ImageGraph/StaticGraph/Evolution.php:28]
#9 Piwik_ImageGraph_StaticGraph_Evolution->renderGraph(...) called at [/var/www/html/piwik/plugins/ImageGraph/API.php:477]
#10 Piwik_ImageGraph_API->get(...) called at [:]
#11 call_user_func_array(...) called at [/var/www/html/piwik/core/API/Proxy.php:188]
#12 Piwik_API_Proxy->call(...) called at [/var/www/html/piwik/core/API/Request.php:145]
#13 Piwik_API_Request->process(...) called at [/var/www/html/piwik/core/ReportRenderer.php:238]
#14 Piwik_ReportRenderer::getStaticGraph(...) called at [/var/www/html/piwik/core/ReportRenderer/Pdf.php:411]
#15 Piwik_ReportRenderer_Pdf->paintGraph(...) called at [/var/www/html/piwik/core/ReportRenderer/Pdf.php:301]
#16 Piwik_ReportRenderer_Pdf->renderReport(...) called at [:]
#17 array_walk(...) called at [/var/www/html/piwik/plugins/PDFReports/API.php:425]
#18 Piwik_PDFReports_API->generateReport(...) called at [:]
#19 call_user_func_array(...) called at [/var/www/html/piwik/core/API/Proxy.php:188]
#20 Piwik_API_Proxy->call(...) called at [/var/www/html/piwik/core/API/Request.php:145]
#21 Piwik_API_Request->process(...) called at [/var/www/html/piwik/plugins/API/Controller.php:25]
#22 Piwik_API_Controller->index(...) called at [:]
#23 call_user_func_array(...) called at [/var/www/html/piwik/core/FrontController.php:125]
#24 Piwik_FrontController->dispatch(...) called at [/var/www/html/piwik/index.php:47]

Proposed solution

Add the process of converting to SJIS from UTF-8 as follows.

 if ($gdinfo['JIS-mapped Japanese Font Support']) {
 $string = mb_convert_encoding($string, "SJIS", "UTF-8");
 }

Keywords: graph chart

@mattab
Owner

thanks for report!

have you tested this code in Piwik (which file)?

When you compile PHP with --enable-gd-jis-conv, do you also need the unifont.ttf as explained in this FAQ or is this font not required?
http://piwik.org/faq/how-to-install/#faq_142

@anonymous-piwik-user

No, this is a conceputual code.
I found this function is used in the pChart library, so I think adding the source to the library itself would be undesirable.

When you compile PHP with --enable-gd-jis-conv, do you also need the unifont.ttf as explained in this FAQ or is this font not required?

I'll try and report here.

@anonymous-piwik-user

I am sorry. In my misunderstanding, this was a phenomenon in the mobile app actually.
Please remove once this ticket.

@mattab
Owner

There is this other line with this error:
Warning: imagettftext(): any2eucjp(): invalid code in input string in /var/www/html/piwik/libs/pChart2.1.3/class/pDraw.class.php on line 1023

@tsteur
Owner

In 516c13d: fixes #4206 it is now possible to render the graphs, fix is verified on the mentioned Piwik instance

@tsteur
Owner

In 69b30cd: refs #4206 mention fix in readme

@anonymous-piwik-user anonymous-piwik-user added this to the 2.0 - Piwik 2.0 milestone
@sabl0r sabl0r referenced this issue from a commit in sabl0r/piwik
@tsteur tsteur fixes #4206 it is now possible to render the graphs, fix is verified …
…on the mentioned Piwik instance
516c13d
@sabl0r sabl0r referenced this issue from a commit in sabl0r/piwik
@tsteur tsteur refs #4206 mention fix in readme 69b30cd
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.