#!/usr/local/bin/fontforge
-Open($1)
-Generate($2)
\ No newline at end of file
+Open($1,1)
+
+i=2;
+while ( i<=$argc-2 )
+ if (i==1)
+ MergeFonts($argv[i],1)
+ endif
+ ++i
+endloop
+
+RemoveAllKerns()
+Generate($argv[i])
\ No newline at end of file
+++ /dev/null
-#!/usr/local/bin/fontforge
-
-a=FontsInFile($1)
-formats=Array(4);
-formats[0]='ttf';
-formats[1]='woff';
-formats[2]='svg';
-formats[3]='svgz';
-i=0
-while(i<SizeOf(a))
-
- e=StrSplit(a[i],"+",2)
- name=a[i]
- if(SizeOf(e)==2)
- name=e[1]
- endif
-
-
- Print("open font "+$1+"("+name+")")
- Open($1+"("+name+")")
- Print($fontname+">"+$nextfont)
-
- j=0;
-
- while(j<SizeOf(formats))
- out=$2+"/"+name+"."+formats[j]
- Print("write file "+out)
- Generate(out)
- j++
- endloop
- i++
-endloop
\ No newline at end of file
+++ /dev/null
-#!/usr/bin/python
-# vim:ts=8:sw=4:expandtab:encoding=utf-8
-# Export named font from PDF file using fontforge and ctypes
-
-import sys
-from ctypes import *
-
-STRING = c_char_p
-real = c_float
-
-# We need the `map` attribute of SplineFont, so declear an incomplete struct.
-# see: http://sourceforge.net/projects/wqy/files/misc/
-# file: fontforge-bindctypes-0.1.tar.bz2
-class splinefont(Structure):
- pass
-SplineFont = splinefont
-splinefont._fields_ = [
- ('fontname', STRING),
- ('fullname', STRING),
- ('familyname', STRING),
- ('weight', STRING),
- ('copyright', STRING),
- ('filename', STRING),
- ('defbasefilename', STRING),
- ('version', STRING),
- ('italicangle', real),
- ('upos', real),
- ('uwidth', real),
- ('ascent', c_int),
- ('descent', c_int),
- ('uniqueid', c_int),
- ('glyphcnt', c_int),
- ('glyphmax', c_int),
- ('glyphs', POINTER(c_void_p)),
- ('changed', c_uint, 1),
- ('changed_since_autosave', c_uint, 1),
- ('changed_since_xuidchanged', c_uint, 1),
- ('display_antialias', c_uint, 1),
- ('display_bbsized', c_uint, 1),
- ('dotlesswarn', c_uint, 1),
- ('onlybitmaps', c_uint, 1),
- ('serifcheck', c_uint, 1),
- ('issans', c_uint, 1),
- ('isserif', c_uint, 1),
- ('hasvmetrics', c_uint, 1),
- ('loading_cid_map', c_uint, 1),
- ('dupnamewarn', c_uint, 1),
- ('encodingchanged', c_uint, 1),
- ('multilayer', c_uint, 1),
- ('strokedfont', c_uint, 1),
- ('new', c_uint, 1),
- ('compacted', c_uint, 1),
- ('backedup', c_uint, 2),
- ('use_typo_metrics', c_uint, 1),
- ('weight_width_slope_only', c_uint, 1),
- ('save_to_dir', c_uint, 1),
- ('head_optimized_for_cleartype', c_uint, 1),
- ('ticked', c_uint, 1),
- ('internal_temp', c_uint, 1),
- ('complained_about_spiros', c_uint, 1),
- ('use_xuid', c_uint, 1),
- ('use_uniqueid', c_uint, 1),
- ('fv', c_void_p),
- ('metrics', c_void_p),
- ('uni_interp', c_int),
- ('for_new_glyphs', c_void_p),
- ('map', c_void_p),
- # ...
-]
-
-def main():
- if len(sys.argv) != 3:
- print "Usage: %s doc.pdf fontname" % sys.argv[0]
- sys.exit(2)
- pdfname = sys.argv[1]
- fontname = sys.argv[2]
- fontfile = fontname + '.ttf'
-
- # ctypes functions
- libc = CDLL("libc.so.6")
- libc.fopen.restype = c_void_p
- libc.fopen.argtype = [c_char_p, c_char_p]
-
- lib_ff = CDLL('libfontforge.so')
-
- # SplineFont *_SFReadPdfFont(FILE *pdf,char *filename,
- # char *select_this_font, enum openflags openflags)
- lib_ff._SFReadPdfFont.argtypes = [c_void_p, c_char_p, c_char_p, c_int]
- lib_ff._SFReadPdfFont.restype = POINTER(SplineFont)
-
- # int GenerateScript(SplineFont *sf, char *filename, char *bitmaptype,
- # int fmflags, int res, char *subfontdefinition, struct sflist *sfs,
- # EncMap *map, NameList *rename_to,int layer)
- lib_ff.GenerateScript.argytpes = [POINTER(SplineFont), c_char_p, c_char_p,
- c_int, c_int, c_char_p, c_void_p, c_void_p, c_void_p, c_int]
- lib_ff.GenerateScript.restype = c_int
-
- # need to somehow initialize libfontforge or it will segfault somewhere.
- lib_ff.doinitFontForgeMain()
- fobj = libc.fopen(pdfname, "rb")
- if not fobj:
- print "%s not found" % pdfname
- sys.exit(1)
-
- font = lib_ff._SFReadPdfFont(fobj, pdfname, fontname, 0)
- ret = 0
- if bool(font):
- ret = lib_ff.GenerateScript(font, fontfile, None, -1, -1, None, None,
- font.contents.map, None, 1)
- if ret:
- print 'Font export to "%s".' % fontfile
- else:
- print "** Error ** Failed to export font!!"
-
-if __name__ == '__main__':
- main()
-
<?xml version="1.0" encoding="UTF-8"?>\r
<classpath>\r
<classpathentry kind="src" path="src"/>\r
- <classpathentry kind="src" path="project_resources"/>\r
- <classpathentry kind="src" path="resources"/>\r
- <classpathentry excluding="com/fluidbook/fwstk/|com/fluidbook/fwstk/geom/|com/fluidbook/stats/|com/fluidbook/stats/lists/" kind="src" path="Java"/>\r
+ <classpathentry excluding="com/adobe/icc/rgb/" kind="src" path="project_resources"/>\r
+ <classpathentry excluding="org/apache/pdfbox/resources/cmap/" kind="src" path="resources"/>\r
+ <classpathentry excluding="com/fluidbook/fwstk/|com/fluidbook/fwstk/geom/|com/fluidbook/stats/|com/fluidbook/stats/lists/|com/maxmind/geoip/|org/jdom/|org/jdom/adapters/|org/jdom/filter/|org/jdom/input/|org/jdom/output/|org/jdom/transform/|org/jdom/xpath/|org/json/|resources/org/apache/pdfbox/resources/|resources/org/apache/pdfbox/resources/cmap/|resources/org/apache/pdfbox/resources/ttf/|jar/" kind="src" path="Java"/>\r
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jdk1.6.0_25"/>\r
<classpathentry kind="output" path="bin"/>\r
</classpath>\r
\r
cubeLang::set();\r
try {\r
- $this->authentifie();\r
+ $this->authentifie(); \r
} catch (Exception $e) {\r
\r
}\r
. 'LEFT JOIN utilisateurs_entreprise r ON d.revendeur=r.utilisateur_id '\r
. 'LEFT JOIN utilisateurs_entreprise c ON d.utilisateur=c.utilisateur_id '\r
. 'LEFT JOIN utilisateurs a ON d.administrateur=a.utilisateur_id');\r
- // cubeDb::mysqlConvert($this->con);\r
+ cubeDb::mysqlConvert($this->con, 'UTF8', 'utf8_general_ci', 'MYISAM'); \r
touch($cache);\r
}\r
\r
\r
public static function cleanPackages() {\r
$limit = TIME - (4 * 3600); // 4 heures avant maintenant*\r
+ // Clean downloads\r
+ $dir = ROOT . '/cache/download/';\r
+ $dr = opendir($dir);\r
+ while ($file = readdir($dr)) {\r
+ if ($file == '.' || $file == '..') {\r
+ continue;\r
+ }\r
+ $f = $dir . $file;\r
+ if (!is_dir($f)) {\r
+ continue;\r
+ }\r
+ if (filemtime($f) > $limit) {\r
+ continue;\r
+ }\r
+ `rm -rf $f`;\r
+ }\r
+\r
// Clean downloaded packages\r
$dir = WS_FILES . '/packager/download/';\r
$dr = opendir($dir);\r
mkdir($out, 0777, true);\r
}\r
// Extract fonts from PDF\r
- $gs = new cubeCommandLine('gs');\r
- $gs->setPath(CONVERTER_PATH);\r
- $gs->cd($out);\r
- $gs->setArg('-dBATCH');\r
- $gs->setArg('-dNOPAUSE');\r
- $gs->setArg('-dNOPROMPT');\r
- $gs->setArg('-dNODISPLAY');\r
- $gs->setArg(null, WS_TOOLS . '/extractFonts.ps');\r
- $gs->setManualArg('-c "(' . $this->in . ') extractFonts quit"');\r
-\r
- $gs->execute();\r
- $this->addToLog($gs);\r
-\r
+ /* $gs = new cubeCommandLine('gs');\r
+ $gs->setPath(CONVERTER_PATH);\r
+ $gs->cd($out);\r
+ $gs->setArg('-dBATCH');\r
+ $gs->setArg('-dNOPAUSE');\r
+ $gs->setArg('-dNOPROMPT');\r
+ $gs->setArg('-dNODISPLAY');\r
+ $gs->setArg(null, WS_TOOLS . '/extractFonts.ps');\r
+ $gs->setManualArg('-c "(' . $this->in . ') extractFonts quit"');\r
+\r
+ $gs->execute();\r
+ $this->addToLog($gs); */\r
+\r
+ $mupdf = new cubeCommandLine('/usr/local/mupdf/pdfextract');\r
+ $mupdf->setPath(CONVERTER_PATH);\r
+ $mupdf->cd($out);\r
+ $mupdf->setArg(null, $this->in);\r
+ $mupdf->execute();\r
+ $this->addToLog($mupdf);\r
+\r
+\r
+ `rm $out/fonts/*.png`;\r
+ `rm $out/fonts/*.pam`;\r
$dr = opendir($out);\r
\r
if (!file_exists($this->out . '/fonts/web')) {\r
}\r
$formats = array('ttf', 'woff', 'svg', 'svgz', 'eot');\r
// Fonts conversion\r
+ $collections = array();\r
while ($file = readdir($dr)) {\r
if ($file == '.' || $file == '..') {\r
continue;\r
array_pop($e);\r
$fname = implode('.', $e);\r
\r
+ $e = explode('-', $fname);\r
+ array_pop($e);\r
+ $fname = implode('-', $e);\r
+\r
+ if (!isset($collections[$fname])) {\r
+ $collections[$fname] = array();\r
+ }\r
+ $collections[$fname][] = $file;\r
+ }\r
+\r
+ foreach ($collections as $fontname => $files) {\r
foreach ($formats as $format) {\r
if ($format == 'eot') {\r
- $ttf2eot = new cubeCommandLine('ttf2eot', $this->out . '/fonts/web/' . $fname . '.eot');\r
+ $ttf2eot = new cubeCommandLine('ttf2eot', $this->out . '/fonts/web/' . $fontname . '.eot');\r
$ttf2eot->setPath(CONVERTER_PATH);\r
- $ttf2eot->setManualArg('< ' . $this->out . '/fonts/web/' . $fname . '.ttf');\r
+ $ttf2eot->setManualArg('< ' . $this->out . '/fonts/web/' . $fontname . '.ttf');\r
$ttf2eot->execute();\r
} else {\r
$fontforge = new cubeCommandLine('convert.pe');\r
$fontforge->setPath(CONVERTER_PATH);\r
- $fontforge->setArg(null, $out . '/' . $file);\r
- $fontforge->setArg(null, $this->out . '/fonts/web/' . $fname . '.' . $format);\r
+ foreach ($files as $file) {\r
+ $fontforge->setArg(null, $out . '/' . $file);\r
+ }\r
+ $fontforge->setArg(null, $this->out . '/fonts/web/' . $fontname . '.' . $format);\r
$fontforge->execute();\r
$this->addToLog($fontforge);\r
}\r
// Then make HD background shots\r
$resolutions = array(36 => 80, 72 => 70, 150 => 50);\r
foreach ($resolutions as $r => $q) {\r
- $texts=false;\r
+ $texts = false;\r
$this->makeShotPNM($page, 'html/h' . $r . '-', $r, $q, 4, null, $texts);\r
}\r
}\r
}
public function getCSS() {
- return 'border:1px dotter #ff0000;';
+ return '';
}
public static function getUniversalLocation($loc, $css=false) {
}\r
\r
$imagesize = getimagesize(WS_DOCS . '/' . $this->pages[1]['document_id'] . '/html/h72-' . $this->pages[1]['document_page'] . '.jpg');\r
- $this->pdf2htmlRatio = $imagesize[0] / $this->layouts[1]['width'];\r
+ $this->pdf2htmlRatio = round($imagesize[0] / $this->layouts[1]['width'], 2);\r
$this->scale = 4;\r
$this->multiply = $this->pdf2htmlRatio * $this->scale;\r
$this->numerotation = explode(',', $this->book->numerotation);\r
return $p + 1;\r
}\r
\r
+ protected function compareLines($a, $b) {\r
+ if ((float) $a['y'] > (float) $b['y']) {\r
+ return 1;\r
+ } else {\r
+ return -1;\r
+ }\r
+ }\r
+\r
protected function createHTML() {\r
foreach ($this->layouts as $page => $layout) {\r
$this->div[$page] = array();\r
$document_id = $this->pages[$page]['document_id'];\r
+ $lines = array();\r
foreach ($layout->l as $line) {\r
+ $lines[] = $line;\r
+ }\r
+ usort($lines, array($this, 'compareLines'));\r
+\r
+ foreach ($lines as $line) {\r
$this->div[$page][] = $this->addLine($line, $document_id);\r
}\r
}\r
}\r
\r
protected function writeLine($line) {\r
- $line['x'] = $this->getCSSX($line['x'] * $this->multiply);\r
- $line['y'] = $this->getCSSY($line['y'] * $this->multiply);\r
-\r
- $class = array('l');\r
- if (!is_null($line['rotation'])) {\r
- $class[] = 'r' . $line['rotation'];\r
- }\r
- if (!is_null($line['x'])) {\r
- $class[] = 'x' . $line['x'];\r
- }\r
- if (!is_null($line['y'])) {\r
- $class[] = 'y' . $line['y'];\r
- }\r
- $class = implode(' ', $class);\r
-\r
-\r
- $res = '<div class="' . $class . '">';\r
+ $res = '';\r
foreach ($line['groups'] as $group) {\r
- $res.=$this->writeGroup($group);\r
+ $res.=$this->writeGroup($group, $line);\r
}\r
- $res.='</div>';\r
return $res;\r
}\r
\r
- protected function writeGroup($group) {\r
+ protected function writeGroup($group, $line) {\r
if ($group === false) {\r
return '';\r
}\r
\r
- $group['y'] = $this->getCSSY($group['y'] * $this->multiply);\r
- $group['x'] = $this->getCSSX($group['x'] * $this->multiply);\r
+ $group['y'] = $this->getCSSY(($group['y'] + $line['y']) * $this->multiply);\r
+ $group['x'] = $this->getCSSX(($group['x']) * $this->multiply);\r
\r
$class = array('g');\r
if (!is_null($group['color'])) {\r
if (!is_null($group['y'])) {\r
$class[] = 'y' . $group['y'];\r
}\r
+ if (!is_null($line['rotation'])) {\r
+ $class[] = 'r' . $line['rotation'];\r
+ }\r
if (!is_null($group['letterspacing'])) {\r
$class[] = 'l' . $group['letterspacing'];\r
}\r
return '';\r
}\r
\r
- return self::escapeHTML($span['text']);\r
+ if ($span['space']) {\r
+ return $span['text'];\r
+ } else {\r
+ return self::escapeHTML($span['text']);\r
+ }\r
}\r
\r
protected function writeCSS($file, $links) {\r
$res[] = '.portrait #pages,.portrait .doublePage.page,.page,.portrait #shadow,#shadow.single,.page .links{width:' . $w . ';max-width:' . $w . ';height:' . $h . ';max-height:' . $h . '}';\r
$res[] = '.background{' . $this->writeCSSUA('transform-origin', 'top left') . ';}';\r
foreach (self::$resolutions as $r) {\r
- $ratio = 72 / $r;\r
+ $ratio = round(72 / $r, 2);\r
$wr = $this->book->parametres->width / $ratio;\r
$hr = $this->book->parametres->height / $ratio;\r
\r
$res[] = '.landscape #shadow.single.right{left: ' . $w . ';}';\r
$res[] = '.landscape .page.right{left:' . $w . '}';\r
$texts = '.texts{' . $this->writeCSSUA('transform-origin', 'top left') . ';';\r
- $texts.=$this->writeCSSUA('transform', 'scale(' . (1 / $this->multiply) . ')') . ';';\r
+ $texts.=$this->writeCSSUA('transform', 'scale(' . round(1 / $this->multiply, 2) . ')') . ';';\r
$texts.='width:' . $wm . '; max-width:' . $wm . ';';\r
$texts.='height:' . $hm . '; max-height:' . $hm . ';';\r
$texts.='}';\r
\r
$css = '.r' . $index . '{';\r
$css.=self::writeCSSUA('transform', 'rotate(' . $rotation . 'deg)') . ';';\r
- $css.=self::writeCSSUA('transform-origin', 'left top');\r
+ $css.=self::writeCSSUA('transform-origin', 'left top') . ';';\r
+ $css.='margin-top:' . round(cos(deg2rad($rotation)) * -1, 2) . 'em !important;';\r
+ $css.='margin-left:' . round(sin(deg2rad($rotation)), 2) . 'em !important;';\r
$css.='}';\r
$res[] = $css;\r
}\r
protected function addLine($line, $document_id) {\r
$res = array();\r
foreach ($line->a as $group) {\r
- $res[] = $this->addGroup($group, $document_id);\r
+ $res = array_merge($res, $this->addGroup($group, $document_id));\r
}\r
- return array('x' => $this->normalizeFloatValue($line['x']),\r
+ return array(\r
'y' => $this->normalizeFloatValue($line['y']),\r
'rotation' => $this->getCSSRotation($this->normalizeFloatValue($line['rotation'], 0)),\r
"groups" => $res);\r
return false;\r
}\r
\r
+ $first = true;\r
+ $letterSpacing = 0;\r
+ $letterCount = 0;\r
+ $wordSpacing = 0;\r
+ $wordCount = 0;\r
+\r
$res = array();\r
+ $spans = array();\r
\r
- $first = true;\r
foreach ($group->s as $span) {\r
+ if ($first && trim((string) $span) == '') {\r
+ continue;\r
+ }\r
if ($first) {\r
- $x = $span['x'];\r
+ $pos = $x = $span['x'];\r
+ $pos+=$span['width'];\r
$first = false;\r
+ } else {\r
+ if ((string) $span == 'MARDI 19') {\r
+ fb($span['x'], $newSpan['x']);\r
+ }\r
+ if ((float) $span['x'] < (float) $newSpan['x']) {\r
+ // On change de groupe\r
+ $ls = $ws = 0;\r
+ if ($letterCount > 0) {\r
+ $ls = $letterSpacing / $letterCount;\r
+ }\r
+ if ($wordCount > 0) {\r
+ $ws = $wordSpacing / $wordCount;\r
+ }\r
+\r
+ $res[] = array(\r
+ 'color' => $this->getCSSColor($group['color']),\r
+ 'size' => $this->getCSSSize($group['size']),\r
+ 'font' => $this->getCSSFont($group['font'], $document_id),\r
+ 'letterspacing' => $this->getCSSLetterSpacing($ls),\r
+ 'wordspacing' => $this->getCSSLetterSpacing($ws),\r
+ 'y' => 0,\r
+ 'x' => $x,\r
+ 'spans' => $spans);\r
+\r
+ $spans = array();\r
+ $pos = $x = $span['x'];\r
+ $pos+=$span['width'];\r
+ } else {\r
+\r
+ $diff = $span['x'] - $pos;\r
+ if ($diff > $group['size'] / 4) {\r
+ $space = round($diff / $group['size'], 4);\r
+ if ($space > 2) {\r
+ // On change de groupe\r
+ $ls = $ws = 0;\r
+ if ($letterCount > 0) {\r
+ $ls = $letterSpacing / $letterCount;\r
+ }\r
+ if ($wordCount > 0) {\r
+ $ws = $wordSpacing / $wordCount;\r
+ }\r
+ $res[] = array(\r
+ 'color' => $this->getCSSColor($group['color']),\r
+ 'size' => $this->getCSSSize($group['size']),\r
+ 'font' => $this->getCSSFont($group['font'], $document_id),\r
+ 'letterspacing' => $this->getCSSLetterSpacing($ls),\r
+ 'wordspacing' => $this->getCSSLetterSpacing($ws),\r
+ 'y' => 0,\r
+ 'x' => $x,\r
+ 'spans' => $spans);\r
+\r
+ $spans = array();\r
+ $pos = $x = $span['x'];\r
+ $pos+=$span['width'];\r
+ } else {\r
+\r
+ $newSpan = $this->addSpan('<span style="width:' . $space . 'em;"> </span>', true);\r
+ array_push($spans, $newSpan);\r
+ }\r
+ }\r
+ }\r
}\r
- $newSpan = $this->addSpan($span, $document_id);\r
\r
- array_push($res, $newSpan);\r
+\r
+ $newSpan = $this->addSpan($span);\r
+ $pos = $span['x'] + $span['width'];\r
+\r
+ array_push($spans, $newSpan);\r
+ $copy = (string) $span;\r
+ $len = mb_strlen($copy);\r
+ str_replace(' ', '-', $copy, $w);\r
+ $l = $len - $w;\r
+\r
+ $letterCount+=$l;\r
+ $wordCount+=$w;\r
+\r
+ $letterSpacing+=$l * (float) $span['letterspacing'];\r
+ $wordSpacing+=$w * (float) $span['wordspacing'];\r
}\r
\r
- return array(\r
- 'color' => $this->getCSSColor($group['color']),\r
- 'size' => $this->getCSSSize($group['size']),\r
- 'font' => $this->getCSSFont($group['font'], $document_id),\r
- 'letterspacing' => $this->getCSSLetterSpacing($group['letterspacing']),\r
- 'wordspacing' => $this->getCSSWordSpacing($group['wordspacing']),\r
- 'y' => ($group['size']) / -1.2,\r
- 'x' => $x,\r
- 'spans' => $res);\r
- }\r
+ if (count($spans)) {\r
+ $ls = $ws = 0;\r
+ if ($letterCount > 0) {\r
+ $ls = $letterSpacing / $letterCount;\r
+ }\r
+ if ($wordCount > 0) {\r
+ $ws = $wordSpacing / $wordCount;\r
+ }\r
\r
- protected function addSpan($span, $document_id) {\r
+ $res[] = array(\r
+ 'color' => $this->getCSSColor($group['color']),\r
+ 'size' => $this->getCSSSize($group['size']),\r
+ 'font' => $this->getCSSFont($group['font'], $document_id),\r
+ 'letterspacing' => $this->getCSSLetterSpacing($ls),\r
+ 'wordspacing' => $this->getCSSLetterSpacing($ws),\r
+ 'y' => 0,\r
+ 'x' => $x,\r
+ 'spans' => $spans);\r
+ }\r
\r
+ return $res;\r
+ }\r
+\r
+ protected function addSpan($span, $space=false) {\r
$text = (string) $span;\r
- if ($text == '') {\r
- return false;\r
- }\r
- return array('text' => $text);\r
+ return array('text' => $text, 'space' => $space, 'x' => $span['x']);\r
}\r
\r
- protected function getCSSSize(&$size) {\r
- $size = $this->normalizeFloatValue($size * $this->multiply, 3);\r
- $sizer = $size;\r
- return $this->getIndex($sizer, $this->cssSize);\r
+ protected function getCSSSize($size) {\r
+ $size = $this->normalizeFloatValue($size);\r
+ $size*=$this->multiply;\r
+ return $this->getIndex($size, $this->cssSize);\r
}\r
\r
protected function getCSSFont($font, $document_id) {\r