From 2f2756d246f2a8df3c9fec3b80b9e16cd4ebe87b Mon Sep 17 00:00:00 2001 From: "vincent@cubedesigners.com" Date: Fri, 19 Aug 2011 16:17:22 +0000 Subject: [PATCH] --- fluidbook/tools/convert.pe | 22 ++++++- .../apache/pdfbox/util/PDFStreamEngine.java | 19 ++++++ .../apache/pdfbox/util/operator/ShowText.java | 45 +++++++++++++ .../pdfbox/util/operator/ShowTextGlyph.java | 64 +++++++++++++++++++ inc/ws/Metier/class.ws.document.php | 1 + inc/ws/Util/html5/class.ws.html5.compiler.php | 13 ++-- 6 files changed, 157 insertions(+), 7 deletions(-) create mode 100644 fluidbook/tools/fwstk/src/org/apache/pdfbox/util/operator/ShowText.java create mode 100644 fluidbook/tools/fwstk/src/org/apache/pdfbox/util/operator/ShowTextGlyph.java diff --git a/fluidbook/tools/convert.pe b/fluidbook/tools/convert.pe index d9d307371..43c65f706 100644 --- a/fluidbook/tools/convert.pe +++ b/fluidbook/tools/convert.pe @@ -1,11 +1,29 @@ #!/usr/local/bin/fontforge Open($1,1) Print("Open font ",$1) -i=2; -while ( i<=$argc-2 ) +i=2 +while ( i<=$argc-3 ) Print ("Merge with font ",$argv[i]); MergeFonts($argv[i],1) ++i endloop + +// +if($argv[i]!="-") + cmap=LoadStringFromFile() + glyphs=StrSplit(cmap,"\\n"); + j=0 + while(j documentFontCache = new HashMap(); private int validCharCnt; private int totalCharCnt; + protected String currentString; /** * Flag to skip malformed or otherwise unparseable input where possible. */ @@ -151,6 +152,10 @@ public class PDFStreamEngine { totalCharCnt = 0; } + public void setCurrentString(String s) { + currentString = s; + } + public boolean isForceParsing() { return forceParsing; } @@ -366,6 +371,20 @@ public class PDFStreamEngine { c = font.encode(string, i, codeLength); } + try { + String currentChar= Character.toString(currentString.charAt(i)); + if (c.toUpperCase().equals(currentChar)) { + System.out.println("up"); + c = c.toUpperCase(); + } else if (c.toLowerCase().equals(currentChar)) { + System.out.println("low"); + c = c.toLowerCase(); + } + } catch ( NullPointerException | StringIndexOutOfBoundsException e) { + } + + //System.out.println(c+";"+currentString.charAt(i)); + // the space width has to be transformed into display units float spaceWidthDisp = spaceWidthText * fontSizeText * horizontalScalingText * textMatrix.getValue(0, 0) * ctm.getValue(0, 0); diff --git a/fluidbook/tools/fwstk/src/org/apache/pdfbox/util/operator/ShowText.java b/fluidbook/tools/fwstk/src/org/apache/pdfbox/util/operator/ShowText.java new file mode 100644 index 000000000..a5f7c8d4e --- /dev/null +++ b/fluidbook/tools/fwstk/src/org/apache/pdfbox/util/operator/ShowText.java @@ -0,0 +1,45 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.pdfbox.util.operator; + +import java.util.List; + +import org.apache.pdfbox.cos.COSBase; +import org.apache.pdfbox.cos.COSString; +import org.apache.pdfbox.util.PDFOperator; + +import java.io.IOException; + +/** + * @author Huault : huault@free.fr + * @version $Revision: 1.4 $ + */ +public class ShowText extends OperatorProcessor { + + /** + * Tj show Show text. + * @param operator The operator that is being executed. + * @param arguments List + * + * @throws IOException If there is an error processing this operator. + */ + public void process(PDFOperator operator, List arguments) throws IOException { + COSString string = (COSString) arguments.get(0); + context.setCurrentString(string.getString()); + context.processEncodedText(string.getBytes()); + } +} diff --git a/fluidbook/tools/fwstk/src/org/apache/pdfbox/util/operator/ShowTextGlyph.java b/fluidbook/tools/fwstk/src/org/apache/pdfbox/util/operator/ShowTextGlyph.java new file mode 100644 index 000000000..b61c6dece --- /dev/null +++ b/fluidbook/tools/fwstk/src/org/apache/pdfbox/util/operator/ShowTextGlyph.java @@ -0,0 +1,64 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.pdfbox.util.operator; + +import java.util.List; + +import org.apache.pdfbox.util.Matrix; +import org.apache.pdfbox.util.PDFOperator; +import org.apache.pdfbox.cos.COSArray; +import org.apache.pdfbox.cos.COSBase; +import org.apache.pdfbox.cos.COSNumber; +import java.io.IOException; +import org.apache.pdfbox.cos.COSString; + +/** + * @author Huault : huault@free.fr + * @version $Revision: 1.6 $ + */ +public class ShowTextGlyph extends OperatorProcessor { + + /** + * TJ Show text, allowing individual glyph positioning. + * @param operator The operator that is being executed. + * @param arguments List + * @throws IOException If there is an error processing this operator. + */ + public void process(PDFOperator operator, List arguments) throws IOException { + COSArray array = (COSArray) arguments.get(0); + int arraySize = array.size(); + float fontsize = context.getGraphicsState().getTextState().getFontSize(); + float horizontalScaling = context.getGraphicsState().getTextState().getHorizontalScalingPercent() / 100; + for (int i = 0; i < arraySize; i++) { + COSBase next = array.get(i); + if (next instanceof COSNumber) { + float adjustment = ((COSNumber) next).floatValue(); + Matrix adjMatrix = new Matrix(); + adjustment = -(adjustment / 1000) * horizontalScaling * fontsize; + // TODO vertical writing mode + adjMatrix.setValue(2, 0, adjustment); + context.setTextMatrix(adjMatrix.multiply(context.getTextMatrix(), adjMatrix)); + } else if (next instanceof COSString) { + context.setCurrentString(((COSString) next).getString()); + context.processEncodedText(((COSString) next).getBytes()); + + } else { + throw new IOException("Unknown type in array for TJ operation:" + next); + } + } + } +} diff --git a/inc/ws/Metier/class.ws.document.php b/inc/ws/Metier/class.ws.document.php index b960c3fbd..7b707046a 100644 --- a/inc/ws/Metier/class.ws.document.php +++ b/inc/ws/Metier/class.ws.document.php @@ -156,6 +156,7 @@ class wsDocument extends cubeMetier { foreach ($files as $file) { $fontforge->setArg(null, $out . '/' . $file); } + $fontforge->setArg(null, $this->out . '/html/' . $fontname . '.cmap'); $fontforge->setArg(null, $this->out . '/fonts/web/' . $fontname . '.ttf'); $fontforge->execute(); $this->addToLog($fontforge); diff --git a/inc/ws/Util/html5/class.ws.html5.compiler.php b/inc/ws/Util/html5/class.ws.html5.compiler.php index 0b89cc366..a05e34557 100644 --- a/inc/ws/Util/html5/class.ws.html5.compiler.php +++ b/inc/ws/Util/html5/class.ws.html5.compiler.php @@ -93,8 +93,8 @@ class wsHTML5Compiler { $firstDoc = $daoDoc->selectById($this->pages[1]['document_id']); $size = $firstDoc->generalInfos['size']; - $this->width = round($size[0],2); - $this->height = round($size[1],2); + $this->width = round($size[0], 2); + $this->height = round($size[1], 2); } public function virtualToPhysical($virtual) { @@ -297,8 +297,8 @@ class wsHTML5Compiler { $config->numerotation = explode(',', $this->book->numerotation); $config->id = $this->book->book_id; $config->cacheDate = TIME; - $config->width=$this->width; - $config->height=$this->height; + $config->width = $this->width; + $config->height = $this->height; return 'var DATAS=' . json_encode($config) . ';' . "\n"; } @@ -313,8 +313,11 @@ class wsHTML5Compiler { foreach ($this->fontDocs[$font] as $document_id => $dummy) { $fontforge->setArg(null, WS_DOCS . '/' . $document_id . '/fonts/web/' . $font . '.ttf'); } + $fontforge->setArg(null, '-'); $fontforge->setArg(null, $this->vdir . '/data/style/F' . $index . '.' . $format); $fontforge->execute(); + + fb($fontforge->commande); } } } @@ -560,7 +563,7 @@ class wsHTML5Compiler { // Links Styles $res = array_merge($res, $links); $res[] = '.link a.displayArea:hover,.link a.displayArea.animating{background-color:' . self::colorToCSS($this->theme->parametres->linksColor, 0.4) . ';}'; - $res[]='.link a.displayArea{-webkit-tap-highlight-color:'.self::colorToCSS($this->theme->parametres->linksColor, 0.4).';}'; + $res[] = '.link a.displayArea{-webkit-tap-highlight-color:' . self::colorToCSS($this->theme->parametres->linksColor, 0.4) . ';}'; // Menus # View -- 2.39.5