Ignore:
Timestamp:
May 25, 2006, 4:09:55 PM (16 years ago)
Author:
Eugene Romanenko
Message:

poppler updated to version 0.5.2, also needed changes to be compatible with new poppler

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/poppler/mypoppler/poppler/CairoOutputDev.cc

    r2 r27  
    5353  fontEngine = NULL;
    5454  glyphs = NULL;
    55   surface = NULL;
    5655  fill_pattern = NULL;
    5756  stroke_pattern = NULL;
     
    5958  fill_opacity = 1.0;
    6059  textClipPath = NULL;
     60  cairo = NULL;
    6161}
    6262
     
    6666  }
    6767  FT_Done_FreeType(ft_lib);
    68   cairo_surface_destroy (surface);
     68 
     69  if (cairo)
     70    cairo_destroy (cairo);
    6971  cairo_pattern_destroy (stroke_pattern);
    7072  cairo_pattern_destroy (fill_pattern);
    7173}
    7274
    73 void CairoOutputDev::setSurface(cairo_surface_t *surface)
     75void CairoOutputDev::setCairo(cairo_t *cairo)
    7476{
    75   cairo_surface_destroy (this->surface);
    76   cairo_surface_reference (surface);
    77   this->surface = surface;
     77  if (this->cairo != NULL)
     78    cairo_destroy (this->cairo);
     79  if (cairo != NULL)
     80    this->cairo = cairo_reference (cairo);
     81  else
     82    this->cairo = NULL;
    7883}
    7984
     
    8489  }
    8590  fontEngine = new CairoFontEngine(ft_lib);
    86 }
    87 
    88 void CairoOutputDev::startPage(int pageNum, GfxState *state) {
    89   cairo = cairo_create (surface);
    90 }
    91 
    92 void CairoOutputDev::endPage() {
    93   cairo_destroy (cairo);
    9491}
    9592
     
    261258
    262259  needFontUpdate = gFalse;
    263 
    264   if (state->getFont()->getType() == fontType3)
    265     return;
    266260
    267261  currentFont = fontEngine->getFont (state->getFont(), xref);
     
    379373
    380374  glyphs[glyphCount].index = currentFont->getGlyph (code, u, uLen);
    381   state->transform(x, y, &tx, &ty);
     375  state->transform(x - originX, y - originY, &tx, &ty);
    382376  glyphs[glyphCount].x = tx;
    383377  glyphs[glyphCount].y = ty;
     
    452446
    453447void CairoOutputDev::type3D1(GfxState *state, double wx, double wy,
    454                               double llx, double lly, double urx, double ury) {
     448                             double llx, double lly, double urx, double ury) {
    455449}
    456450
     
    529523  image = cairo_image_surface_create_for_data (buffer, CAIRO_FORMAT_A8,
    530524                                               width, height, row_stride);
    531   if (image == NULL)
    532     return;
     525  if (image == NULL) {
     526    delete imgStr;
     527    return;
     528  }
    533529  pattern = cairo_pattern_create_for_surface (image);
    534   if (pattern == NULL)
    535     return;
     530  if (pattern == NULL) {
     531    delete imgStr;
     532    return;
     533  }
    536534
    537535  cairo_matrix_invert (&matrix);
     
    550548  cairo_surface_destroy (image);
    551549  free (buffer);
     550  delete imgStr;
     551}
     552
     553void CairoOutputDev::drawMaskedImage(GfxState *state, Object *ref,
     554                                Stream *str, int width, int height,
     555                                GfxImageColorMap *colorMap,
     556                                Stream *maskStr, int maskWidth,
     557                                int maskHeight, GBool maskInvert)
     558{
     559  ImageStream *maskImgStr;
     560  maskImgStr = new ImageStream(maskStr, maskWidth, 1, 1);
     561  maskImgStr->reset();
     562
     563  int row_stride = (maskWidth + 3) & ~3;
     564  unsigned char *maskBuffer;
     565  maskBuffer = (unsigned char *)gmalloc (row_stride * maskHeight);
     566  unsigned char *maskDest;
     567  cairo_surface_t *maskImage;
     568  cairo_pattern_t *maskPattern;
     569  Guchar *pix;
     570  int x, y;
     571
     572  int invert_bit;
     573 
     574  invert_bit = maskInvert ? 1 : 0;
     575
     576  for (y = 0; y < height; y++) {
     577    pix = maskImgStr->getLine();
     578    maskDest = maskBuffer + y * row_stride;
     579    for (x = 0; x < width; x++) {
     580      if (pix[x] ^ invert_bit)
     581        *maskDest++ = 0;
     582      else
     583        *maskDest++ = 255;
     584    }
     585  }
     586
     587  maskImage = cairo_image_surface_create_for_data (maskBuffer, CAIRO_FORMAT_A8,
     588                                                 maskWidth, maskHeight, row_stride);
     589
     590  delete maskImgStr;
     591  maskStr->close();
     592
     593  unsigned char *buffer;
     594  unsigned int *dest;
     595  cairo_surface_t *image;
     596  cairo_pattern_t *pattern;
     597  ImageStream *imgStr;
     598  GfxRGB rgb;
     599  int alpha, i;
     600  double *ctm;
     601  cairo_matrix_t matrix;
     602  cairo_matrix_t maskMatrix;
     603  int is_identity_transform;
     604
     605  buffer = (unsigned char *)gmalloc (width * height * 4);
     606
     607  /* TODO: Do we want to cache these? */
     608  imgStr = new ImageStream(str, width,
     609                           colorMap->getNumPixelComps(),
     610                           colorMap->getBits());
     611  imgStr->reset();
     612 
     613  /* ICCBased color space doesn't do any color correction
     614   * so check its underlying color space as well */
     615  is_identity_transform = colorMap->getColorSpace()->getMode() == csDeviceRGB ||
     616                  colorMap->getColorSpace()->getMode() == csICCBased &&
     617                  ((GfxICCBasedColorSpace*)colorMap->getColorSpace())->getAlt()->getMode() == csDeviceRGB;
     618
     619  for (y = 0; y < height; y++) {
     620    dest = (unsigned int *) (buffer + y * 4 * width);
     621    pix = imgStr->getLine();
     622    colorMap->getRGBLine (pix, dest, width);
     623  }
     624
     625  image = cairo_image_surface_create_for_data (buffer, CAIRO_FORMAT_RGB24,
     626                                                 width, height, width * 4);
     627
     628  if (image == NULL) {
     629    delete imgStr;
     630    return;
     631  }
     632  pattern = cairo_pattern_create_for_surface (image);
     633  maskPattern = cairo_pattern_create_for_surface (maskImage);
     634  if (pattern == NULL) {
     635    delete imgStr;
     636    return;
     637  }
     638
     639  ctm = state->getCTM();
     640  LOG (printf ("drawImageMask %dx%d, matrix: %f, %f, %f, %f, %f, %f\n",
     641               width, height, ctm[0], ctm[1], ctm[2], ctm[3], ctm[4], ctm[5]));
     642  matrix.xx = ctm[0] / width;
     643  matrix.xy = -ctm[2] / height;
     644  matrix.yx = ctm[1] / width;
     645  matrix.yy = -ctm[3] / height;
     646  matrix.x0 = ctm[2] + ctm[4];
     647  matrix.y0 = ctm[3] + ctm[5];
     648
     649  maskMatrix.xx = ctm[0] / maskWidth;
     650  maskMatrix.xy = -ctm[2] / maskHeight;
     651  maskMatrix.yx = ctm[1] / maskWidth;
     652  maskMatrix.yy = -ctm[3] / maskHeight;
     653  maskMatrix.x0 = ctm[2] + ctm[4];
     654  maskMatrix.y0 = ctm[3] + ctm[5];
     655
     656  cairo_matrix_invert (&matrix);
     657  cairo_matrix_invert (&maskMatrix);
     658
     659  cairo_pattern_set_matrix (pattern, &matrix);
     660  cairo_pattern_set_matrix (maskPattern, &maskMatrix);
     661
     662  cairo_pattern_set_filter (pattern, CAIRO_FILTER_BILINEAR);
     663  cairo_set_source (cairo, pattern);
     664  cairo_mask (cairo, maskPattern);
     665
     666  cairo_pattern_destroy (maskPattern);
     667  cairo_surface_destroy (maskImage);
     668  cairo_pattern_destroy (pattern);
     669  cairo_surface_destroy (image);
     670  free (buffer);
     671  free (maskBuffer);
    552672  delete imgStr;
    553673}
     
    595715  double *ctm;
    596716  cairo_matrix_t matrix;
     717  cairo_matrix_t maskMatrix;
    597718  int is_identity_transform;
    598719
     
    620741                                                 width, height, width * 4);
    621742
    622   if (image == NULL)
    623     return;
     743  if (image == NULL) {
     744    delete imgStr;
     745    return;
     746  }
    624747  pattern = cairo_pattern_create_for_surface (image);
    625748  maskPattern = cairo_pattern_create_for_surface (maskImage);
    626   if (pattern == NULL)
    627     return;
     749  if (pattern == NULL) {
     750    delete imgStr;
     751    return;
     752  }
    628753
    629754  ctm = state->getCTM();
     
    637762  matrix.y0 = ctm[3] + ctm[5];
    638763
     764  maskMatrix.xx = ctm[0] / maskWidth;
     765  maskMatrix.xy = -ctm[2] / maskHeight;
     766  maskMatrix.yx = ctm[1] / maskWidth;
     767  maskMatrix.yy = -ctm[3] / maskHeight;
     768  maskMatrix.x0 = ctm[2] + ctm[4];
     769  maskMatrix.y0 = ctm[3] + ctm[5];
     770
    639771  cairo_matrix_invert (&matrix);
     772  cairo_matrix_invert (&maskMatrix);
    640773
    641774  cairo_pattern_set_matrix (pattern, &matrix);
    642   cairo_pattern_set_matrix (maskPattern, &matrix);
     775  cairo_pattern_set_matrix (maskPattern, &maskMatrix);
    643776
    644777  cairo_pattern_set_filter (pattern, CAIRO_FILTER_BILINEAR);
     
    720853  }
    721854
    722   if (image == NULL)
    723     return;
     855  if (image == NULL) {
     856   delete imgStr;
     857   return;
     858  }
    724859  pattern = cairo_pattern_create_for_surface (image);
    725   if (pattern == NULL)
    726     return;
     860  if (pattern == NULL) {
     861    delete imgStr;
     862    return;
     863  }
    727864
    728865  ctm = state->getCTM();
Note: See TracChangeset for help on using the changeset viewer.