Lines 17-30
Link Here
|
17 |
* The Initial Developer of the Original Code is |
17 |
* The Initial Developer of the Original Code is |
18 |
* Netscape Communications Corporation. |
18 |
* Netscape Communications Corporation. |
19 |
* Portions created by the Initial Developer are Copyright (C) 1998 |
19 |
* Portions created by the Initial Developer are Copyright (C) 1998 |
20 |
* the Initial Developer. All Rights Reserved. |
20 |
* the Initial Developer. All Rights Reserved. |
21 |
* |
21 |
* |
22 |
* Contributor(s): |
22 |
* Contributor(s): |
23 |
* Roland Mainz <roland.mainz@informatik.med.uni-giessen.de> |
23 |
* Roland Mainz <roland.mainz@informatik.med.uni-giessen.de> |
|
|
24 |
* Ervin Yan <Ervin.Yan@sun.com> |
25 |
* Christopher Blizzard <blizzard@mozilla.org> |
26 |
* Jungshik Shin <jshin@i18nl10n.com> |
24 |
* |
27 |
* |
25 |
* |
28 |
* |
26 |
* Alternatively, the contents of this file may be used under the terms of |
29 |
* Alternatively, the contents of this file may be used under the terms of |
27 |
* either the GNU General Public License Version 2 or later (the "GPL"), or |
30 |
* either the GNU General Public License Version 2 or later (the "GPL"), or |
28 |
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), |
31 |
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), |
29 |
* in which case the provisions of the GPL or the LGPL are applicable instead |
32 |
* in which case the provisions of the GPL or the LGPL are applicable instead |
30 |
* of those above. If you wish to allow use of your version of this file only |
33 |
* of those above. If you wish to allow use of your version of this file only |
Lines 43-72
Link Here
|
43 |
#include "nsRenderingContextPS.h" |
46 |
#include "nsRenderingContextPS.h" |
44 |
#include "nsIServiceManager.h" |
47 |
#include "nsIServiceManager.h" |
45 |
#include "nsGfxCIID.h" |
48 |
#include "nsGfxCIID.h" |
46 |
|
49 |
|
47 |
#include "nsIPref.h" |
50 |
#include "nsIPref.h" |
48 |
#include "nsVoidArray.h" |
51 |
#include "nsVoidArray.h" |
49 |
#include "nsReadableUtils.h" |
52 |
#include "nsReadableUtils.h" |
50 |
#ifdef MOZ_ENABLE_FREETYPE2 |
53 |
#if defined(MOZ_ENABLE_FREETYPE2) || defined(MOZ_ENABLE_XFT) |
51 |
#include "nsType8.h" |
54 |
#include "nsType8.h" |
52 |
#endif |
55 |
#endif |
53 |
#include "prlog.h" |
56 |
#include "prlog.h" |
54 |
|
57 |
|
55 |
#include "nsArray.h" |
58 |
#include "nsArray.h" |
56 |
|
59 |
|
57 |
extern nsIAtom *gUsersLocale; |
60 |
extern nsIAtom *gUsersLocale; |
58 |
#define NS_IS_BOLD(weight) ((weight) > 400 ? 1 : 0) |
61 |
#define NS_IS_BOLD(weight) ((weight) > 400 ? 1 : 0) |
59 |
|
62 |
|
|
|
63 |
#ifdef MOZ_ENABLE_XFT |
64 |
|
65 |
#include "nsFontConfigUtils.h" |
66 |
|
67 |
static nsFontPS* CreateFontPS(nsXftEntry*, const nsFont&, |
68 |
nsFontMetricsPS*); |
69 |
|
70 |
#else |
60 |
#ifdef MOZ_ENABLE_FREETYPE2 |
71 |
#ifdef MOZ_ENABLE_FREETYPE2 |
61 |
static nsFontPS* CreateFontPS(nsITrueTypeFontCatalogEntry*, const nsFont&, |
72 |
static nsFontPS* CreateFontPS(nsITrueTypeFontCatalogEntry*, const nsFont&, |
62 |
nsFontMetricsPS*); |
73 |
nsFontMetricsPS*); |
63 |
|
74 |
|
64 |
static NS_DEFINE_CID(kFCSCID, NS_FONTCATALOGSERVICE_CID); |
75 |
static NS_DEFINE_CID(kFCSCID, NS_FONTCATALOGSERVICE_CID); |
65 |
#endif |
76 |
#endif |
|
|
77 |
#endif |
66 |
|
78 |
|
67 |
#ifdef PR_LOGGING |
79 |
#ifdef PR_LOGGING |
68 |
static PRLogModuleInfo *gFontMetricsPSM = PR_NewLogModule("FontMetricsPS"); |
80 |
static PRLogModuleInfo *gFontMetricsPSM = PR_NewLogModule("FontMetricsPS"); |
69 |
#endif |
81 |
#endif |
70 |
|
82 |
|
71 |
/** --------------------------------------------------- |
83 |
/** --------------------------------------------------- |
72 |
* See documentation in nsFontMetricsPS.h |
84 |
* See documentation in nsFontMetricsPS.h |
Lines 89-107
nsFontMetricsPS :: ~nsFontMetricsPS()
Link Here
|
89 |
|
101 |
|
90 |
if (mFontsPS) { |
102 |
if (mFontsPS) { |
91 |
int i; |
103 |
int i; |
92 |
for (i=0; i<mFontsPS->Count(); i++) { |
104 |
for (i=0; i<mFontsPS->Count(); i++) { |
93 |
fontps *fontPS = (fontps *)mFontsPS->ElementAt(i); |
105 |
fontps *fontPS = (fontps *)mFontsPS->ElementAt(i); |
94 |
if (!fontPS) |
106 |
if (!fontPS) |
95 |
continue; |
107 |
continue; |
96 |
NS_IF_RELEASE(fontPS->entry); |
|
|
97 |
if (fontPS->fontps) |
108 |
if (fontPS->fontps) |
98 |
delete fontPS->fontps; |
109 |
delete fontPS->fontps; |
|
|
110 |
#ifdef MOZ_ENABLE_XFT |
111 |
if (fontPS->entry) |
112 |
delete fontPS->entry; |
113 |
if (fontPS->charset) |
114 |
FcCharSetDestroy(fontPS->charset); |
115 |
#else |
116 |
#ifdef MOZ_ENABLE_FREETYPE2 |
117 |
NS_IF_RELEASE(fontPS->entry); |
99 |
if (fontPS->ccmap) |
118 |
if (fontPS->ccmap) |
100 |
FreeCCMap(fontPS->ccmap); |
119 |
FreeCCMap(fontPS->ccmap); |
|
|
120 |
#endif |
121 |
#endif |
101 |
delete fontPS; |
122 |
delete fontPS; |
102 |
} |
123 |
} |
103 |
delete mFontsPS; |
124 |
delete mFontsPS; |
104 |
} |
125 |
} |
105 |
|
126 |
|
106 |
if (mFontsAlreadyLoaded) { |
127 |
if (mFontsAlreadyLoaded) { |
107 |
delete mFontsAlreadyLoaded; |
128 |
delete mFontsAlreadyLoaded; |
Lines 123-136
NS_IMPL_ISUPPORTS1(nsFontMetricsPS, nsIF
Link Here
|
123 |
NS_IMETHODIMP |
144 |
NS_IMETHODIMP |
124 |
nsFontMetricsPS :: Init(const nsFont& aFont, nsIAtom* aLangGroup, |
145 |
nsFontMetricsPS :: Init(const nsFont& aFont, nsIAtom* aLangGroup, |
125 |
nsIDeviceContext *aContext) |
146 |
nsIDeviceContext *aContext) |
126 |
{ |
147 |
{ |
127 |
mLangGroup = aLangGroup; |
148 |
mLangGroup = aLangGroup; |
128 |
|
149 |
|
129 |
mFont = new nsFont(aFont); |
150 |
mFont = new nsFont(aFont); |
|
|
151 |
|
130 |
//don't addref this to avoid circular refs |
152 |
//don't addref this to avoid circular refs |
131 |
mDeviceContext = (nsDeviceContextPS *)aContext; |
153 |
mDeviceContext = (nsDeviceContextPS *)aContext; |
132 |
|
154 |
|
133 |
mFontsPS = new nsVoidArray(); |
155 |
mFontsPS = new nsVoidArray(); |
134 |
NS_ENSURE_TRUE(mFontsPS, NS_ERROR_OUT_OF_MEMORY); |
156 |
NS_ENSURE_TRUE(mFontsPS, NS_ERROR_OUT_OF_MEMORY); |
135 |
mFontsAlreadyLoaded = new nsHashtable(); |
157 |
mFontsAlreadyLoaded = new nsHashtable(); |
136 |
NS_ENSURE_TRUE(mFontsAlreadyLoaded, NS_ERROR_OUT_OF_MEMORY); |
158 |
NS_ENSURE_TRUE(mFontsAlreadyLoaded, NS_ERROR_OUT_OF_MEMORY); |
Lines 158-172
nsFontMetricsPS :: Destroy()
Link Here
|
158 |
void |
180 |
void |
159 |
nsFontMetricsPS::RealizeFont() |
181 |
nsFontMetricsPS::RealizeFont() |
160 |
{ |
182 |
{ |
161 |
if (mFont && mDeviceContext) { |
183 |
if (mFont && mDeviceContext) { |
162 |
float dev2app; |
184 |
float dev2app; |
163 |
dev2app = mDeviceContext->DevUnitsToAppUnits(); |
185 |
dev2app = mDeviceContext->DevUnitsToAppUnits(); |
164 |
fontps *font = (fontps*)mFontsPS->ElementAt(0); |
186 |
fontps *font = (fontps*)mFontsPS->ElementAt(0); |
165 |
#ifdef MOZ_ENABLE_FREETYPE2 |
187 |
#if defined(MOZ_ENABLE_FREETYPE2) || defined(MOZ_ENABLE_XFT) |
166 |
NS_ASSERTION(font && font->entry, "no font available"); |
188 |
NS_ASSERTION(font && font->entry, "no font available"); |
167 |
if (font && !font->fontps && font->entry) |
189 |
if (font && !font->fontps && font->entry) |
168 |
font->fontps = CreateFontPS(font->entry, *mFont, this); |
190 |
font->fontps = CreateFontPS(font->entry, *mFont, this); |
169 |
#endif |
191 |
#endif |
170 |
NS_ASSERTION(font && font->fontps, "no font available"); |
192 |
NS_ASSERTION(font && font->fontps, "no font available"); |
171 |
if (font && font->fontps) |
193 |
if (font && font->fontps) |
172 |
font->fontps->RealizeFont(this, dev2app); |
194 |
font->fontps->RealizeFont(this, dev2app); |
Lines 464-482
nsFontPS::FindFont(char aChar, const nsF
Link Here
|
464 |
// nsFontPS |
486 |
// nsFontPS |
465 |
nsFontPS* |
487 |
nsFontPS* |
466 |
nsFontPS::FindFont(PRUnichar aChar, const nsFont& aFont, |
488 |
nsFontPS::FindFont(PRUnichar aChar, const nsFont& aFont, |
467 |
nsFontMetricsPS* aFontMetrics) |
489 |
nsFontMetricsPS* aFontMetrics) |
468 |
{ |
490 |
{ |
469 |
nsFontPS* fontPS; |
491 |
nsFontPS* fontPS; |
470 |
|
492 |
|
471 |
#ifdef MOZ_ENABLE_FREETYPE2 |
493 |
#if defined(MOZ_ENABLE_FREETYPE2) || defined(MOZ_ENABLE_XFT) |
472 |
nsDeviceContextPS* dc = aFontMetrics->GetDeviceContext(); |
494 |
nsDeviceContextPS* dc = aFontMetrics->GetDeviceContext(); |
473 |
NS_ENSURE_TRUE(dc, nsnull); |
495 |
NS_ENSURE_TRUE(dc, nsnull); |
474 |
if (dc->mFTPEnable) { |
496 |
if (dc->mFTPEnable) { |
|
|
497 |
#ifdef MOZ_ENABLE_XFT |
498 |
fontPS = nsFontPSXft::FindFont(aChar, aFont, aFontMetrics); |
499 |
#else |
475 |
fontPS = nsFontPSFreeType::FindFont(aChar, aFont, aFontMetrics); |
500 |
fontPS = nsFontPSFreeType::FindFont(aChar, aFont, aFontMetrics); |
|
|
501 |
#endif |
476 |
if (fontPS) |
502 |
if (fontPS) |
477 |
return fontPS; |
503 |
return fontPS; |
478 |
} |
504 |
} |
479 |
#endif |
505 |
#endif |
480 |
|
506 |
|
481 |
/* Find in afm font */ |
507 |
/* Find in afm font */ |
482 |
if (aFontMetrics->GetFontsPS()->Count() > 0) { |
508 |
if (aFontMetrics->GetFontsPS()->Count() > 0) { |
Lines 484-500
nsFontPS::FindFont(PRUnichar aChar, cons
Link Here
|
484 |
NS_ENSURE_TRUE(fps, nsnull); |
510 |
NS_ENSURE_TRUE(fps, nsnull); |
485 |
fontPS = fps->fontps; |
511 |
fontPS = fps->fontps; |
486 |
} |
512 |
} |
487 |
else { |
513 |
else { |
488 |
fontPS = nsFontPSAFM::FindFont(aFont, aFontMetrics); |
514 |
fontPS = nsFontPSAFM::FindFont(aFont, aFontMetrics); |
489 |
fontps *fps = new fontps; |
515 |
fontps *fps = new fontps; |
490 |
NS_ENSURE_TRUE(fps, nsnull); |
516 |
NS_ENSURE_TRUE(fps, nsnull); |
491 |
fps->entry = nsnull; |
|
|
492 |
fps->fontps = fontPS; |
517 |
fps->fontps = fontPS; |
|
|
518 |
#if defined(MOZ_ENABLE_XFT) || defined(MOZ_ENABLE_FREETYPE2) |
519 |
fps->entry = nsnull; |
520 |
#ifdef MOZ_ENABLE_XFT |
521 |
fps->charset = nsnull; |
522 |
#else |
493 |
fps->ccmap = nsnull; |
523 |
fps->ccmap = nsnull; |
|
|
524 |
#endif |
525 |
#endif |
494 |
aFontMetrics->GetFontsPS()->AppendElement(fps); |
526 |
aFontMetrics->GetFontsPS()->AppendElement(fps); |
495 |
} |
527 |
} |
496 |
return fontPS; |
528 |
return fontPS; |
497 |
} |
529 |
} |
498 |
|
530 |
|
499 |
nsFontPS::nsFontPS(const nsFont& aFont, nsFontMetricsPS* aFontMetrics) |
531 |
nsFontPS::nsFontPS(const nsFont& aFont, nsFontMetricsPS* aFontMetrics) |
500 |
{ |
532 |
{ |
Lines 544-705
nsFontPSAFM::FindFont(const nsFont& aFon
Link Here
|
544 |
} |
576 |
} |
545 |
|
577 |
|
546 |
nsFontPSAFM::nsFontPSAFM(const nsFont& aFont, nsAFMObject* aAFMInfo, |
578 |
nsFontPSAFM::nsFontPSAFM(const nsFont& aFont, nsAFMObject* aAFMInfo, |
547 |
PRInt16 fontIndex, nsFontMetricsPS* aFontMetrics) : |
579 |
PRInt16 fontIndex, nsFontMetricsPS* aFontMetrics) : |
548 |
nsFontPS(aFont, aFontMetrics), mAFMInfo(aAFMInfo), mFontIndex(fontIndex) |
580 |
nsFontPS(aFont, aFontMetrics), mAFMInfo(aAFMInfo), mFontIndex(fontIndex) |
549 |
{ |
581 |
{ |
550 |
if (!(mFont && mAFMInfo)) return; |
582 |
if (!(mFont && mAFMInfo)) return; |
551 |
mFamilyName.AssignWithConversion((char*)mAFMInfo->mPSFontInfo->mFamilyName); |
583 |
AppendASCIItoUTF16(mAFMInfo->mPSFontInfo->mFamilyName, mFamilyName); |
552 |
} |
584 |
} |
553 |
|
585 |
|
554 |
nsFontPSAFM::~nsFontPSAFM() |
586 |
nsFontPSAFM::~nsFontPSAFM() |
555 |
{ |
587 |
{ |
556 |
if (mAFMInfo) { |
588 |
if (mAFMInfo) { |
557 |
delete mAFMInfo; |
589 |
delete mAFMInfo; |
558 |
mAFMInfo = nsnull; |
590 |
mAFMInfo = nsnull; |
559 |
} |
591 |
} |
560 |
} |
592 |
} |
561 |
|
593 |
|
562 |
nscoord |
594 |
nscoord |
563 |
nsFontPSAFM::GetWidth(const char* aString, PRUint32 aLength) |
595 |
nsFontPSAFM::GetWidth(const char* aString, PRUint32 aLength) |
564 |
{ |
596 |
{ |
565 |
nscoord width = 0; |
597 |
nscoord width = 0; |
566 |
if (mAFMInfo) { |
598 |
if (mAFMInfo) { |
567 |
mAFMInfo->GetStringWidth(aString, width, aLength); |
599 |
mAFMInfo->GetStringWidth(aString, width, aLength); |
568 |
} |
600 |
} |
569 |
return width; |
601 |
return width; |
|
|
602 |
} |
603 |
|
604 |
nscoord |
605 |
nsFontPSAFM::GetWidth(const PRUnichar* aString, PRUint32 aLength) |
606 |
{ |
607 |
nscoord width = 0; |
608 |
if (mAFMInfo) { |
609 |
mAFMInfo->GetStringWidth(aString, width, aLength); |
610 |
} |
611 |
return width; |
612 |
} |
613 |
|
614 |
nscoord |
615 |
nsFontPSAFM::DrawString(nsRenderingContextPS* aContext, |
616 |
nscoord aX, nscoord aY, |
617 |
const char* aString, PRUint32 aLength) |
618 |
{ |
619 |
NS_ENSURE_TRUE(aContext, 0); |
620 |
nsPostScriptObj* psObj = aContext->GetPostScriptObj(); |
621 |
NS_ENSURE_TRUE(psObj, 0); |
622 |
|
623 |
psObj->moveto(aX, aY); |
624 |
psObj->show(aString, aLength, ""); |
625 |
return GetWidth(aString, aLength); |
626 |
} |
627 |
|
628 |
nscoord |
629 |
nsFontPSAFM::DrawString(nsRenderingContextPS* aContext, |
630 |
nscoord aX, nscoord aY, |
631 |
const PRUnichar* aString, PRUint32 aLength) |
632 |
{ |
633 |
NS_ENSURE_TRUE(aContext, 0); |
634 |
nsPostScriptObj* psObj = aContext->GetPostScriptObj(); |
635 |
NS_ENSURE_TRUE(psObj, 0); |
636 |
|
637 |
psObj->moveto(aX, aY); |
638 |
psObj->show(aString, aLength, "", 0); |
639 |
return GetWidth(aString, aLength); |
640 |
} |
641 |
|
642 |
nsresult |
643 |
nsFontPSAFM::RealizeFont(nsFontMetricsPS* aFontMetrics, float dev2app) |
644 |
{ |
645 |
NS_ENSURE_ARG_POINTER(aFontMetrics); |
646 |
|
647 |
float fontSize; |
648 |
float offset; |
649 |
|
650 |
nscoord onePixel = NSToCoordRound(1 * dev2app); |
651 |
|
652 |
// convert the font size which is in twips to points |
653 |
fontSize = mFont->size / TWIPS_PER_POINT_FLOAT; |
654 |
|
655 |
offset = NSFloatPointsToTwips(fontSize * mAFMInfo->mPSFontInfo->mXHeight) / 1000.0f; |
656 |
nscoord xHeight = NSToCoordRound(offset); |
657 |
aFontMetrics->SetXHeight(xHeight); |
658 |
aFontMetrics->SetSuperscriptOffset(xHeight); |
659 |
aFontMetrics->SetSubscriptOffset(xHeight); |
660 |
aFontMetrics->SetStrikeout((nscoord)(xHeight / 2), onePixel); |
661 |
|
662 |
offset = NSFloatPointsToTwips(fontSize * mAFMInfo->mPSFontInfo->mUnderlinePosition) / 1000.0f; |
663 |
aFontMetrics->SetUnderline(NSToCoordRound(offset), onePixel); |
664 |
|
665 |
nscoord size = NSToCoordRound(fontSize * dev2app); |
666 |
aFontMetrics->SetHeight(size); |
667 |
aFontMetrics->SetEmHeight(size); |
668 |
aFontMetrics->SetMaxAdvance(size); |
669 |
aFontMetrics->SetMaxHeight(size); |
670 |
|
671 |
offset = NSFloatPointsToTwips(fontSize * mAFMInfo->mPSFontInfo->mAscender) / 1000.0f; |
672 |
nscoord ascent = NSToCoordRound(offset); |
673 |
aFontMetrics->SetAscent(ascent); |
674 |
aFontMetrics->SetEmAscent(ascent); |
675 |
aFontMetrics->SetMaxAscent(ascent); |
676 |
|
677 |
offset = NSFloatPointsToTwips(fontSize * mAFMInfo->mPSFontInfo->mDescender) / 1000.0f; |
678 |
nscoord descent = -(NSToCoordRound(offset)); |
679 |
aFontMetrics->SetDescent(descent); |
680 |
aFontMetrics->SetEmDescent(descent); |
681 |
aFontMetrics->SetMaxDescent(descent); |
682 |
|
683 |
aFontMetrics->SetLeading(0); |
684 |
|
685 |
nscoord spaceWidth = GetWidth(" ", 1); |
686 |
aFontMetrics->SetSpaceWidth(spaceWidth); |
687 |
|
688 |
nscoord aveCharWidth = GetWidth("x", 1); |
689 |
aFontMetrics->SetAveCharWidth(aveCharWidth); |
690 |
|
691 |
return NS_OK; |
692 |
} |
693 |
|
694 |
nsresult |
695 |
nsFontPSAFM::SetupFont(nsRenderingContextPS* aContext) |
696 |
{ |
697 |
NS_ENSURE_TRUE(aContext && mFontMetrics, 0); |
698 |
nsPostScriptObj* psObj = aContext->GetPostScriptObj(); |
699 |
NS_ENSURE_TRUE(psObj, 0); |
700 |
|
701 |
nscoord fontHeight = 0; |
702 |
mFontMetrics->GetHeight(fontHeight); |
703 |
|
704 |
psObj->setscriptfont(mFontIndex, mFamilyName, |
705 |
fontHeight, mFont->style, mFont->variant, |
706 |
mFont->weight, mFont->decorations); |
707 |
return NS_OK; |
708 |
} |
709 |
|
710 |
#ifdef MOZ_MATHML |
711 |
nsresult |
712 |
nsFontPSAFM::GetBoundingMetrics(const char* aString, |
713 |
PRUint32 aLength, |
714 |
nsBoundingMetrics& aBoundingMetrics) |
715 |
{ |
716 |
return NS_ERROR_NOT_IMPLEMENTED; |
717 |
} |
718 |
|
719 |
nsresult |
720 |
nsFontPSAFM::GetBoundingMetrics(const PRUnichar* aString, |
721 |
PRUint32 aLength, |
722 |
nsBoundingMetrics& aBoundingMetrics) |
723 |
{ |
724 |
return NS_ERROR_NOT_IMPLEMENTED; |
725 |
} |
726 |
#endif |
727 |
|
728 |
#if defined(MOZ_ENABLE_FREETYPE2) || defined(MOZ_ENABLE_XFT) |
729 |
|
730 |
#define WIDEN_8_TO_16_BUF_SIZE 1024 |
731 |
|
732 |
#ifdef MOZ_ENABLE_XFT |
733 |
|
734 |
nsXftEntry::nsXftEntry(FcPattern *aFontPattern) |
735 |
{ |
736 |
mFace = nsnull; |
737 |
mFaceIndex = 0; |
738 |
|
739 |
char *fcResult; |
740 |
|
741 |
if (FcPatternGetString(aFontPattern, FC_FILE, 0, (FcChar8 **) &fcResult) |
742 |
== FcResultMatch) |
743 |
mFontFileName = fcResult; |
744 |
|
745 |
if (FcPatternGetString(aFontPattern, FC_FAMILY, 0, (FcChar8 **) &fcResult) |
746 |
== FcResultMatch) |
747 |
mFamilyName = fcResult; |
748 |
|
749 |
if (FcPatternGetString(aFontPattern, FC_STYLE, 0, (FcChar8 **) &fcResult) |
750 |
== FcResultMatch) |
751 |
mStyleName = fcResult; |
752 |
} |
753 |
|
754 |
|
755 |
static nsFontPS* |
756 |
CreateFontPS(nsXftEntry *aEntry, const nsFont& aFont, |
757 |
nsFontMetricsPS* aFontMetrics) |
758 |
{ |
759 |
nsresult rv; |
760 |
nsDeviceContextPS* dc = aFontMetrics->GetDeviceContext(); |
761 |
NS_ENSURE_TRUE(dc, nsnull); |
762 |
|
763 |
nsCAutoString fileName(aEntry->mFontFileName); |
764 |
nsCAutoString familyName(aEntry->mFamilyName); |
765 |
nsCAutoString styleName(aEntry->mStyleName); |
766 |
ToLowerCase(familyName); |
767 |
ToLowerCase(styleName); |
768 |
|
769 |
nsCAutoString fontName; |
770 |
fontName.Append(familyName); |
771 |
fontName.Append("-"); |
772 |
fontName.Append(styleName); |
773 |
nsCStringKey key(fontName); |
774 |
|
775 |
nsHashtable *psFGList = dc->GetPSFontGeneratorList(); |
776 |
NS_ENSURE_TRUE(psFGList, nsnull); |
777 |
|
778 |
nsPSFontGenerator* psFontGen = (nsPSFontGenerator*) psFGList->Get(&key); |
779 |
if (!psFontGen) { |
780 |
psFontGen = new nsXftType8Generator; |
781 |
NS_ENSURE_TRUE(psFontGen, nsnull); |
782 |
rv = ((nsXftType8Generator*)psFontGen)->Init(aEntry); |
783 |
if (NS_FAILED(rv)) { |
784 |
delete psFontGen; |
785 |
return nsnull; |
786 |
} |
787 |
psFGList->Put(&key, (void *) psFontGen); |
788 |
} |
789 |
nsFontPSXft* font = new nsFontPSXft(aFont, aFontMetrics); |
790 |
NS_ENSURE_TRUE(font, nsnull); |
791 |
rv = font->Init(aEntry, psFontGen); |
792 |
if (NS_FAILED(rv)) { |
793 |
delete font; |
794 |
return nsnull; |
795 |
} |
796 |
return font; |
797 |
} |
798 |
|
799 |
/* static */ |
800 |
PRBool |
801 |
nsFontPSXft::CSSFontEnumCallback(const nsString& aFamily, PRBool aIsGeneric, |
802 |
void* aFpi) |
803 |
{ |
804 |
fontPSInfo *fpi = (fontPSInfo *)aFpi; |
805 |
|
806 |
// make sure it's an ascii name, if not then return and continue |
807 |
// enumerating |
808 |
if (!NS_IsASCIIFontName(aFamily)) |
809 |
return PR_TRUE; |
810 |
|
811 |
NS_LossyConvertUTF16toASCII name(aFamily); |
812 |
ToLowerCase(name); |
813 |
fpi->mFontList.AppendCString(name); |
814 |
fpi->mFontIsGeneric.AppendElement((void *)aIsGeneric); |
815 |
if (aIsGeneric) { |
816 |
fpi->mGenericFont = |
817 |
fpi->mFontList.CStringAt(fpi->mFontList.Count() - 1); |
818 |
return PR_FALSE; // stop processing |
819 |
} |
820 |
|
821 |
return PR_TRUE; // keep processing |
822 |
} |
823 |
|
824 |
nsFontPS* |
825 |
nsFontPSXft::FindFont(PRUnichar aChar, const nsFont& aFont, |
826 |
nsFontMetricsPS* aFontMetrics) |
827 |
{ |
828 |
PRBool inited = PR_FALSE; |
829 |
nsCOMPtr<nsIAtom> langGroup; |
830 |
fontPSInfo fpi; |
831 |
fpi.fontps = aFontMetrics->GetFontsPS(); |
832 |
int i = 0; |
833 |
|
834 |
while (1) { |
835 |
// |
836 |
// see if it is already in the list of fonts |
837 |
// |
838 |
for (; i<fpi.fontps->Count(); i++) { |
839 |
fontps *fi = (fontps *)fpi.fontps->ElementAt(i); |
840 |
if (!fi->entry || !fi->charset) { |
841 |
NS_ASSERTION(fi->entry, "invalid entry"); |
842 |
NS_ASSERTION(fi->charset, "invalid charset"); |
843 |
continue; |
844 |
} |
845 |
if (FcCharSetHasChar(fi->charset, aChar)) { |
846 |
if (!fi->fontps) { |
847 |
#ifdef PR_LOGGING |
848 |
if (PR_LOG_TEST(gFontMetricsPSM, PR_LOG_DEBUG)) { |
849 |
PR_LogPrint("CreateFontPS %s/%s\n", |
850 |
fi->entry->mFamilyName.get(), fi->entry->mStyleName.get()); |
851 |
} |
852 |
#endif |
853 |
fi->fontps = CreateFontPS(fi->entry, aFont, aFontMetrics); |
854 |
} |
855 |
if (fi->fontps) |
856 |
return fi->fontps; |
857 |
} |
858 |
} |
859 |
|
860 |
// if already get all matched fonts and not found suitable |
861 |
// then return nsnull |
862 |
if (fpi.fontps->Count() > 0) |
863 |
return nsnull; |
864 |
|
865 |
// |
866 |
// it is not already in the list of fonts |
867 |
// so add more fonts to the list |
868 |
// |
869 |
if (inited) |
870 |
return nsnull; |
871 |
|
872 |
inited = PR_TRUE; |
873 |
|
874 |
fpi.nsfont = &aFont; |
875 |
fpi.alreadyLoaded = aFontMetrics->GetFontsAlreadyLoadedList(); |
876 |
fpi.mGenericFont = nsnull; |
877 |
|
878 |
aFontMetrics->GetLangGroup(getter_AddRefs(langGroup)); |
879 |
if (!langGroup) |
880 |
langGroup = NS_NewAtom("x-western"); |
881 |
|
882 |
// enumerate over the font names passed in |
883 |
aFont.EnumerateFamilies(nsFontPSXft::CSSFontEnumCallback, &fpi); |
884 |
|
885 |
nsCOMPtr<nsIPref> prefService; |
886 |
prefService = do_GetService(NS_PREF_CONTRACTID); |
887 |
if (!prefService) |
888 |
return nsnull; |
889 |
|
890 |
nsXPIDLCString value; |
891 |
nsCAutoString aDefaultFont; |
892 |
|
893 |
// Set up the default font name if it's not set |
894 |
if (!fpi.mGenericFont) { |
895 |
prefService->CopyCharPref("font.default", getter_Copies(value)); |
896 |
|
897 |
if (value.get()) |
898 |
aDefaultFont = value.get(); |
899 |
else |
900 |
aDefaultFont = "serif"; |
901 |
|
902 |
fpi.mGenericFont = &aDefaultFont; |
903 |
} |
904 |
|
905 |
// If pattern is null, set up the base bits of it so we can |
906 |
// match. If we need to match later we don't have to set it up |
907 |
// again. |
908 |
FcPattern *pattern = nsnull; |
909 |
|
910 |
pattern = FcPatternCreate(); |
911 |
if (!pattern) |
912 |
return nsnull; |
913 |
|
914 |
// XXX need to add user defined family |
915 |
|
916 |
// Add CSS names - walk the list of fonts, adding the generic as |
917 |
// the last font |
918 |
for (int i=0; i < fpi.mFontList.Count(); ++i) { |
919 |
// if this was a generic name, break out of the loop since we |
920 |
// don't want to add it to the pattern yet |
921 |
if (fpi.mFontIsGeneric[i]) |
922 |
break;; |
923 |
|
924 |
nsCString *familyName = fpi.mFontList.CStringAt(i); |
925 |
NS_AddFFRE(pattern, familyName, PR_FALSE); |
926 |
} |
927 |
|
928 |
// Add the language group. Note that we do this before adding any |
929 |
// generics. That's because the language is more important than |
930 |
// any generic font. |
931 |
NS_AddLangGroup(pattern, langGroup); |
932 |
|
933 |
// If there's a generic add a pref for the generic if there's one |
934 |
// set. |
935 |
if (fpi.mGenericFont && !aFont.systemFont) { |
936 |
nsCAutoString name("font.name."); |
937 |
name += fpi.mGenericFont->get(); |
938 |
name += "."; |
939 |
|
940 |
nsAutoString langGroupStr; |
941 |
langGroup->ToString(langGroupStr); |
942 |
|
943 |
LossyAppendUTF16toASCII(langGroupStr, name); |
944 |
|
945 |
nsCOMPtr<nsIPref> pref; |
946 |
pref = do_GetService(NS_PREF_CONTRACTID); |
947 |
if (pref) { |
948 |
nsresult rv; |
949 |
nsXPIDLCString value; |
950 |
rv = pref->GetCharPref(name.get(), getter_Copies(value)); |
951 |
|
952 |
// we ignore prefs that have three hypens since they are X |
953 |
// style prefs. |
954 |
if (NS_FFRECountHyphens(value) < 3) { |
955 |
nsCAutoString tmpstr(value); |
956 |
|
957 |
if (PR_LOG_TEST(gFontMetricsPSM, PR_LOG_DEBUG)) { |
958 |
printf("\tadding generic font from preferences: %s\n", |
959 |
tmpstr.get()); |
960 |
} |
961 |
|
962 |
NS_AddFFRE(pattern, &tmpstr, PR_FALSE); |
963 |
} |
964 |
} |
965 |
} |
966 |
|
967 |
// Add the generic if there is one. |
968 |
if (fpi.mGenericFont && !aFont.systemFont) |
969 |
NS_AddFFRE(pattern, fpi.mGenericFont, PR_FALSE); |
970 |
|
971 |
// Add the slant type |
972 |
FcPatternAddInteger(pattern, FC_SLANT, NS_CalculateSlant(aFont.style)); |
973 |
|
974 |
// Add the weight |
975 |
FcPatternAddInteger(pattern, FC_WEIGHT, NS_CalculateWeight(aFont.weight)); |
976 |
|
977 |
// Set up the default substitutions for this font |
978 |
FcConfigSubstitute(0, pattern, FcMatchPattern); |
979 |
FcDefaultSubstitute(pattern); |
980 |
|
981 |
FcResult result; |
982 |
FcFontSet *set = FcFontSort(0, pattern, FcTrue, 0, &result); |
983 |
if (!set) { |
984 |
return nsnull; |
985 |
} |
986 |
|
987 |
// Create a list of new font objects based on the fonts returned |
988 |
// as part of the query |
989 |
for (int i=0; i < set->nfont; ++i) { |
990 |
FcBool fc_outline; |
991 |
FcChar8 *fc_family; |
992 |
FcChar8 *fc_style; |
993 |
FcCharSet *fc_charset; |
994 |
|
995 |
// skip if the fonts is not outline font files. |
996 |
result = FcPatternGetBool (set->fonts[i], FC_OUTLINE, 0, &fc_outline); |
997 |
if (!fc_outline) |
998 |
continue; |
999 |
|
1000 |
result = FcPatternGetString (set->fonts[i], FC_FAMILY, 0, &fc_family); |
1001 |
if (result != FcResultMatch || fc_family == nsnull) |
1002 |
continue; |
1003 |
|
1004 |
result = FcPatternGetString (set->fonts[i], FC_STYLE, 0, &fc_style); |
1005 |
if (result != FcResultMatch || fc_style == nsnull) |
1006 |
continue; |
1007 |
|
1008 |
result = FcPatternGetCharSet(set->fonts[i], FC_CHARSET, 0, &fc_charset); |
1009 |
if (result != FcResultMatch || fc_charset == nsnull) |
1010 |
continue; |
1011 |
|
1012 |
nsXftEntry *xftEntry = new nsXftEntry(set->fonts[i]); |
1013 |
if (!xftEntry) |
1014 |
continue; |
1015 |
|
1016 |
fontps *fps = new fontps; |
1017 |
fps->entry = xftEntry; |
1018 |
fps->charset = fc_charset; |
1019 |
fps->fontps = nsnull; |
1020 |
fpi.fontps->AppendElement(fps); |
1021 |
} |
1022 |
|
1023 |
// we're done with the set now |
1024 |
FcFontSetDestroy(set); |
1025 |
|
1026 |
FcPatternDestroy(pattern); |
1027 |
} |
1028 |
|
1029 |
return nsnull; |
1030 |
} |
1031 |
|
1032 |
/*FT_CALLBACK_DEF*/ |
1033 |
FT_Error |
1034 |
nsXftFaceRequester(FTC_FaceID face_id, FT_Library lib, |
1035 |
FT_Pointer request_data, FT_Face* aFace) |
1036 |
{ |
1037 |
nsXftEntry *faceID = (nsXftEntry *)face_id; |
1038 |
|
1039 |
FT_Error fterror = FT_New_Face(lib, faceID->mFontFileName.get(), |
1040 |
faceID->mFaceIndex, aFace); |
1041 |
if (fterror) |
1042 |
*aFace = nsnull; |
1043 |
return 0; |
1044 |
} |
1045 |
|
1046 |
nsFontPSXft::nsFontPSXft(const nsFont& aFont, |
1047 |
nsFontMetricsPS* aFontMetrics) |
1048 |
:nsFontPS(aFont, aFontMetrics) |
1049 |
{ |
1050 |
} |
1051 |
|
1052 |
nsresult |
1053 |
nsFontPSXft::Init(nsXftEntry* aEntry, |
1054 |
nsPSFontGenerator* aPSFontGen) |
1055 |
{ |
1056 |
NS_ENSURE_TRUE(aEntry && aPSFontGen, NS_ERROR_FAILURE); |
1057 |
mEntry = aEntry; |
1058 |
mPSFontGenerator = aPSFontGen; |
1059 |
|
1060 |
float app2dev; |
1061 |
nsIDeviceContext* dc = mFontMetrics->GetDeviceContext(); |
1062 |
NS_ENSURE_TRUE(dc, NS_ERROR_NULL_POINTER); |
1063 |
app2dev = dc->AppUnitsToDevUnits(); |
1064 |
|
1065 |
mPixelSize = NSToIntRound(app2dev * mFont->size); |
1066 |
|
1067 |
mImageDesc.font.face_id = (void*)mEntry; |
1068 |
mImageDesc.font.pix_width = mPixelSize; |
1069 |
mImageDesc.font.pix_height = mPixelSize; |
1070 |
mImageDesc.image_type = 0; |
1071 |
|
1072 |
FT_Error fterror; |
1073 |
fterror = FT_Init_FreeType(&mFreeTypeLibrary); |
1074 |
if (fterror) { |
1075 |
NS_ASSERTION(!fterror, "failed to initialize FreeType library"); |
1076 |
mFreeTypeLibrary = nsnull; |
1077 |
return NS_ERROR_FAILURE; |
1078 |
} |
1079 |
fterror = FTC_Manager_New(mFreeTypeLibrary, 0, 0, 0, nsXftFaceRequester, |
1080 |
NULL, &mFTCacheManager); |
1081 |
NS_ASSERTION(!fterror, "failed to create FreeType Cache manager"); |
1082 |
if (fterror) |
1083 |
return NS_ERROR_FAILURE; |
1084 |
|
1085 |
fterror = FTC_Image_Cache_New(mFTCacheManager, &mImageCache); |
1086 |
NS_ASSERTION(!fterror, "failed to create FreeType image cache"); |
1087 |
if (fterror) |
1088 |
return NS_ERROR_FAILURE; |
1089 |
|
1090 |
return NS_OK; |
1091 |
} |
1092 |
|
1093 |
nsFontPSXft::~nsFontPSXft() |
1094 |
{ |
1095 |
FTC_Manager_Done(mFTCacheManager); |
1096 |
|
1097 |
if (FT_Done_FreeType(mFreeTypeLibrary)) |
1098 |
return; |
1099 |
|
1100 |
mEntry = nsnull; |
1101 |
} |
1102 |
|
1103 |
FT_Face |
1104 |
nsFontPSXft::getFTFace() |
1105 |
{ |
1106 |
FT_Error error; |
1107 |
FT_Face face = mEntry->mFace; |
1108 |
|
1109 |
if (face) |
1110 |
return (face); |
1111 |
|
1112 |
error = FTC_Manager_Lookup_Size(mFTCacheManager, &mImageDesc.font, |
1113 |
&face, nsnull); |
1114 |
NS_ASSERTION(error == 0, "failed to get face/size"); |
1115 |
if (error) |
1116 |
return nsnull; |
1117 |
|
1118 |
mEntry->mFace = face; |
1119 |
return face; |
1120 |
} |
1121 |
|
1122 |
nscoord |
1123 |
nsFontPSXft::GetWidth(const char* aString, PRUint32 aLength) |
1124 |
{ |
1125 |
PRUnichar unichars[WIDEN_8_TO_16_BUF_SIZE]; |
1126 |
PRUint32 len, width = 0; |
1127 |
while ( aLength > 0 ) { |
1128 |
len = PR_MIN(aLength, WIDEN_8_TO_16_BUF_SIZE); |
1129 |
for (PRUint32 i=0; i < len; i++) { |
1130 |
unichars[i] = PRUnichar(PRUint8(aString[i])); |
1131 |
} |
1132 |
width += GetWidth(unichars, len); |
1133 |
aString += len; |
1134 |
aLength -= len; |
1135 |
} |
1136 |
return width; |
1137 |
} |
1138 |
|
1139 |
|
1140 |
nscoord |
1141 |
nsFontPSXft::GetWidth(const PRUnichar* aString, PRUint32 aLength) |
1142 |
{ |
1143 |
FT_UInt glyph_index; |
1144 |
FT_Glyph glyph; |
1145 |
double origin_x = 0; |
1146 |
|
1147 |
// get the face/size from the FreeType cache |
1148 |
FT_Face face = getFTFace(); |
1149 |
NS_ASSERTION(face, "failed to get face/size"); |
1150 |
if (!face) |
1151 |
return 0; |
1152 |
|
1153 |
for (PRUint32 i=0; i<aLength; i++) { |
1154 |
glyph_index = FT_Get_Char_Index((FT_Face)face, aString[i]); |
1155 |
FT_Error error = FTC_Image_Cache_Lookup(mImageCache, &mImageDesc, |
1156 |
glyph_index, &glyph); |
1157 |
if (error) { |
1158 |
origin_x += FT_REG_TO_16_16(face->size->metrics.x_ppem/2 + 2); |
1159 |
continue; |
1160 |
} |
1161 |
origin_x += glyph->advance.x; |
1162 |
} |
1163 |
|
1164 |
NS_ENSURE_TRUE(mFontMetrics, 0); |
1165 |
|
1166 |
nsDeviceContextPS* dc = mFontMetrics->GetDeviceContext(); |
1167 |
NS_ENSURE_TRUE(dc, 0); |
1168 |
|
1169 |
float dev2app; |
1170 |
dev2app = dc->DevUnitsToAppUnits(); |
1171 |
origin_x *= dev2app; |
1172 |
origin_x /= FT_REG_TO_16_16(1); |
1173 |
|
1174 |
return NSToCoordRound((nscoord)origin_x); |
1175 |
} |
1176 |
|
1177 |
nscoord |
1178 |
nsFontPSXft::DrawString(nsRenderingContextPS* aContext, |
1179 |
nscoord aX, nscoord aY, |
1180 |
const char* aString, PRUint32 aLength) |
1181 |
{ |
1182 |
NS_ENSURE_TRUE(aContext, 0); |
1183 |
nsPostScriptObj* psObj = aContext->GetPostScriptObj(); |
1184 |
NS_ENSURE_TRUE(psObj, 0); |
1185 |
nscoord width = 0; |
1186 |
|
1187 |
psObj->moveto(aX, aY); |
1188 |
|
1189 |
PRUnichar unichars[WIDEN_8_TO_16_BUF_SIZE]; |
1190 |
PRUint32 len; |
1191 |
|
1192 |
while ( aLength > 0 ) { |
1193 |
len = PR_MIN(aLength, WIDEN_8_TO_16_BUF_SIZE); |
1194 |
for (PRUint32 i=0; i < len; i++) { |
1195 |
unichars[i] = PRUnichar(PRUint8(aString[i])); |
1196 |
} |
1197 |
psObj->show(unichars, len, "", 1); |
1198 |
mPSFontGenerator->AddToSubset(unichars, len); |
1199 |
width += GetWidth(unichars, len); |
1200 |
aString += len; |
1201 |
aLength -= len; |
1202 |
} |
1203 |
return width; |
1204 |
} |
1205 |
|
1206 |
nscoord |
1207 |
nsFontPSXft::DrawString(nsRenderingContextPS* aContext, |
1208 |
nscoord aX, nscoord aY, |
1209 |
const PRUnichar* aString, PRUint32 aLength) |
1210 |
{ |
1211 |
NS_ENSURE_TRUE(aContext, 0); |
1212 |
nsPostScriptObj* psObj = aContext->GetPostScriptObj(); |
1213 |
NS_ENSURE_TRUE(psObj, 0); |
1214 |
|
1215 |
psObj->moveto(aX, aY); |
1216 |
psObj->show(aString, aLength, "", 1); |
1217 |
|
1218 |
mPSFontGenerator->AddToSubset(aString, aLength); |
1219 |
return GetWidth(aString, aLength); |
1220 |
} |
1221 |
|
1222 |
int |
1223 |
nsFontPSXft::ascent() |
1224 |
{ |
1225 |
FT_Face face = getFTFace(); |
1226 |
NS_ASSERTION(face, "failed to get face/size"); |
1227 |
NS_ENSURE_TRUE(face, 0); |
1228 |
return FT_DESIGN_UNITS_TO_PIXELS(face->ascender, face->size->metrics.y_scale); |
1229 |
} |
1230 |
|
1231 |
int |
1232 |
nsFontPSXft::descent() |
1233 |
{ |
1234 |
FT_Face face = getFTFace(); |
1235 |
NS_ASSERTION(face, "failed to get face/size"); |
1236 |
NS_ENSURE_TRUE(face, 0); |
1237 |
return FT_DESIGN_UNITS_TO_PIXELS(-face->descender, face->size->metrics.y_scale); |
1238 |
} |
1239 |
|
1240 |
int |
1241 |
nsFontPSXft::max_ascent() |
1242 |
{ |
1243 |
FT_Face face = getFTFace(); |
1244 |
NS_ASSERTION(face, "failed to get face/size"); |
1245 |
NS_ENSURE_TRUE(face, 0); |
1246 |
TT_OS2 *tt_os2 = (TT_OS2 *) FT_Get_Sfnt_Table(face, ft_sfnt_os2); |
1247 |
NS_ASSERTION(tt_os2, "unable to get OS2 table"); |
1248 |
if (tt_os2) |
1249 |
return FT_DESIGN_UNITS_TO_PIXELS(tt_os2->sTypoAscender, |
1250 |
face->size->metrics.y_scale); |
1251 |
else |
1252 |
return FT_DESIGN_UNITS_TO_PIXELS(face->bbox.yMax, |
1253 |
face->size->metrics.y_scale); |
1254 |
} |
1255 |
|
1256 |
int |
1257 |
nsFontPSXft::max_descent() |
1258 |
{ |
1259 |
FT_Face face = getFTFace(); |
1260 |
NS_ASSERTION(face, "failed to get face/size"); |
1261 |
NS_ENSURE_TRUE(face, 0); |
1262 |
TT_OS2 *tt_os2 = (TT_OS2 *) FT_Get_Sfnt_Table(face, ft_sfnt_os2); |
1263 |
NS_ASSERTION(tt_os2, "unable to get OS2 table"); |
1264 |
if (tt_os2) |
1265 |
return FT_DESIGN_UNITS_TO_PIXELS(-tt_os2->sTypoDescender, |
1266 |
face->size->metrics.y_scale); |
1267 |
else |
1268 |
return FT_DESIGN_UNITS_TO_PIXELS(-face->bbox.yMin, |
1269 |
face->size->metrics.y_scale); |
1270 |
} |
1271 |
|
1272 |
int |
1273 |
nsFontPSXft::max_width() |
1274 |
{ |
1275 |
FT_Face face = getFTFace(); |
1276 |
NS_ASSERTION(face, "failed to get face/size"); |
1277 |
NS_ENSURE_TRUE(face, 0); |
1278 |
return FT_DESIGN_UNITS_TO_PIXELS(face->max_advance_width, |
1279 |
face->size->metrics.x_scale); |
1280 |
} |
1281 |
|
1282 |
PRBool |
1283 |
nsFontPSXft::getXHeight(unsigned long &aVal) |
1284 |
{ |
1285 |
FT_Face face = getFTFace(); |
1286 |
NS_ASSERTION(face, "failed to get face/size"); |
1287 |
if (!face || !aVal) |
1288 |
return PR_FALSE; |
1289 |
aVal = FT_DESIGN_UNITS_TO_PIXELS(face->height, face->size->metrics.y_scale); |
1290 |
|
1291 |
return PR_TRUE; |
1292 |
} |
1293 |
|
1294 |
PRBool |
1295 |
nsFontPSXft::underlinePosition(long &aVal) |
1296 |
{ |
1297 |
FT_Face face = getFTFace(); |
1298 |
NS_ASSERTION(face, "failed to get face/size"); |
1299 |
if (!face) |
1300 |
return PR_FALSE; |
1301 |
aVal = FT_DESIGN_UNITS_TO_PIXELS(-face->underline_position, |
1302 |
face->size->metrics.y_scale); |
1303 |
return PR_TRUE; |
570 |
} |
1304 |
} |
571 |
|
1305 |
|
572 |
nscoord |
1306 |
PRBool |
573 |
nsFontPSAFM::GetWidth(const PRUnichar* aString, PRUint32 aLength) |
1307 |
nsFontPSXft::underline_thickness(unsigned long &aVal) |
574 |
{ |
1308 |
{ |
575 |
nscoord width = 0; |
1309 |
FT_Face face = getFTFace(); |
576 |
if (mAFMInfo) { |
1310 |
NS_ASSERTION(face, "failed to get face/size"); |
577 |
mAFMInfo->GetStringWidth(aString, width, aLength); |
1311 |
if (!face) |
578 |
} |
1312 |
return PR_FALSE; |
579 |
return width; |
1313 |
aVal = FT_DESIGN_UNITS_TO_PIXELS(face->underline_thickness, |
|
|
1314 |
face->size->metrics.x_scale); |
1315 |
return PR_TRUE; |
580 |
} |
1316 |
} |
581 |
|
1317 |
|
582 |
nscoord |
1318 |
PRBool |
583 |
nsFontPSAFM::DrawString(nsRenderingContextPS* aContext, |
1319 |
nsFontPSXft::superscript_y(long &aVal) |
584 |
nscoord aX, nscoord aY, |
|
|
585 |
const char* aString, PRUint32 aLength) |
586 |
{ |
1320 |
{ |
587 |
NS_ENSURE_TRUE(aContext, 0); |
1321 |
aVal = 0; |
588 |
nsPostScriptObj* psObj = aContext->GetPostScriptObj(); |
1322 |
FT_Face face = getFTFace(); |
589 |
NS_ENSURE_TRUE(psObj, 0); |
1323 |
NS_ASSERTION(face, "failed to get face/size"); |
|
|
1324 |
if (!face) |
1325 |
return PR_FALSE; |
590 |
|
1326 |
|
591 |
psObj->moveto(aX, aY); |
1327 |
TT_OS2 *tt_os2 = (TT_OS2 *) FT_Get_Sfnt_Table(face, ft_sfnt_os2); |
592 |
psObj->show(aString, aLength, ""); |
1328 |
NS_ASSERTION(tt_os2, "unable to get OS2 table"); |
593 |
return GetWidth(aString, aLength); |
1329 |
if (!tt_os2) |
|
|
1330 |
return PR_FALSE; |
1331 |
|
1332 |
aVal = FT_DESIGN_UNITS_TO_PIXELS(tt_os2->ySuperscriptYOffset, |
1333 |
face->size->metrics.y_scale); |
1334 |
return PR_TRUE; |
594 |
} |
1335 |
} |
595 |
|
1336 |
|
596 |
nscoord |
1337 |
PRBool |
597 |
nsFontPSAFM::DrawString(nsRenderingContextPS* aContext, |
1338 |
nsFontPSXft::subscript_y(long &aVal) |
598 |
nscoord aX, nscoord aY, |
|
|
599 |
const PRUnichar* aString, PRUint32 aLength) |
600 |
{ |
1339 |
{ |
601 |
NS_ENSURE_TRUE(aContext, 0); |
1340 |
aVal = 0; |
602 |
nsPostScriptObj* psObj = aContext->GetPostScriptObj(); |
1341 |
FT_Face face = getFTFace(); |
603 |
NS_ENSURE_TRUE(psObj, 0); |
1342 |
NS_ASSERTION(face, "failed to get face/size"); |
|
|
1343 |
if (!face) |
1344 |
return PR_FALSE; |
604 |
|
1345 |
|
605 |
psObj->moveto(aX, aY); |
1346 |
TT_OS2 *tt_os2 = (TT_OS2 *) FT_Get_Sfnt_Table(face, ft_sfnt_os2); |
606 |
psObj->show(aString, aLength, "", 0); |
1347 |
NS_ASSERTION(tt_os2, "unable to get OS2 table"); |
607 |
return GetWidth(aString, aLength); |
1348 |
if (!tt_os2) |
|
|
1349 |
return PR_FALSE; |
1350 |
|
1351 |
aVal = FT_DESIGN_UNITS_TO_PIXELS(tt_os2->ySubscriptYOffset, |
1352 |
face->size->metrics.y_scale); |
1353 |
|
1354 |
// some fonts have the sign wrong. it should be always positive. |
1355 |
aVal = (aVal < 0) ? -aVal : aVal; |
1356 |
return PR_TRUE; |
608 |
} |
1357 |
} |
609 |
|
1358 |
|
610 |
nsresult |
1359 |
nsresult |
611 |
nsFontPSAFM::RealizeFont(nsFontMetricsPS* aFontMetrics, float dev2app) |
1360 |
nsFontPSXft::RealizeFont(nsFontMetricsPS* aFontMetrics, float dev2app) |
612 |
{ |
1361 |
{ |
613 |
NS_ENSURE_ARG_POINTER(aFontMetrics); |
1362 |
|
614 |
|
1363 |
nscoord leading, emHeight, emAscent, emDescent; |
615 |
float fontSize; |
1364 |
nscoord maxHeight, maxAscent, maxDescent, maxAdvance; |
616 |
float offset; |
1365 |
nscoord xHeight, spaceWidth, aveCharWidth; |
|
|
1366 |
nscoord underlineOffset, underlineSize, superscriptOffset, subscriptOffset; |
1367 |
nscoord strikeoutOffset, strikeoutSize; |
617 |
|
1368 |
|
618 |
nscoord onePixel = NSToCoordRound(1 * dev2app); |
1369 |
int lineSpacing = ascent() + descent(); |
|
|
1370 |
if (lineSpacing > mPixelSize) { |
1371 |
leading = nscoord((lineSpacing - mPixelSize) * dev2app); |
1372 |
} |
1373 |
else { |
1374 |
leading = 0; |
1375 |
} |
1376 |
emHeight = PR_MAX(1, nscoord(mPixelSize * dev2app)); |
1377 |
emAscent = nscoord(ascent() * mPixelSize * dev2app / lineSpacing); |
1378 |
emDescent = emHeight - emAscent; |
619 |
|
1379 |
|
620 |
// convert the font size which is in twips to points |
1380 |
maxHeight = nscoord((max_ascent() + max_descent()) * dev2app); |
621 |
fontSize = mFont->size / TWIPS_PER_POINT_FLOAT; |
1381 |
maxAscent = nscoord(max_ascent() * dev2app) ; |
|
|
1382 |
maxDescent = nscoord(max_descent() * dev2app); |
1383 |
maxAdvance = nscoord(max_width() * dev2app); |
622 |
|
1384 |
|
623 |
offset = NSFloatPointsToTwips(fontSize * mAFMInfo->mPSFontInfo->mXHeight) / 1000.0f; |
1385 |
// 56% of ascent, best guess for non-true type |
624 |
nscoord xHeight = NSToCoordRound(offset); |
1386 |
xHeight = NSToCoordRound((float)ascent()* dev2app * 0.56f); |
625 |
aFontMetrics->SetXHeight(xHeight); |
|
|
626 |
aFontMetrics->SetSuperscriptOffset(xHeight); |
627 |
aFontMetrics->SetSubscriptOffset(xHeight); |
628 |
aFontMetrics->SetStrikeout((nscoord)(xHeight / 2), onePixel); |
629 |
|
1387 |
|
630 |
offset = NSFloatPointsToTwips(fontSize * mAFMInfo->mPSFontInfo->mUnderlinePosition) / 1000.0f; |
1388 |
PRUnichar space = (PRUnichar)' '; |
631 |
aFontMetrics->SetUnderline(NSToCoordRound(offset), onePixel); |
1389 |
spaceWidth = NSToCoordRound(GetWidth(&space, 1)); |
|
|
1390 |
PRUnichar averageX = (PRUnichar)'x'; |
1391 |
aveCharWidth = NSToCoordRound(GetWidth(&averageX, 1)); |
1392 |
|
1393 |
unsigned long pr = 0; |
1394 |
if (getXHeight(pr)) { |
1395 |
xHeight = (nscoord(pr * dev2app)); |
1396 |
} |
632 |
|
1397 |
|
633 |
nscoord size = NSToCoordRound(fontSize * dev2app); |
1398 |
float height; |
634 |
aFontMetrics->SetHeight(size); |
1399 |
long val; |
635 |
aFontMetrics->SetEmHeight(size); |
1400 |
|
636 |
aFontMetrics->SetMaxAdvance(size); |
1401 |
height = ascent() + descent(); |
637 |
aFontMetrics->SetMaxHeight(size); |
1402 |
underlineOffset = -NSToIntRound( |
|
|
1403 |
PR_MAX (1, floor (0.1 * height + 0.5)) * dev2app); |
638 |
|
1404 |
|
639 |
offset = NSFloatPointsToTwips(fontSize * mAFMInfo->mPSFontInfo->mAscender) / 1000.0f; |
1405 |
if (underline_thickness(pr)) { |
640 |
nscoord ascent = NSToCoordRound(offset); |
1406 |
/* this will only be provided from adobe .afm fonts */ |
641 |
aFontMetrics->SetAscent(ascent); |
1407 |
underlineSize = nscoord(PR_MAX(dev2app, NSToIntRound(pr * dev2app))); |
642 |
aFontMetrics->SetEmAscent(ascent); |
1408 |
} |
643 |
aFontMetrics->SetMaxAscent(ascent); |
1409 |
else { |
|
|
1410 |
height = ascent() + descent(); |
1411 |
underlineSize = NSToIntRound( |
1412 |
PR_MAX(1, floor (0.05 * height + 0.5)) * dev2app); |
1413 |
} |
644 |
|
1414 |
|
645 |
offset = NSFloatPointsToTwips(fontSize * mAFMInfo->mPSFontInfo->mDescender) / 1000.0f; |
1415 |
if (superscript_y(val)) { |
646 |
nscoord descent = -(NSToCoordRound(offset)); |
1416 |
superscriptOffset = nscoord(PR_MAX(dev2app, NSToIntRound(val * dev2app))); |
647 |
aFontMetrics->SetDescent(descent); |
1417 |
} |
648 |
aFontMetrics->SetEmDescent(descent); |
1418 |
else { |
649 |
aFontMetrics->SetMaxDescent(descent); |
1419 |
superscriptOffset = xHeight; |
|
|
1420 |
} |
650 |
|
1421 |
|
651 |
aFontMetrics->SetLeading(0); |
1422 |
if (subscript_y(val)) { |
|
|
1423 |
subscriptOffset = nscoord(PR_MAX(dev2app, NSToIntRound(val * dev2app))); |
1424 |
} |
1425 |
else { |
1426 |
subscriptOffset = xHeight; |
1427 |
} |
652 |
|
1428 |
|
653 |
nscoord spaceWidth = GetWidth(" ", 1); |
1429 |
/* need better way to calculate this */ |
|
|
1430 |
strikeoutOffset = NSToCoordRound(xHeight / 2.0); |
1431 |
strikeoutSize = underlineSize; |
1432 |
|
1433 |
// TODO: leading never used, does it equal to "Height"? |
1434 |
aFontMetrics->SetHeight(emHeight); |
1435 |
aFontMetrics->SetEmHeight(emHeight); |
1436 |
aFontMetrics->SetEmAscent(emAscent); |
1437 |
aFontMetrics->SetEmDescent(emDescent); |
1438 |
aFontMetrics->SetMaxHeight(maxHeight); |
1439 |
aFontMetrics->SetMaxAscent(maxAscent); |
1440 |
aFontMetrics->SetMaxDescent(maxDescent); |
1441 |
aFontMetrics->SetMaxAdvance(maxAdvance); |
1442 |
aFontMetrics->SetXHeight(xHeight); |
654 |
aFontMetrics->SetSpaceWidth(spaceWidth); |
1443 |
aFontMetrics->SetSpaceWidth(spaceWidth); |
655 |
|
|
|
656 |
nscoord aveCharWidth = GetWidth("x", 1); |
657 |
aFontMetrics->SetAveCharWidth(aveCharWidth); |
1444 |
aFontMetrics->SetAveCharWidth(aveCharWidth); |
|
|
1445 |
aFontMetrics->SetUnderline(underlineOffset, underlineSize); |
1446 |
aFontMetrics->SetSuperscriptOffset(superscriptOffset); |
1447 |
aFontMetrics->SetSubscriptOffset(subscriptOffset); |
1448 |
aFontMetrics->SetStrikeout(strikeoutOffset, strikeoutSize); |
658 |
|
1449 |
|
659 |
return NS_OK; |
1450 |
return NS_OK; |
660 |
} |
1451 |
} |
661 |
|
1452 |
|
662 |
nsresult |
1453 |
nsresult |
663 |
nsFontPSAFM::SetupFont(nsRenderingContextPS* aContext) |
1454 |
nsFontPSXft::SetupFont(nsRenderingContextPS* aContext) |
664 |
{ |
1455 |
{ |
665 |
NS_ENSURE_TRUE(aContext && mFontMetrics, 0); |
1456 |
NS_ENSURE_TRUE(aContext, NS_ERROR_FAILURE); |
666 |
nsPostScriptObj* psObj = aContext->GetPostScriptObj(); |
1457 |
nsPostScriptObj* psObj = aContext->GetPostScriptObj(); |
667 |
NS_ENSURE_TRUE(psObj, 0); |
1458 |
NS_ENSURE_TRUE(psObj, NS_ERROR_FAILURE); |
668 |
|
1459 |
|
669 |
nscoord fontHeight = 0; |
1460 |
nscoord fontHeight = 0; |
670 |
mFontMetrics->GetHeight(fontHeight); |
1461 |
mFontMetrics->GetHeight(fontHeight); |
671 |
|
1462 |
|
672 |
psObj->setscriptfont(mFontIndex, mFamilyName, |
1463 |
nsCString fontName; |
673 |
fontHeight, mFont->style, mFont->variant, |
1464 |
int wmode = 0; |
674 |
mFont->weight, mFont->decorations); |
1465 |
FT_Face face = getFTFace(); |
|
|
1466 |
NS_ENSURE_TRUE(face, NS_ERROR_NULL_POINTER); |
1467 |
char *cidFontName = FT2ToType8CidFontName(face, wmode); |
1468 |
NS_ENSURE_TRUE(cidFontName, NS_ERROR_FAILURE); |
1469 |
fontName.Assign(cidFontName); |
1470 |
psObj->setfont(fontName, fontHeight); |
1471 |
PR_Free(cidFontName); |
1472 |
|
675 |
return NS_OK; |
1473 |
return NS_OK; |
676 |
} |
1474 |
} |
677 |
|
1475 |
|
678 |
#ifdef MOZ_MATHML |
1476 |
#ifdef MOZ_MATHML |
679 |
nsresult |
1477 |
nsresult |
680 |
nsFontPSAFM::GetBoundingMetrics(const char* aString, |
1478 |
nsFontPSXft::GetBoundingMetrics(const char* aString, |
681 |
PRUint32 aLength, |
1479 |
PRUint32 aLength, |
682 |
nsBoundingMetrics& aBoundingMetrics) |
1480 |
nsBoundingMetrics& aBoundingMetrics) |
683 |
{ |
1481 |
{ |
684 |
return NS_ERROR_NOT_IMPLEMENTED; |
1482 |
return NS_ERROR_NOT_IMPLEMENTED; |
685 |
} |
1483 |
} |
686 |
|
1484 |
|
687 |
nsresult |
1485 |
nsresult |
688 |
nsFontPSAFM::GetBoundingMetrics(const PRUnichar* aString, |
1486 |
nsFontPSXft::GetBoundingMetrics(const PRUnichar* aString, |
689 |
PRUint32 aLength, |
1487 |
PRUint32 aLength, |
690 |
nsBoundingMetrics& aBoundingMetrics) |
1488 |
nsBoundingMetrics& aBoundingMetrics) |
691 |
{ |
1489 |
{ |
692 |
return NS_ERROR_NOT_IMPLEMENTED; |
1490 |
return NS_ERROR_NOT_IMPLEMENTED; |
693 |
} |
1491 |
} |
694 |
#endif |
1492 |
#endif //MOZ_MATHML |
695 |
|
|
|
696 |
#ifdef MOZ_ENABLE_FREETYPE2 |
697 |
|
1493 |
|
698 |
#define WIDEN_8_TO_16_BUF_SIZE 1024 |
1494 |
#else |
699 |
|
1495 |
|
700 |
PRBool |
1496 |
PRBool |
701 |
nsFontPSFreeType::CSSFontEnumCallback(const nsString& aFamily, PRBool aGeneric, |
1497 |
nsFontPSFreeType::CSSFontEnumCallback(const nsString& aFamily, PRBool aGeneric, |
702 |
void* aFpi) |
1498 |
void* aFpi) |
703 |
{ |
1499 |
{ |
704 |
fontPSInfo* fpi = (fontPSInfo*)aFpi; |
1500 |
fontPSInfo* fpi = (fontPSInfo*)aFpi; |
705 |
nsCAutoString familyname; |
1501 |
nsCAutoString familyname; |
Lines 709-723
nsFontPSFreeType::CSSFontEnumCallback(co
Link Here
|
709 |
return PR_TRUE; // keep trying |
1505 |
return PR_TRUE; // keep trying |
710 |
} |
1506 |
} |
711 |
nsXPIDLCString value; |
1507 |
nsXPIDLCString value; |
712 |
nsresult rv; |
1508 |
nsresult rv; |
713 |
nsCOMPtr<nsIPref> pref(do_GetService(NS_PREF_CONTRACTID, &rv)); |
1509 |
nsCOMPtr<nsIPref> pref(do_GetService(NS_PREF_CONTRACTID, &rv)); |
714 |
NS_ENSURE_SUCCESS(rv, PR_TRUE); // keep trying |
1510 |
NS_ENSURE_SUCCESS(rv, PR_TRUE); // keep trying |
715 |
nsCAutoString name("font.name."); |
1511 |
nsCAutoString name("font.name."); |
716 |
name.AppendWithConversion(aFamily.get()); |
1512 |
LossyAppendUTF16toASCII(aFamily, name); |
717 |
name.Append(char('.')); |
1513 |
name.Append(char('.')); |
718 |
name.Append(fpi->lang); |
1514 |
name.Append(fpi->lang); |
719 |
pref->CopyCharPref(name.get(), getter_Copies(value)); |
1515 |
pref->CopyCharPref(name.get(), getter_Copies(value)); |
720 |
if (!value.get()) |
1516 |
if (!value.get()) |
721 |
return PR_TRUE; // keep trying |
1517 |
return PR_TRUE; // keep trying |
722 |
// strip down to just the family name |
1518 |
// strip down to just the family name |
723 |
PRInt32 startFamily = value.FindChar('-') + 1; |
1519 |
PRInt32 startFamily = value.FindChar('-') + 1; |
Lines 730-744
nsFontPSFreeType::CSSFontEnumCallback(co
Link Here
|
730 |
else // FFRE |
1526 |
else // FFRE |
731 |
familyname.Append(Substring(value, startFamily, endFamily - startFamily)); |
1527 |
familyname.Append(Substring(value, startFamily, endFamily - startFamily)); |
732 |
} |
1528 |
} |
733 |
PR_LOG(gFontMetricsPSM, PR_LOG_DEBUG, |
1529 |
PR_LOG(gFontMetricsPSM, PR_LOG_DEBUG, |
734 |
("generic font \"%s\" -> \"%s\"\n", name.get(), familyname.get())); |
1530 |
("generic font \"%s\" -> \"%s\"\n", name.get(), familyname.get())); |
735 |
} |
1531 |
} |
736 |
else |
1532 |
else |
737 |
familyname.AppendWithConversion(aFamily); |
1533 |
LossyAppendUTF16toASCII(aFamily, familyname); |
738 |
|
1534 |
|
739 |
AddFontEntries(familyname, fpi->lang, fpi->weight, |
1535 |
AddFontEntries(familyname, fpi->lang, fpi->weight, |
740 |
nsIFontCatalogService::kFCWidthAny, fpi->slant, |
1536 |
nsIFontCatalogService::kFCWidthAny, fpi->slant, |
741 |
nsIFontCatalogService::kFCSpacingAny, fpi); |
1537 |
nsIFontCatalogService::kFCSpacingAny, fpi); |
742 |
|
1538 |
|
743 |
return PR_TRUE; |
1539 |
return PR_TRUE; |
744 |
} |
1540 |
} |
Lines 1556-1569
nsFontPSFreeType::GetBoundingMetrics(con
Link Here
|
1556 |
nsBoundingMetrics& aBoundingMetrics) |
2352 |
nsBoundingMetrics& aBoundingMetrics) |
1557 |
{ |
2353 |
{ |
1558 |
return NS_ERROR_NOT_IMPLEMENTED; |
2354 |
return NS_ERROR_NOT_IMPLEMENTED; |
1559 |
} |
2355 |
} |
1560 |
#endif //MOZ_MATHML |
2356 |
#endif //MOZ_MATHML |
1561 |
|
2357 |
|
1562 |
#endif //MOZ_ENABLE_FREETYPE2 |
2358 |
#endif //MOZ_ENABLE_FREETYPE2 |
|
|
2359 |
#endif //MOZ_ENABLE_XFT |
1563 |
|
2360 |
|
1564 |
// Implementation of nsPSFontGenerator |
2361 |
// Implementation of nsPSFontGenerator |
1565 |
nsPSFontGenerator::nsPSFontGenerator() |
2362 |
nsPSFontGenerator::nsPSFontGenerator() |
1566 |
{ |
2363 |
{ |
1567 |
} |
2364 |
} |
1568 |
|
2365 |
|
1569 |
nsPSFontGenerator::~nsPSFontGenerator() |
2366 |
nsPSFontGenerator::~nsPSFontGenerator() |
Lines 1589-1603
void nsPSFontGenerator::AddToSubset(cons
Link Here
|
1589 |
for (PRUint32 i=0; i < aLength; i++) { |
2386 |
for (PRUint32 i=0; i < aLength; i++) { |
1590 |
unichar = (PRUnichar)((unsigned char)aString[i]); |
2387 |
unichar = (PRUnichar)((unsigned char)aString[i]); |
1591 |
if (mSubset.FindChar(unichar) == -1 ) |
2388 |
if (mSubset.FindChar(unichar) == -1 ) |
1592 |
mSubset.Append(unichar); |
2389 |
mSubset.Append(unichar); |
1593 |
} |
2390 |
} |
1594 |
} |
2391 |
} |
1595 |
|
2392 |
|
|
|
2393 |
#ifdef MOZ_ENABLE_XFT |
2394 |
nsXftType8Generator::nsXftType8Generator() |
2395 |
{ |
2396 |
} |
2397 |
|
2398 |
nsresult |
2399 |
nsXftType8Generator::Init(nsXftEntry* aEntry) |
2400 |
{ |
2401 |
NS_ENSURE_TRUE(aEntry, NS_ERROR_FAILURE); |
2402 |
mEntry = aEntry; |
2403 |
|
2404 |
FT_Error error = FT_Init_FreeType(&mFreeTypeLibrary); |
2405 |
NS_ASSERTION(!error, "failed to initialize FreeType library"); |
2406 |
if (error) { |
2407 |
mFreeTypeLibrary = nsnull; |
2408 |
return NS_ERROR_FAILURE; |
2409 |
} |
2410 |
error = FTC_Manager_New(mFreeTypeLibrary, 0, 0, 0, nsXftFaceRequester, |
2411 |
NULL, &mFTCacheManager); |
2412 |
NS_ASSERTION(!error, "failed to create FreeType Cache manager"); |
2413 |
if (error) |
2414 |
return NS_ERROR_FAILURE; |
2415 |
|
2416 |
return NS_OK; |
2417 |
} |
2418 |
|
2419 |
nsXftType8Generator::~nsXftType8Generator() |
2420 |
{ |
2421 |
FTC_Manager_Done(mFTCacheManager); |
2422 |
|
2423 |
if (FT_Done_FreeType(mFreeTypeLibrary)) |
2424 |
return; |
2425 |
|
2426 |
mEntry = nsnull; |
2427 |
} |
2428 |
|
2429 |
void nsXftType8Generator::GeneratePSFont(FILE* aFile) |
2430 |
{ |
2431 |
FT_Error error; |
2432 |
FT_Face face = mEntry->mFace; |
2433 |
|
2434 |
if (face == nsnull) { |
2435 |
mImageDesc.font.face_id = (void*)mEntry; |
2436 |
mImageDesc.font.pix_width = 16; |
2437 |
mImageDesc.font.pix_height = 16; |
2438 |
mImageDesc.image_type = 0; |
2439 |
error = FTC_Manager_Lookup_Size(mFTCacheManager, &mImageDesc.font, |
2440 |
&face, nsnull); |
2441 |
if (error) |
2442 |
return; |
2443 |
} |
2444 |
|
2445 |
if (face == nsnull) |
2446 |
return; |
2447 |
|
2448 |
int wmode = 0; |
2449 |
if (!mSubset.IsEmpty()) |
2450 |
FT2SubsetToType8(face, mSubset.get(), mSubset.Length(), wmode, aFile); |
2451 |
} |
2452 |
|
2453 |
#else |
1596 |
#ifdef MOZ_ENABLE_FREETYPE2 |
2454 |
#ifdef MOZ_ENABLE_FREETYPE2 |
|
|
2455 |
|
1597 |
nsFT2Type8Generator::nsFT2Type8Generator() |
2456 |
nsFT2Type8Generator::nsFT2Type8Generator() |
1598 |
{ |
2457 |
{ |
1599 |
} |
2458 |
} |
1600 |
|
2459 |
|
1601 |
nsresult |
2460 |
nsresult |
1602 |
nsFT2Type8Generator::Init(nsITrueTypeFontCatalogEntry* aEntry) |
2461 |
nsFT2Type8Generator::Init(nsITrueTypeFontCatalogEntry* aEntry) |
1603 |
{ |
2462 |
{ |
Lines 1635-1643
void nsFT2Type8Generator::GeneratePSFont
Link Here
|
1635 |
if (NS_FAILED(rv)) |
2494 |
if (NS_FAILED(rv)) |
1636 |
return; |
2495 |
return; |
1637 |
|
2496 |
|
1638 |
int wmode = 0; |
2497 |
int wmode = 0; |
1639 |
if (!mSubset.IsEmpty()) |
2498 |
if (!mSubset.IsEmpty()) |
1640 |
FT2SubsetToType8(face, mSubset.get(), mSubset.Length(), wmode, aFile); |
2499 |
FT2SubsetToType8(face, mSubset.get(), mSubset.Length(), wmode, aFile); |
1641 |
} |
2500 |
} |
1642 |
#endif //MOZ_ENABLE_FREETYPE2 |
|
|
1643 |
|
2501 |
|
|
|
2502 |
#endif //MOZ_ENABLE_FREETYPE2 |
2503 |
#endif //MOZ_ENABLE_XFT |