cairo_textlayout.cxx (07a3d7f1) | cairo_textlayout.cxx (906a4e93) |
---|---|
1/************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance --- 30 unchanged lines hidden (view full) --- 39#include <tools/postwin.h> 40#ifdef max 41#undef max 42#endif 43#ifdef min 44#undef min 45#endif 46#endif | 1/************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance --- 30 unchanged lines hidden (view full) --- 39#include <tools/postwin.h> 40#ifdef max 41#undef max 42#endif 43#ifdef min 44#undef min 45#endif 46#endif |
47 48#ifdef OS2 49#define INCL_WIN 50#include <os2.h> 51#endif 52 |
|
47#include <vcl/sysdata.hxx> 48 49#include <basegfx/matrix/b2dhommatrix.hxx> 50#include <basegfx/numeric/ftools.hxx> 51 52#include <boost/scoped_array.hpp> 53 54#include "cairo_textlayout.hxx" 55#include "cairo_spritecanvas.hxx" 56 57#ifdef CAIRO_HAS_QUARTZ_SURFACE 58# include "cairo_quartz_cairo.hxx" 59#elif defined CAIRO_HAS_WIN32_SURFACE 60# include "cairo_win32_cairo.hxx" 61# include <cairo-win32.h> 62#elif defined CAIRO_HAS_XLIB_SURFACE 63# include "cairo_xlib_cairo.hxx" 64# include <cairo-ft.h> | 53#include <vcl/sysdata.hxx> 54 55#include <basegfx/matrix/b2dhommatrix.hxx> 56#include <basegfx/numeric/ftools.hxx> 57 58#include <boost/scoped_array.hpp> 59 60#include "cairo_textlayout.hxx" 61#include "cairo_spritecanvas.hxx" 62 63#ifdef CAIRO_HAS_QUARTZ_SURFACE 64# include "cairo_quartz_cairo.hxx" 65#elif defined CAIRO_HAS_WIN32_SURFACE 66# include "cairo_win32_cairo.hxx" 67# include <cairo-win32.h> 68#elif defined CAIRO_HAS_XLIB_SURFACE 69# include "cairo_xlib_cairo.hxx" 70# include <cairo-ft.h> |
71#elif defined CAIRO_HAS_OS2_SURFACE 72# include "cairo_os2_cairo.hxx" 73# include <cairo-os2.h> |
|
65#else 66# error Native API needed. 67#endif 68 69using namespace ::cairo; 70using namespace ::com::sun::star; 71 72namespace cairocanvas --- 393 unchanged lines hidden (view full) --- 466 const FontLevelVector::const_iterator aFontDataEnd = aFontData.end(); 467 for( ; aFontDataIter != aFontDataEnd; ++aFontDataIter ) 468 { 469 const SystemFontData &rSysFontData = aFontDataIter->first; 470 471 // setup glyphs 472 std::vector<cairo_glyph_t> cairo_glyphs; 473 cairo_glyphs.reserve( 256 ); | 74#else 75# error Native API needed. 76#endif 77 78using namespace ::cairo; 79using namespace ::com::sun::star; 80 81namespace cairocanvas --- 393 unchanged lines hidden (view full) --- 475 const FontLevelVector::const_iterator aFontDataEnd = aFontData.end(); 476 for( ; aFontDataIter != aFontDataEnd; ++aFontDataIter ) 477 { 478 const SystemFontData &rSysFontData = aFontDataIter->first; 479 480 // setup glyphs 481 std::vector<cairo_glyph_t> cairo_glyphs; 482 cairo_glyphs.reserve( 256 ); |
474 | 483 |
475 SystemGlyphDataVector::const_iterator aIter=aSysLayoutData.rGlyphData.begin(); 476 const SystemGlyphDataVector::const_iterator aEnd=aSysLayoutData.rGlyphData.end(); 477 for( ; aIter != aEnd; ++aIter ) 478 { 479 SystemGlyphData systemGlyph = *aIter; 480 if( systemGlyph.fallbacklevel != aFontDataIter->second ) 481 continue; 482 483 cairo_glyph_t aGlyph; 484 aGlyph.index = systemGlyph.index; 485 #ifdef CAIRO_HAS_WIN32_SURFACE 486 // Cairo requires standard glyph indexes (ETO_GLYPH_INDEX), while vcl/win/* uses ucs4 chars. 487 // Convert to standard indexes 488 aGlyph.index = cairo::ucs4toindex((unsigned int) aGlyph.index, rSysFontData.hFont); | 484 SystemGlyphDataVector::const_iterator aIter=aSysLayoutData.rGlyphData.begin(); 485 const SystemGlyphDataVector::const_iterator aEnd=aSysLayoutData.rGlyphData.end(); 486 for( ; aIter != aEnd; ++aIter ) 487 { 488 SystemGlyphData systemGlyph = *aIter; 489 if( systemGlyph.fallbacklevel != aFontDataIter->second ) 490 continue; 491 492 cairo_glyph_t aGlyph; 493 aGlyph.index = systemGlyph.index; 494 #ifdef CAIRO_HAS_WIN32_SURFACE 495 // Cairo requires standard glyph indexes (ETO_GLYPH_INDEX), while vcl/win/* uses ucs4 chars. 496 // Convert to standard indexes 497 aGlyph.index = cairo::ucs4toindex((unsigned int) aGlyph.index, rSysFontData.hFont); |
498 #elif defined(CAIRO_HAS_OS2_SURFACE) 499 // Cairo requires standard glyph indexes (ETO_GLYPH_INDEX), while vcl/os2/* uses codepage chars. 500 // Convert to standard indexes 501 ::rtl::OString aFontName = ::rtl::OUStringToOString( 502 rOutDev.GetFont().GetName(), RTL_TEXTENCODING_UTF8); 503 aGlyph.index = cairo::ucs4toindex((unsigned int) aGlyph.index, aFontName); |
|
489 #endif 490 aGlyph.x = systemGlyph.x; 491 aGlyph.y = systemGlyph.y; 492 cairo_glyphs.push_back(aGlyph); 493 } 494 495 if (cairo_glyphs.empty()) 496 continue; | 504 #endif 505 aGlyph.x = systemGlyph.x; 506 aGlyph.y = systemGlyph.y; 507 cairo_glyphs.push_back(aGlyph); 508 } 509 510 if (cairo_glyphs.empty()) 511 continue; |
497 | 512 |
498 /** 499 * Setup font 500 **/ 501 cairo_font_face_t* font_face = NULL; 502 503 #ifdef CAIRO_HAS_QUARTZ_SURFACE 504 // TODO: use cairo_quartz_font_face_create_for_cgfont(cgFont) 505 // when CGFont (Mac OS X 10.5 API) is provided by the AQUA VCL backend. --- 5 unchanged lines hidden (view full) --- 511 #endif 512 // Note: cairo library uses logfont fallbacks when lfEscapement, lfOrientation and lfWidth are not zero. 513 // VCL always has non-zero value for lfWidth 514 font_face = cairo_win32_font_face_create_for_hfont(rSysFontData.hFont); 515 516 #elif defined CAIRO_HAS_XLIB_SURFACE 517 font_face = cairo_ft_font_face_create_for_ft_face((FT_Face)rSysFontData.nFontId, 518 rSysFontData.nFontFlags); | 513 /** 514 * Setup font 515 **/ 516 cairo_font_face_t* font_face = NULL; 517 518 #ifdef CAIRO_HAS_QUARTZ_SURFACE 519 // TODO: use cairo_quartz_font_face_create_for_cgfont(cgFont) 520 // when CGFont (Mac OS X 10.5 API) is provided by the AQUA VCL backend. --- 5 unchanged lines hidden (view full) --- 526 #endif 527 // Note: cairo library uses logfont fallbacks when lfEscapement, lfOrientation and lfWidth are not zero. 528 // VCL always has non-zero value for lfWidth 529 font_face = cairo_win32_font_face_create_for_hfont(rSysFontData.hFont); 530 531 #elif defined CAIRO_HAS_XLIB_SURFACE 532 font_face = cairo_ft_font_face_create_for_ft_face((FT_Face)rSysFontData.nFontId, 533 rSysFontData.nFontFlags); |
534 #elif defined CAIRO_HAS_OS2_SURFACE 535 // see below |
|
519 #else 520 # error Native API needed. 521 #endif 522 523 CairoSharedPtr pSCairo = pSurface->getCairo(); | 536 #else 537 # error Native API needed. 538 #endif 539 540 CairoSharedPtr pSCairo = pSurface->getCairo(); |
524 525 cairo_set_font_face( pSCairo.get(), font_face); | |
526 | 541 |
542 #if defined CAIRO_HAS_OS2_SURFACE 543 ::rtl::OString aFontName = ::rtl::OUStringToOString( 544 rOutDev.GetFont().GetName(), RTL_TEXTENCODING_UTF8); 545 cairo_font_slant_t slant = (rOutDev.GetFont().GetItalic() == ITALIC_NONE ? 546 CAIRO_FONT_SLANT_NORMAL : CAIRO_FONT_SLANT_ITALIC); 547 cairo_font_weight_t weight = (rOutDev.GetFont().GetWeight() == WEIGHT_NORMAL ? 548 CAIRO_FONT_WEIGHT_NORMAL : CAIRO_FONT_WEIGHT_BOLD); 549 cairo_select_font_face( pSCairo.get(), aFontName, 550 slant, weight); 551 #endif 552 553 if (font_face) 554 cairo_set_font_face( pSCairo.get(), font_face); 555 |
|
527 // create default font options. cairo_get_font_options() does not retrieve the surface defaults, 528 // only what has been set before with cairo_set_font_options() 529 cairo_font_options_t* options = cairo_font_options_create(); 530 if (rSysFontData.bAntialias) { 531 // CAIRO_ANTIALIAS_GRAY provides more similar result to VCL Canvas, 532 // so we're not using CAIRO_ANTIALIAS_SUBPIXEL 533 cairo_font_options_set_antialias(options, CAIRO_ANTIALIAS_GRAY); 534 } --- 54 unchanged lines hidden (view full) --- 589 #else 590 ::rtl::OUStringToOString( aFont.GetName(), RTL_TEXTENCODING_UTF8 ).getStr(), 591 #endif 592 ::rtl::OUStringToOString( maText.Text.copy( maText.StartPosition, maText.Length ), 593 RTL_TEXTENCODING_UTF8 ).getStr() 594 ); 595 596 cairo_show_glyphs(pSCairo.get(), &cairo_glyphs[0], cairo_glyphs.size()); | 556 // create default font options. cairo_get_font_options() does not retrieve the surface defaults, 557 // only what has been set before with cairo_set_font_options() 558 cairo_font_options_t* options = cairo_font_options_create(); 559 if (rSysFontData.bAntialias) { 560 // CAIRO_ANTIALIAS_GRAY provides more similar result to VCL Canvas, 561 // so we're not using CAIRO_ANTIALIAS_SUBPIXEL 562 cairo_font_options_set_antialias(options, CAIRO_ANTIALIAS_GRAY); 563 } --- 54 unchanged lines hidden (view full) --- 618 #else 619 ::rtl::OUStringToOString( aFont.GetName(), RTL_TEXTENCODING_UTF8 ).getStr(), 620 #endif 621 ::rtl::OUStringToOString( maText.Text.copy( maText.StartPosition, maText.Length ), 622 RTL_TEXTENCODING_UTF8 ).getStr() 623 ); 624 625 cairo_show_glyphs(pSCairo.get(), &cairo_glyphs[0], cairo_glyphs.size()); |
597 | 626 |
598 //faux bold 599 if (rSysFontData.bFakeBold) { 600 double bold_dx = 0.5 * sqrt( 0.7 * aFont.GetHeight() ); 601 int total_steps = 2 * ((int) (bold_dx + 0.5)); 602 603 // loop to draw the text for every half pixel of displacement 604 for (int nSteps = 0; nSteps < total_steps; nSteps++) { 605 for(int nGlyphIdx = 0; nGlyphIdx < (int) cairo_glyphs.size(); nGlyphIdx++) { 606 cairo_glyphs[nGlyphIdx].x += bold_dx * nSteps / total_steps; 607 } 608 cairo_show_glyphs(pSCairo.get(), &cairo_glyphs[0], cairo_glyphs.size()); 609 } 610 OSL_TRACE(":cairocanvas::TextLayout::draw(S,O,p,v,r): FAKEBOLD - dx:%d", (int) bold_dx); 611 } 612 613 cairo_restore( pSCairo.get() ); | 627 //faux bold 628 if (rSysFontData.bFakeBold) { 629 double bold_dx = 0.5 * sqrt( 0.7 * aFont.GetHeight() ); 630 int total_steps = 2 * ((int) (bold_dx + 0.5)); 631 632 // loop to draw the text for every half pixel of displacement 633 for (int nSteps = 0; nSteps < total_steps; nSteps++) { 634 for(int nGlyphIdx = 0; nGlyphIdx < (int) cairo_glyphs.size(); nGlyphIdx++) { 635 cairo_glyphs[nGlyphIdx].x += bold_dx * nSteps / total_steps; 636 } 637 cairo_show_glyphs(pSCairo.get(), &cairo_glyphs[0], cairo_glyphs.size()); 638 } 639 OSL_TRACE(":cairocanvas::TextLayout::draw(S,O,p,v,r): FAKEBOLD - dx:%d", (int) bold_dx); 640 } 641 642 cairo_restore( pSCairo.get() ); |
614 cairo_font_face_destroy(font_face); | 643 if (font_face) 644 cairo_font_face_destroy(font_face); |
615 } 616 return true; 617 } 618 619 620 namespace 621 { 622 class OffsetTransformer --- 71 unchanged lines hidden --- | 645 } 646 return true; 647 } 648 649 650 namespace 651 { 652 class OffsetTransformer --- 71 unchanged lines hidden --- |