pspgraphics.cxx (5f27b83c) pspgraphics.cxx (248a599f)
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

--- 589 unchanged lines hidden (view full) ---

598
599//--------------------------------------------------------------------------
600
601bool PspFontLayout::LayoutText( ImplLayoutArgs& rArgs )
602{
603 mbVertical = ((rArgs.mnFlags & SAL_LAYOUT_VERTICAL) != 0);
604
605 long nUnitsPerPixel = 1;
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

--- 589 unchanged lines hidden (view full) ---

598
599//--------------------------------------------------------------------------
600
601bool PspFontLayout::LayoutText( ImplLayoutArgs& rArgs )
602{
603 mbVertical = ((rArgs.mnFlags & SAL_LAYOUT_VERTICAL) != 0);
604
605 long nUnitsPerPixel = 1;
606 int nOldGlyphId = -1;
606 sal_GlyphId aOldGlyphId( GF_DROPPED);
607 long nGlyphWidth = 0;
608 int nCharPos = -1;
609 Point aNewPos( 0, 0 );
610 GlyphItem aPrevItem;
611 rtl_TextEncoding aFontEnc = mrPrinterGfx.GetFontMgr().getFontEncoding( mnFontID );
612 for(;;)
613 {
614 bool bRightToLeft;
615 if( !rArgs.GetNextPos( &nCharPos, &bRightToLeft ) )
616 break;
617
618 sal_Unicode cChar = rArgs.mpStr[ nCharPos ];
619 if( bRightToLeft )
620 cChar = GetMirroredChar( cChar );
621 // symbol font aliasing: 0x0020-0x00ff -> 0xf020 -> 0xf0ff
622 if( aFontEnc == RTL_TEXTENCODING_SYMBOL )
623 if( cChar < 256 )
624 cChar += 0xf000;
607 long nGlyphWidth = 0;
608 int nCharPos = -1;
609 Point aNewPos( 0, 0 );
610 GlyphItem aPrevItem;
611 rtl_TextEncoding aFontEnc = mrPrinterGfx.GetFontMgr().getFontEncoding( mnFontID );
612 for(;;)
613 {
614 bool bRightToLeft;
615 if( !rArgs.GetNextPos( &nCharPos, &bRightToLeft ) )
616 break;
617
618 sal_Unicode cChar = rArgs.mpStr[ nCharPos ];
619 if( bRightToLeft )
620 cChar = GetMirroredChar( cChar );
621 // symbol font aliasing: 0x0020-0x00ff -> 0xf020 -> 0xf0ff
622 if( aFontEnc == RTL_TEXTENCODING_SYMBOL )
623 if( cChar < 256 )
624 cChar += 0xf000;
625 int nGlyphIndex = cChar; // printer glyphs = unicode
625 sal_GlyphId aGlyphId( cChar); // printer glyphs = unicode
626
627 // update fallback_runs if needed
628 psp::CharacterMetric aMetric;
629 mrPrinterGfx.GetFontMgr().getMetrics( mnFontID, cChar, cChar, &aMetric, mbVertical );
630 if( aMetric.width == -1 && aMetric.height == -1 )
631 rArgs.NeedFallback( nCharPos, bRightToLeft );
632
633 // apply pair kerning to prev glyph if requested
634 if( SAL_LAYOUT_KERNING_PAIRS & rArgs.mnFlags )
635 {
626
627 // update fallback_runs if needed
628 psp::CharacterMetric aMetric;
629 mrPrinterGfx.GetFontMgr().getMetrics( mnFontID, cChar, cChar, &aMetric, mbVertical );
630 if( aMetric.width == -1 && aMetric.height == -1 )
631 rArgs.NeedFallback( nCharPos, bRightToLeft );
632
633 // apply pair kerning to prev glyph if requested
634 if( SAL_LAYOUT_KERNING_PAIRS & rArgs.mnFlags )
635 {
636 if( nOldGlyphId > 0 )
636 if( aOldGlyphId > 0 )
637 {
638 const std::list< KernPair >& rKernPairs = mrPrinterGfx.getKernPairs(mbVertical);
639 for( std::list< KernPair >::const_iterator it = rKernPairs.begin();
640 it != rKernPairs.end(); ++it )
641 {
637 {
638 const std::list< KernPair >& rKernPairs = mrPrinterGfx.getKernPairs(mbVertical);
639 for( std::list< KernPair >::const_iterator it = rKernPairs.begin();
640 it != rKernPairs.end(); ++it )
641 {
642 if( it->first == nOldGlyphId && it->second == nGlyphIndex )
642 if( (it->first == aOldGlyphId) && (it->second == aGlyphId) )
643 {
644 int nTextScale = mrPrinterGfx.GetFontWidth();
645 if( ! nTextScale )
646 nTextScale = mrPrinterGfx.GetFontHeight();
647 int nKern = (mbVertical ? it->kern_y : it->kern_x) * nTextScale;
648 nGlyphWidth += nKern;
649 aPrevItem.mnNewWidth = nGlyphWidth;
650 break;
651 }
652 }
653 }
654 }
655
656 // finish previous glyph
643 {
644 int nTextScale = mrPrinterGfx.GetFontWidth();
645 if( ! nTextScale )
646 nTextScale = mrPrinterGfx.GetFontHeight();
647 int nKern = (mbVertical ? it->kern_y : it->kern_x) * nTextScale;
648 nGlyphWidth += nKern;
649 aPrevItem.mnNewWidth = nGlyphWidth;
650 break;
651 }
652 }
653 }
654 }
655
656 // finish previous glyph
657 if( nOldGlyphId >= 0 )
657 if( aOldGlyphId != GF_DROPPED )
658 AppendGlyph( aPrevItem );
658 AppendGlyph( aPrevItem );
659 nOldGlyphId = nGlyphIndex;
659 aOldGlyphId = aGlyphId;
660 aNewPos.X() += nGlyphWidth;
661
662 // prepare GlyphItem for appending it in next round
663 nUnitsPerPixel = mrPrinterGfx.GetCharWidth( cChar, cChar, &nGlyphWidth );
664 int nGlyphFlags = bRightToLeft ? GlyphItem::IS_RTL_GLYPH : 0;
660 aNewPos.X() += nGlyphWidth;
661
662 // prepare GlyphItem for appending it in next round
663 nUnitsPerPixel = mrPrinterGfx.GetCharWidth( cChar, cChar, &nGlyphWidth );
664 int nGlyphFlags = bRightToLeft ? GlyphItem::IS_RTL_GLYPH : 0;
665 nGlyphIndex |= GF_ISCHAR;
666 aPrevItem = GlyphItem( nCharPos, nGlyphIndex, aNewPos, nGlyphFlags, nGlyphWidth );
665 aGlyphId |= GF_ISCHAR;
666 aPrevItem = GlyphItem( nCharPos, aGlyphId, aNewPos, nGlyphFlags, nGlyphWidth );
667 }
668
669 // append last glyph item if any
667 }
668
669 // append last glyph item if any
670 if( nOldGlyphId >= 0 )
670 if( aOldGlyphId != GF_DROPPED )
671 AppendGlyph( aPrevItem );
672
673 SetOrientation( mrPrinterGfx.GetFontAngle() );
674 SetUnitsPerPixel( nUnitsPerPixel );
671 AppendGlyph( aPrevItem );
672
673 SetOrientation( mrPrinterGfx.GetFontAngle() );
674 SetUnitsPerPixel( nUnitsPerPixel );
675 return (nOldGlyphId >= 0);
675 return (aOldGlyphId != GF_DROPPED);
676}
677
678class PspServerFontLayout : public ServerFontLayout
679{
680public:
681 PspServerFontLayout( psp::PrinterGfx&, ServerFont& rFont, const ImplLayoutArgs& rArgs );
682
683 virtual void InitFont() const;

--- 32 unchanged lines hidden (view full) ---

716 mnOrientation, mbVertical, mbArtItalic, mbArtBold );
717}
718
719//--------------------------------------------------------------------------
720
721static void DrawPrinterLayout( const SalLayout& rLayout, ::psp::PrinterGfx& rGfx, bool bIsPspServerFontLayout )
722{
723 const int nMaxGlyphs = 200;
676}
677
678class PspServerFontLayout : public ServerFontLayout
679{
680public:
681 PspServerFontLayout( psp::PrinterGfx&, ServerFont& rFont, const ImplLayoutArgs& rArgs );
682
683 virtual void InitFont() const;

--- 32 unchanged lines hidden (view full) ---

716 mnOrientation, mbVertical, mbArtItalic, mbArtBold );
717}
718
719//--------------------------------------------------------------------------
720
721static void DrawPrinterLayout( const SalLayout& rLayout, ::psp::PrinterGfx& rGfx, bool bIsPspServerFontLayout )
722{
723 const int nMaxGlyphs = 200;
724 sal_uInt32 aGlyphAry[ nMaxGlyphs ]; // TODO: use sal_GlyphId
724 sal_GlyphId aGlyphAry[ nMaxGlyphs ];
725 sal_Int32 aWidthAry[ nMaxGlyphs ];
726 sal_Int32 aIdxAry [ nMaxGlyphs ];
727 sal_Unicode aUnicodes[ nMaxGlyphs ];
728 int aCharPosAry [ nMaxGlyphs ];
729
730 Point aPos;
731 long nUnitsPerPixel = rLayout.GetUnitsPerPixel();
732 const sal_Unicode* pText = NULL;

--- 31 unchanged lines hidden (view full) ---

764 if( !nGlyphCount )
765 break;
766
767 sal_Int32 nXOffset = 0;
768 for( int i = 0; i < nGlyphCount; ++i )
769 {
770 nXOffset += aWidthAry[ i ];
771 aIdxAry[ i ] = nXOffset / nUnitsPerPixel;
725 sal_Int32 aWidthAry[ nMaxGlyphs ];
726 sal_Int32 aIdxAry [ nMaxGlyphs ];
727 sal_Unicode aUnicodes[ nMaxGlyphs ];
728 int aCharPosAry [ nMaxGlyphs ];
729
730 Point aPos;
731 long nUnitsPerPixel = rLayout.GetUnitsPerPixel();
732 const sal_Unicode* pText = NULL;

--- 31 unchanged lines hidden (view full) ---

764 if( !nGlyphCount )
765 break;
766
767 sal_Int32 nXOffset = 0;
768 for( int i = 0; i < nGlyphCount; ++i )
769 {
770 nXOffset += aWidthAry[ i ];
771 aIdxAry[ i ] = nXOffset / nUnitsPerPixel;
772 sal_Int32 nGlyphIdx = aGlyphAry[i] & (GF_IDXMASK | GF_ROTMASK);
772 sal_GlyphId aGlyphId = aGlyphAry[i] & (GF_IDXMASK | GF_ROTMASK);
773 if( pText )
774 aUnicodes[i] = (aCharPosAry[i] >= nMinCharPos && aCharPosAry[i] <= nMaxCharPos) ? pText[ aCharPosAry[i] ] : 0;
775 else
773 if( pText )
774 aUnicodes[i] = (aCharPosAry[i] >= nMinCharPos && aCharPosAry[i] <= nMaxCharPos) ? pText[ aCharPosAry[i] ] : 0;
775 else
776 aUnicodes[i] = (aGlyphAry[i] & GF_ISCHAR) ? nGlyphIdx : 0;
777 aGlyphAry[i] = nGlyphIdx;
776 aUnicodes[i] = (aGlyphAry[i] & GF_ISCHAR) ? aGlyphId : 0;
777 aGlyphAry[i] = aGlyphId;
778 }
779
778 }
779
780 rGfx.DrawGlyphs( aPos, (sal_uInt32 *)aGlyphAry, aUnicodes, nGlyphCount, aIdxAry );
780 rGfx.DrawGlyphs( aPos, aGlyphAry, aUnicodes, nGlyphCount, aIdxAry );
781 }
782}
783
784//--------------------------------------------------------------------------
785
786void PspFontLayout::InitFont() const
787{
788 mrPrinterGfx.SetFont( mnFontID, mnFontHeight, mnFontWidth,

--- 170 unchanged lines hidden (view full) ---

959 pKernPairs[i].mnChar2 = it->second;
960 pKernPairs[i].mnKern = it->kern_x * nTextScale / 1000;
961 }
962
963 }
964 return nHavePairs;
965}
966
781 }
782}
783
784//--------------------------------------------------------------------------
785
786void PspFontLayout::InitFont() const
787{
788 mrPrinterGfx.SetFont( mnFontID, mnFontHeight, mnFontWidth,

--- 170 unchanged lines hidden (view full) ---

959 pKernPairs[i].mnChar2 = it->second;
960 pKernPairs[i].mnKern = it->kern_x * nTextScale / 1000;
961 }
962
963 }
964 return nHavePairs;
965}
966
967sal_Bool PspGraphics::GetGlyphBoundRect( long nGlyphIndex, Rectangle& rRect )
967bool PspGraphics::GetGlyphBoundRect( sal_GlyphId aGlyphId, Rectangle& rRect )
968{
968{
969 int nLevel = nGlyphIndex >> GF_FONTSHIFT;
969 const int nLevel = aGlyphId >> GF_FONTSHIFT;
970 if( nLevel >= MAX_FALLBACK )
970 if( nLevel >= MAX_FALLBACK )
971 return sal_False;
971 return false;
972
973 ServerFont* pSF = m_pServerFont[ nLevel ];
974 if( !pSF )
972
973 ServerFont* pSF = m_pServerFont[ nLevel ];
974 if( !pSF )
975 return sal_False;
975 return false;
976
976
977 nGlyphIndex &= ~GF_FONTMASK;
978 const GlyphMetric& rGM = pSF->GetGlyphMetric( nGlyphIndex );
977 aGlyphId &= ~GF_FONTMASK;
978 const GlyphMetric& rGM = pSF->GetGlyphMetric( aGlyphId );
979 rRect = Rectangle( rGM.GetOffset(), rGM.GetSize() );
979 rRect = Rectangle( rGM.GetOffset(), rGM.GetSize() );
980 return sal_True;
980 return true;
981}
982
981}
982
983sal_Bool PspGraphics::GetGlyphOutline( long nGlyphIndex,
983bool PspGraphics::GetGlyphOutline( sal_GlyphId aGlyphId,
984 ::basegfx::B2DPolyPolygon& rB2DPolyPoly )
985{
984 ::basegfx::B2DPolyPolygon& rB2DPolyPoly )
985{
986 int nLevel = nGlyphIndex >> GF_FONTSHIFT;
986 const int nLevel = aGlyphId >> GF_FONTSHIFT;
987 if( nLevel >= MAX_FALLBACK )
987 if( nLevel >= MAX_FALLBACK )
988 return sal_False;
988 return false;
989
990 ServerFont* pSF = m_pServerFont[ nLevel ];
991 if( !pSF )
989
990 ServerFont* pSF = m_pServerFont[ nLevel ];
991 if( !pSF )
992 return sal_False;
992 return false;
993
993
994 nGlyphIndex &= ~GF_FONTMASK;
995 if( pSF->GetGlyphOutline( nGlyphIndex, rB2DPolyPoly ) )
996 return sal_True;
997
998 return sal_False;
994 aGlyphId &= ~GF_FONTMASK;
995 bool bOK = pSF->GetGlyphOutline( aGlyphId, rB2DPolyPoly );
996 return bOK;
999}
1000
1001SalLayout* PspGraphics::GetTextLayout( ImplLayoutArgs& rArgs, int nFallbackLevel )
1002{
1003 // workaround for printers not handling glyph indexing for non-TT fonts
1004 int nFontId = m_pPrinterGfx->GetFontID();
1005 if( psp::fonttype::TrueType != psp::PrintFontManager::get().getFontType( nFontId ) )
1006 rArgs.mnFlags |= SAL_LAYOUT_DISABLE_GLYPH_PROCESSING;

--- 25 unchanged lines hidden (view full) ---

1032 return pLayout;
1033}
1034
1035//--------------------------------------------------------------------------
1036
1037sal_Bool PspGraphics::CreateFontSubset(
1038 const rtl::OUString& rToFile,
1039 const ImplFontData* pFont,
997}
998
999SalLayout* PspGraphics::GetTextLayout( ImplLayoutArgs& rArgs, int nFallbackLevel )
1000{
1001 // workaround for printers not handling glyph indexing for non-TT fonts
1002 int nFontId = m_pPrinterGfx->GetFontID();
1003 if( psp::fonttype::TrueType != psp::PrintFontManager::get().getFontType( nFontId ) )
1004 rArgs.mnFlags |= SAL_LAYOUT_DISABLE_GLYPH_PROCESSING;

--- 25 unchanged lines hidden (view full) ---

1030 return pLayout;
1031}
1032
1033//--------------------------------------------------------------------------
1034
1035sal_Bool PspGraphics::CreateFontSubset(
1036 const rtl::OUString& rToFile,
1037 const ImplFontData* pFont,
1040 sal_Int32* pGlyphIDs,
1038 sal_GlyphId* pGlyphIds,
1041 sal_uInt8* pEncoding,
1042 sal_Int32* pWidths,
1043 int nGlyphCount,
1044 FontSubsetInfo& rInfo
1045 )
1046{
1047 // in this context the pFont->GetFontId() is a valid PSP
1048 // font since they are the only ones left after the PDF
1049 // export has filtered its list of subsettable fonts (for
1050 // which this method was created). The correct way would
1051 // be to have the GlyphCache search for the ImplFontData pFont
1052 psp::fontID aFont = pFont->GetFontId();
1053
1054 psp::PrintFontManager& rMgr = psp::PrintFontManager::get();
1055 bool bSuccess = rMgr.createFontSubset( rInfo,
1056 aFont,
1057 rToFile,
1039 sal_uInt8* pEncoding,
1040 sal_Int32* pWidths,
1041 int nGlyphCount,
1042 FontSubsetInfo& rInfo
1043 )
1044{
1045 // in this context the pFont->GetFontId() is a valid PSP
1046 // font since they are the only ones left after the PDF
1047 // export has filtered its list of subsettable fonts (for
1048 // which this method was created). The correct way would
1049 // be to have the GlyphCache search for the ImplFontData pFont
1050 psp::fontID aFont = pFont->GetFontId();
1051
1052 psp::PrintFontManager& rMgr = psp::PrintFontManager::get();
1053 bool bSuccess = rMgr.createFontSubset( rInfo,
1054 aFont,
1055 rToFile,
1058 pGlyphIDs,
1056 pGlyphIds,
1059 pEncoding,
1060 pWidths,
1061 nGlyphCount );
1062 return bSuccess;
1063}
1064
1065//--------------------------------------------------------------------------
1066

--- 475 unchanged lines hidden ---
1057 pEncoding,
1058 pWidths,
1059 nGlyphCount );
1060 return bSuccess;
1061}
1062
1063//--------------------------------------------------------------------------
1064

--- 475 unchanged lines hidden ---