| 2194 | |
| 2195 | #define POPPLER_NEW_GFXFONT |
| 2196 | |
| 2197 | #ifdef POPPLER_NEW_GFXFONT |
| 2198 | |
| 2199 | /** |
| 2200 | * This is for the change to GfxFont's getNextChar() call. |
| 2201 | * Thanks to tsdgeos for the fix. |
| 2202 | * Miklos, does this look ok? |
| 2203 | */ |
| 2204 | |
| 2205 | void PdfParser::doShowText(GooString *s) { |
| 2206 | GfxFont *font; |
| 2207 | int wMode; |
| 2208 | double riseX, riseY; |
| 2209 | CharCode code; |
| 2210 | Unicode *u = NULL; |
| 2211 | double x, y, dx, dy, dx2, dy2, curX, curY, tdx, tdy, lineX, lineY; |
| 2212 | double originX, originY, tOriginX, tOriginY; |
| 2213 | double oldCTM[6], newCTM[6]; |
| 2214 | double *mat; |
| 2215 | Object charProc; |
| 2216 | Dict *resDict; |
| 2217 | Parser *oldParser; |
| 2218 | char *p; |
| 2219 | int len, n, uLen, nChars, nSpaces, i; |
| 2220 | |
| 2221 | font = state->getFont(); |
| 2222 | wMode = font->getWMode(); |
| 2223 | |
| 2224 | builder->beginString(state, s); |
| 2225 | |
| 2226 | // handle a Type 3 char |
| 2227 | if (font->getType() == fontType3 && 0) {//out->interpretType3Chars()) { |
| 2228 | mat = state->getCTM(); |
| 2229 | for (i = 0; i < 6; ++i) { |
| 2230 | oldCTM[i] = mat[i]; |
| 2231 | } |
| 2232 | mat = state->getTextMat(); |
| 2233 | newCTM[0] = mat[0] * oldCTM[0] + mat[1] * oldCTM[2]; |
| 2234 | newCTM[1] = mat[0] * oldCTM[1] + mat[1] * oldCTM[3]; |
| 2235 | newCTM[2] = mat[2] * oldCTM[0] + mat[3] * oldCTM[2]; |
| 2236 | newCTM[3] = mat[2] * oldCTM[1] + mat[3] * oldCTM[3]; |
| 2237 | mat = font->getFontMatrix(); |
| 2238 | newCTM[0] = mat[0] * newCTM[0] + mat[1] * newCTM[2]; |
| 2239 | newCTM[1] = mat[0] * newCTM[1] + mat[1] * newCTM[3]; |
| 2240 | newCTM[2] = mat[2] * newCTM[0] + mat[3] * newCTM[2]; |
| 2241 | newCTM[3] = mat[2] * newCTM[1] + mat[3] * newCTM[3]; |
| 2242 | newCTM[0] *= state->getFontSize(); |
| 2243 | newCTM[1] *= state->getFontSize(); |
| 2244 | newCTM[2] *= state->getFontSize(); |
| 2245 | newCTM[3] *= state->getFontSize(); |
| 2246 | newCTM[0] *= state->getHorizScaling(); |
| 2247 | newCTM[2] *= state->getHorizScaling(); |
| 2248 | state->textTransformDelta(0, state->getRise(), &riseX, &riseY); |
| 2249 | curX = state->getCurX(); |
| 2250 | curY = state->getCurY(); |
| 2251 | lineX = state->getLineX(); |
| 2252 | lineY = state->getLineY(); |
| 2253 | oldParser = parser; |
| 2254 | p = s->getCString(); |
| 2255 | len = s->getLength(); |
| 2256 | while (len > 0) { |
| 2257 | n = font->getNextChar(p, len, &code, |
| 2258 | &u, &uLen, |
| 2259 | &dx, &dy, &originX, &originY); |
| 2260 | dx = dx * state->getFontSize() + state->getCharSpace(); |
| 2261 | if (n == 1 && *p == ' ') { |
| 2262 | dx += state->getWordSpace(); |
| 2263 | } |
| 2264 | dx *= state->getHorizScaling(); |
| 2265 | dy *= state->getFontSize(); |
| 2266 | state->textTransformDelta(dx, dy, &tdx, &tdy); |
| 2267 | state->transform(curX + riseX, curY + riseY, &x, &y); |
| 2268 | saveState(); |
| 2269 | state->setCTM(newCTM[0], newCTM[1], newCTM[2], newCTM[3], x, y); |
| 2270 | //~ the CTM concat values here are wrong (but never used) |
| 2271 | //out->updateCTM(state, 1, 0, 0, 1, 0, 0); |
| 2272 | if (0){ /*!out->beginType3Char(state, curX + riseX, curY + riseY, tdx, tdy, |
| 2273 | code, u, uLen)) {*/ |
| 2274 | ((Gfx8BitFont *)font)->getCharProc(code, &charProc); |
| 2275 | if ((resDict = ((Gfx8BitFont *)font)->getResources())) { |
| 2276 | pushResources(resDict); |
| 2277 | } |
| 2278 | if (charProc.isStream()) { |
| 2279 | //parse(&charProc, gFalse); // TODO: parse into SVG font |
| 2280 | } else { |
| 2281 | error(getPos(), "Missing or bad Type3 CharProc entry"); |
| 2282 | } |
| 2283 | //out->endType3Char(state); |
| 2284 | if (resDict) { |
| 2285 | popResources(); |
| 2286 | } |
| 2287 | charProc.free(); |
| 2288 | } |
| 2289 | restoreState(); |
| 2290 | // GfxState::restore() does *not* restore the current position, |
| 2291 | // so we deal with it here using (curX, curY) and (lineX, lineY) |
| 2292 | curX += tdx; |
| 2293 | curY += tdy; |
| 2294 | state->moveTo(curX, curY); |
| 2295 | state->textSetPos(lineX, lineY); |
| 2296 | p += n; |
| 2297 | len -= n; |
| 2298 | } |
| 2299 | parser = oldParser; |
| 2300 | |
| 2301 | } else { |
| 2302 | state->textTransformDelta(0, state->getRise(), &riseX, &riseY); |
| 2303 | p = s->getCString(); |
| 2304 | len = s->getLength(); |
| 2305 | while (len > 0) { |
| 2306 | n = font->getNextChar(p, len, &code, |
| 2307 | &u, &uLen, |
| 2308 | &dx, &dy, &originX, &originY); |
| 2309 | |
| 2310 | if (wMode) { |
| 2311 | dx *= state->getFontSize(); |
| 2312 | dy = dy * state->getFontSize() + state->getCharSpace(); |
| 2313 | if (n == 1 && *p == ' ') { |
| 2314 | dy += state->getWordSpace(); |
| 2315 | } |
| 2316 | } else { |
| 2317 | dx = dx * state->getFontSize() + state->getCharSpace(); |
| 2318 | if (n == 1 && *p == ' ') { |
| 2319 | dx += state->getWordSpace(); |
| 2320 | } |
| 2321 | dx *= state->getHorizScaling(); |
| 2322 | dy *= state->getFontSize(); |
| 2323 | } |
| 2324 | state->textTransformDelta(dx, dy, &tdx, &tdy); |
| 2325 | originX *= state->getFontSize(); |
| 2326 | originY *= state->getFontSize(); |
| 2327 | state->textTransformDelta(originX, originY, &tOriginX, &tOriginY); |
| 2328 | builder->addChar(state, state->getCurX() + riseX, state->getCurY() + riseY, |
| 2329 | dx, dy, tOriginX, tOriginY, code, n, u, uLen); |
| 2330 | state->shift(tdx, tdy); |
| 2331 | p += n; |
| 2332 | len -= n; |
| 2333 | } |
| 2334 | } |
| 2335 | |
| 2336 | builder->endString(state); |
| 2337 | } |
| 2338 | |
| 2339 | #else /* !POPPLER_NEW_GFXFONT */ |
| 2340 | |