Commit bf7e0e98 authored by Albert Astals Cid's avatar Albert Astals Cid

Merge xpdf302branch in HEAD as noone vetoed it.

Testing more than welcome
parent ba74bb3b
2007-04-25 Albert Astals Cid <aacid@kde.org>
* ChangeLog:
* configure.ac:
* fofi/FoFiTrueType.cc:
* fofi/FoFiTrueType.h:
* fofi/FoFiType1.cc:
* fofi/FoFiType1C.cc:
* fofi/FoFiType1C.h:
* glib/poppler-action.cc:
* glib/poppler-document.cc:
* glib/poppler-page.cc:
* goo/FixedPoint.cc:
* goo/FixedPoint.h:
* goo/GooString.cc:
* goo/GooString.h:
* goo/Makefile.am:
* goo/gfile.cc:
* goo/gmem.cc:
* goo/gmem.h:
* poppler/ABWOutputDev.cc:
* poppler/ABWOutputDev.h:
* poppler/Annot.cc:
* poppler/Annot.h:
* poppler/ArthurOutputDev.cc:
* poppler/Catalog.cc:
* poppler/Catalog.h:
* poppler/CharCodeToUnicode.cc:
* poppler/DCTStream.cc:
* poppler/DCTStream.h:
* poppler/Decrypt.cc:
* poppler/Decrypt.h:
* poppler/Dict.cc:
* poppler/Dict.h:
* poppler/FontInfo.cc:
* poppler/Form.cc:
* poppler/Form.h:
* poppler/Function.cc:
* poppler/Function.h:
* poppler/Gfx.cc:
* poppler/Gfx.h:
* poppler/GfxFont.cc:
* poppler/GfxFont.h:
* poppler/GfxState.cc:
* poppler/GfxState.h:
* poppler/GlobalParams.cc:
* poppler/GlobalParams.h:
* poppler/JBIG2Stream.cc:
* poppler/JBIG2Stream.h:
* poppler/JPXStream.cc:
* poppler/JPXStream.h:
* poppler/Lexer.cc:
* poppler/Link.cc:
* poppler/Link.h:
* poppler/Makefile.am:
* poppler/Object.cc:
* poppler/Object.h:
* poppler/Outline.cc:
* poppler/OutputDev.cc:
* poppler/OutputDev.h:
* poppler/PDFDoc.cc:
* poppler/PDFDoc.h:
* poppler/PSOutputDev.cc:
* poppler/PSOutputDev.h:
* poppler/PSTokenizer.cc:
* poppler/Page.cc:
* poppler/Page.h:
* poppler/PageLabelInfo.cc:
* poppler/Parser.cc:
* poppler/Parser.h:
* poppler/PreScanOutputDev.cc:
* poppler/PreScanOutputDev.h:
* poppler/SecurityHandler.cc:
* poppler/SecurityHandler.h:
* poppler/SplashOutputDev.cc:
* poppler/SplashOutputDev.h:
* poppler/Stream.cc:
* poppler/Stream.h:
* poppler/TextOutputDev.cc:
* poppler/TextOutputDev.h:
* poppler/XRef.cc:
* poppler/XRef.h:
* qt/poppler-document.cc:
* qt/poppler-page-transition.cc:
* qt/poppler-page.cc:
* qt/poppler-private.h:
* qt4/src/poppler-annotation-helper.h:
* qt4/src/poppler-document.cc:
* qt4/src/poppler-embeddedfile.cc:
* qt4/src/poppler-form.cc:
* qt4/src/poppler-page.cc:
* qt4/src/poppler-private.h:
* splash/Splash.cc:
* splash/Splash.h:
* splash/SplashBitmap.cc:
* splash/SplashBitmap.h:
* splash/SplashClip.cc:
* splash/SplashClip.h:
* splash/SplashFTFont.cc:
* splash/SplashFTFont.h:
* splash/SplashFTFontEngine.cc:
* splash/SplashFTFontEngine.h:
* splash/SplashFTFontFile.cc:
* splash/SplashFTFontFile.h:
* splash/SplashFont.cc:
* splash/SplashFont.h:
* splash/SplashFontEngine.cc:
* splash/SplashFontEngine.h:
* splash/SplashFontFile.cc:
* splash/SplashFontFile.h:
* splash/SplashMath.h:
* splash/SplashPath.cc:
* splash/SplashPath.h:
* splash/SplashPattern.cc:
* splash/SplashPattern.h:
* splash/SplashScreen.cc:
* splash/SplashScreen.h:
* splash/SplashState.cc:
* splash/SplashState.h:
* splash/SplashT1Font.cc:
* splash/SplashT1Font.h:
* splash/SplashT1FontEngine.cc:
* splash/SplashT1FontFile.cc:
* splash/SplashT1FontFile.h:
* splash/SplashTypes.h:
* splash/SplashXPath.cc:
* splash/SplashXPath.h:
* splash/SplashXPathScanner.cc:
* splash/SplashXPathScanner.h:
* utils/HtmlOutputDev.cc:
* utils/HtmlOutputDev.h:
* utils/pdffonts.cc:
* utils/pdfinfo.cc:
* utils/pdftoabw.cc:
* utils/pdftohtml.cc:
* utils/pdftoppm.cc:
* utils/pdftops.cc:
* utils/pdftotext.cc:
Merge xpdf 3.02 changes
2007-04-15 Pino Toscano <pino@kde.org> 2007-04-15 Pino Toscano <pino@kde.org>
reviewed by: Albert Astals Cid <aacid@kde.org> reviewed by: Albert Astals Cid <aacid@kde.org>
......
...@@ -40,6 +40,10 @@ dnl ##### Checks for header files. ...@@ -40,6 +40,10 @@ dnl ##### Checks for header files.
AC_PATH_XTRA AC_PATH_XTRA
AC_HEADER_DIRENT AC_HEADER_DIRENT
AC_ARG_ENABLE(exceptions,
[ --enable-exceptions use C++ exceptions],
AC_DEFINE([USE_EXCEPTIONS], [], [Throw exceptions to deal with not enough memory and similar problems]))
dnl ##### Switch over to C++. This will make the checks below a little dnl ##### Switch over to C++. This will make the checks below a little
dnl ##### bit stricter (requiring function prototypes in include files). dnl ##### bit stricter (requiring function prototypes in include files).
dnl ##### (99% of xpdf is written in C++.) dnl ##### (99% of xpdf is written in C++.)
......
This diff is collapsed.
...@@ -34,9 +34,12 @@ public: ...@@ -34,9 +34,12 @@ public:
// Create a FoFiTrueType object from a file on disk. // Create a FoFiTrueType object from a file on disk.
static FoFiTrueType *load(char *fileName, int faceIndexA=0); static FoFiTrueType *load(char *fileName, int faceIndexA=0);
FoFiTrueType(char *fileA, int lenA, GBool freeFileDataA, int faceIndexA=0);
virtual ~FoFiTrueType(); virtual ~FoFiTrueType();
// Returns true if this an OpenType font containing CFF data, false
// if it's a TrueType font (or OpenType font with TrueType data).
GBool isOpenTypeCFF() { return openTypeCFF; }
// Return the number of cmaps defined by this font. // Return the number of cmaps defined by this font.
int getNumCmaps(); int getNumCmaps();
...@@ -58,6 +61,11 @@ public: ...@@ -58,6 +61,11 @@ public:
// font does not have a post table. // font does not have a post table.
int mapNameToGID(char *name); int mapNameToGID(char *name);
// Return the mapping from CIDs to GIDs, and return the number of
// CIDs in *<nCIDs>. This is only useful for CID fonts. (Only
// useful for OpenType CFF fonts.)
Gushort *getCIDToGIDMap(int *nCIDs);
// Returns the least restrictive embedding licensing right (as // Returns the least restrictive embedding licensing right (as
// defined by the TrueType spec): // defined by the TrueType spec):
// * 4: OS/2 table is missing or invalid // * 4: OS/2 table is missing or invalid
...@@ -73,38 +81,63 @@ public: ...@@ -73,38 +81,63 @@ public:
// <encoding> array specifies the mapping from char codes to names. // <encoding> array specifies the mapping from char codes to names.
// If <encoding> is NULL, the encoding is unknown or undefined. The // If <encoding> is NULL, the encoding is unknown or undefined. The
// <codeToGID> array specifies the mapping from char codes to GIDs. // <codeToGID> array specifies the mapping from char codes to GIDs.
// (Not useful for OpenType CFF fonts.)
void convertToType42(char *psName, char **encoding, void convertToType42(char *psName, char **encoding,
Gushort *codeToGID, Gushort *codeToGID,
FoFiOutputFunc outputFunc, void *outputStream); FoFiOutputFunc outputFunc, void *outputStream);
// Convert to a Type 1 font, suitable for embedding in a PostScript
// file. This is only useful with 8-bit fonts. If <newEncoding> is
// not NULL, it will be used in place of the encoding in the Type 1C
// font. If <ascii> is true the eexec section will be hex-encoded,
// otherwise it will be left as binary data. If <psName> is
// non-NULL, it will be used as the PostScript font name. (Only
// useful for OpenType CFF fonts.)
void convertToType1(char *psName, char **newEncoding, GBool ascii,
FoFiOutputFunc outputFunc, void *outputStream);
// Convert to a Type 2 CIDFont, suitable for embedding in a // Convert to a Type 2 CIDFont, suitable for embedding in a
// PostScript file. <psName> will be used as the PostScript font // PostScript file. <psName> will be used as the PostScript font
// name (so we don't need to depend on the 'name' table in the // name (so we don't need to depend on the 'name' table in the
// font). The <cidMap> array maps CIDs to GIDs; it has <nCIDs> // font). The <cidMap> array maps CIDs to GIDs; it has <nCIDs>
// entries. // entries. (Not useful for OpenType CFF fonts.)
void convertToCIDType2(char *psName, Gushort *cidMap, int nCIDs, void convertToCIDType2(char *psName, Gushort *cidMap, int nCIDs,
GBool needVerticalMetrics, GBool needVerticalMetrics,
FoFiOutputFunc outputFunc, void *outputStream); FoFiOutputFunc outputFunc, void *outputStream);
// Convert to a Type 0 CIDFont, suitable for embedding in a
// PostScript file. <psName> will be used as the PostScript font
// name. (Only useful for OpenType CFF fonts.)
void convertToCIDType0(char *psName,
FoFiOutputFunc outputFunc, void *outputStream);
// Convert to a Type 0 (but non-CID) composite font, suitable for // Convert to a Type 0 (but non-CID) composite font, suitable for
// embedding in a PostScript file. <psName> will be used as the // embedding in a PostScript file. <psName> will be used as the
// PostScript font name (so we don't need to depend on the 'name' // PostScript font name (so we don't need to depend on the 'name'
// table in the font). The <cidMap> array maps CIDs to GIDs; it has // table in the font). The <cidMap> array maps CIDs to GIDs; it has
// <nCIDs> entries. // <nCIDs> entries. (Not useful for OpenType CFF fonts.)
void convertToType0(char *psName, Gushort *cidMap, int nCIDs, void convertToType0(char *psName, Gushort *cidMap, int nCIDs,
GBool needVerticalMetrics, GBool needVerticalMetrics,
FoFiOutputFunc outputFunc, void *outputStream); FoFiOutputFunc outputFunc, void *outputStream);
// Convert to a Type 0 (but non-CID) composite font, suitable for
// embedding in a PostScript file. <psName> will be used as the
// PostScript font name. (Only useful for OpenType CFF fonts.)
void convertToType0(char *psName,
FoFiOutputFunc outputFunc, void *outputStream);
// Write a clean TTF file, filling in missing tables and correcting // Write a clean TTF file, filling in missing tables and correcting
// various other errors. If <name> is non-NULL, the font is renamed // various other errors. If <name> is non-NULL, the font is renamed
// to <name>. If <codeToGID> is non-NULL, the font is re-encoded, // to <name>. If <codeToGID> is non-NULL, the font is re-encoded,
// using a Windows Unicode cmap. If <name> is NULL and the font is // using a Windows Unicode cmap. If <name> is NULL and the font is
// complete and correct, it will be written unmodified. // complete and correct, it will be written unmodified. (Not useful
// for OpenType CFF fonts.)
void writeTTF(FoFiOutputFunc outputFunc, void *outputStream, void writeTTF(FoFiOutputFunc outputFunc, void *outputStream,
char *name = NULL, Gushort *codeToGID = NULL); char *name = NULL, Gushort *codeToGID = NULL);
private: private:
FoFiTrueType(char *fileA, int lenA, GBool freeFileDataA, int faceIndexA);
void cvtEncoding(char **encoding, void cvtEncoding(char **encoding,
FoFiOutputFunc outputFunc, FoFiOutputFunc outputFunc,
void *outputStream); void *outputStream);
...@@ -131,6 +164,7 @@ private: ...@@ -131,6 +164,7 @@ private:
int locaFmt; int locaFmt;
int bbox[4]; int bbox[4];
GooHash *nameToGID; GooHash *nameToGID;
GBool openTypeCFF;
GBool parsedOk; GBool parsedOk;
int faceIndex; int faceIndex;
......
...@@ -75,7 +75,7 @@ char **FoFiType1::getEncoding() { ...@@ -75,7 +75,7 @@ char **FoFiType1::getEncoding() {
void FoFiType1::writeEncoded(char **newEncoding, void FoFiType1::writeEncoded(char **newEncoding,
FoFiOutputFunc outputFunc, void *outputStream) { FoFiOutputFunc outputFunc, void *outputStream) {
char buf[512]; char buf[512];
char *line; char *line, *line2, *p;
int i; int i;
// copy everything up to the encoding // copy everything up to the encoding
...@@ -101,19 +101,57 @@ void FoFiType1::writeEncoded(char **newEncoding, ...@@ -101,19 +101,57 @@ void FoFiType1::writeEncoded(char **newEncoding,
} }
(*outputFunc)(outputStream, "readonly def\n", 13); (*outputFunc)(outputStream, "readonly def\n", 13);
// copy everything after the encoding // find the end of the encoding data
//~ this ought to parse PostScript tokens
if (!strncmp(line, "/Encoding StandardEncoding def", 30)) { if (!strncmp(line, "/Encoding StandardEncoding def", 30)) {
line = getNextLine(line); line = getNextLine(line);
} else { } else {
for (line = getNextLine(line); // skip "/Encoding" + one whitespace char,
line && strncmp(line, "readonly def", 12); // then look for 'def' preceded by PostScript whitespace
line = getNextLine(line)) ; p = line + 10;
if (line) { line = NULL;
line = getNextLine(line); for (; p < (char *)file + len; ++p) {
if ((*p == ' ' || *p == '\t' || *p == '\x0a' ||
*p == '\x0d' || *p == '\x0c' || *p == '\0') &&
p + 4 <= (char *)file + len &&
!strncmp(p + 1, "def", 3)) {
line = p + 4;
break;
}
} }
} }
// some fonts have two /Encoding entries in their dictionary, so we
// check for a second one here
if (line) { if (line) {
(*outputFunc)(outputStream, line, ((char *)file + len) - line); for (line2 = line, i = 0;
i < 20 && line2 && strncmp(line2, "/Encoding", 9);
line2 = getNextLine(line2), ++i) ;
if (i < 20 && line2) {
(*outputFunc)(outputStream, line, line2 - line);
if (!strncmp(line2, "/Encoding StandardEncoding def", 30)) {
line = getNextLine(line2);
} else {
// skip "/Encoding" + one whitespace char,
// then look for 'def' preceded by PostScript whitespace
p = line2 + 10;
line = NULL;
for (; p < (char *)file + len; ++p) {
if ((*p == ' ' || *p == '\t' || *p == '\x0a' ||
*p == '\x0d' || *p == '\x0c' || *p == '\0') &&
p + 4 <= (char *)file + len &&
!strncmp(p + 1, "def", 3)) {
line = p + 4;
break;
}
}
}
}
// copy everything after the encoding
if (line) {
(*outputFunc)(outputStream, line, ((char *)file + len) - line);
}
} }
} }
...@@ -178,8 +216,15 @@ void FoFiType1::parse() { ...@@ -178,8 +216,15 @@ void FoFiType1::parse() {
if (*p2) { if (*p2) {
c = *p2; c = *p2;
*p2 = '\0'; *p2 = '\0';
if ((code = atoi(p)) < 256) { code = atoi(p);
*p2 = c; *p2 = c;
if (code == 8 && *p2 == '#') {
code = 0;
for (++p2; *p2 >= '0' && *p2 <= '7'; ++p2) {
code = code * 8 + (*p2 - '0');
}
}
if (code < 256) {
for (p = p2; *p == ' ' || *p == '\t'; ++p) ; for (p = p2; *p == ' ' || *p == '\t'; ++p) ;
if (*p == '/') { if (*p == '/') {
++p; ++p;
......
This diff is collapsed.
...@@ -138,7 +138,6 @@ public: ...@@ -138,7 +138,6 @@ public:
// Create a FoFiType1C object from a file on disk. // Create a FoFiType1C object from a file on disk.
static FoFiType1C *load(char *fileName); static FoFiType1C *load(char *fileName);
FoFiType1C(char *fileA, int lenA, GBool freeFileDataA);
virtual ~FoFiType1C(); virtual ~FoFiType1C();
// Return the font name. // Return the font name.
...@@ -156,8 +155,9 @@ public: ...@@ -156,8 +155,9 @@ public:
// file. This is only useful with 8-bit fonts. If <newEncoding> is // file. This is only useful with 8-bit fonts. If <newEncoding> is
// not NULL, it will be used in place of the encoding in the Type 1C // not NULL, it will be used in place of the encoding in the Type 1C
// font. If <ascii> is true the eexec section will be hex-encoded, // font. If <ascii> is true the eexec section will be hex-encoded,
// otherwise it will be left as binary data. // otherwise it will be left as binary data. If <psName> is non-NULL,
void convertToType1(char **newEncoding, GBool ascii, // it will be used as the PostScript font name.
void convertToType1(char *psName, char **newEncoding, GBool ascii,
FoFiOutputFunc outputFunc, void *outputStream); FoFiOutputFunc outputFunc, void *outputStream);
// Convert to a Type 0 CIDFont, suitable for embedding in a // Convert to a Type 0 CIDFont, suitable for embedding in a
...@@ -174,6 +174,7 @@ public: ...@@ -174,6 +174,7 @@ public:
private: private:
FoFiType1C(char *fileA, int lenA, GBool freeFileDataA);
void eexecCvtGlyph(Type1CEexecBuf *eb, char *glyphName, void eexecCvtGlyph(Type1CEexecBuf *eb, char *glyphName,
int offset, int nBytes, int offset, int nBytes,
Type1CIndex *subrIdx, Type1CIndex *subrIdx,
......
...@@ -16,8 +16,6 @@ ...@@ -16,8 +16,6 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/ */
#include <UGooString.h>
#include "poppler.h" #include "poppler.h"
#include "poppler-private.h" #include "poppler-private.h"
...@@ -267,7 +265,7 @@ dest_new_goto (PopplerDocument *document, ...@@ -267,7 +265,7 @@ dest_new_goto (PopplerDocument *document,
} }
static PopplerDest * static PopplerDest *
dest_new_named (UGooString *named_dest) dest_new_named (GooString *named_dest)
{ {
PopplerDest *dest; PopplerDest *dest;
gchar *name; gchar *name;
...@@ -280,9 +278,7 @@ dest_new_named (UGooString *named_dest) ...@@ -280,9 +278,7 @@ dest_new_named (UGooString *named_dest)
} }
dest->type = POPPLER_DEST_NAMED; dest->type = POPPLER_DEST_NAMED;
name = named_dest->getCString (); dest->named_dest = g_strdup (named_dest->getCString ());
dest->named_dest = g_strdup (name);
delete[] name;
return dest; return dest;
} }
...@@ -293,7 +289,7 @@ build_goto_dest (PopplerDocument *document, ...@@ -293,7 +289,7 @@ build_goto_dest (PopplerDocument *document,
LinkGoTo *link) LinkGoTo *link)
{ {
LinkDest *link_dest; LinkDest *link_dest;
UGooString *named_dest; GooString *named_dest;
/* Return if it isn't OK */ /* Return if it isn't OK */
if (! link->isOk ()) { if (! link->isOk ()) {
...@@ -318,7 +314,7 @@ build_goto_remote (PopplerAction *action, ...@@ -318,7 +314,7 @@ build_goto_remote (PopplerAction *action,
LinkGoToR *link) LinkGoToR *link)
{ {
LinkDest *link_dest; LinkDest *link_dest;
UGooString *named_dest; GooString *named_dest;
/* Return if it isn't OK */ /* Return if it isn't OK */
if (! link->isOk ()) { if (! link->isOk ()) {
......
...@@ -28,7 +28,6 @@ ...@@ -28,7 +28,6 @@
#include <Stream.h> #include <Stream.h>
#include <FontInfo.h> #include <FontInfo.h>
#include <PDFDocEncoding.h> #include <PDFDocEncoding.h>
#include <UGooString.h>
#include "poppler.h" #include "poppler.h"
#include "poppler-private.h" #include "poppler-private.h"
...@@ -388,12 +387,12 @@ poppler_document_find_dest (PopplerDocument *document, ...@@ -388,12 +387,12 @@ poppler_document_find_dest (PopplerDocument *document,
{ {
PopplerDest *dest = NULL; PopplerDest *dest = NULL;
LinkDest *link_dest = NULL; LinkDest *link_dest = NULL;
UGooString *g_link_name; GooString *g_link_name;
g_return_val_if_fail (POPPLER_IS_DOCUMENT (document), NULL); g_return_val_if_fail (POPPLER_IS_DOCUMENT (document), NULL);
g_return_val_if_fail (link_name != NULL, NULL); g_return_val_if_fail (link_name != NULL, NULL);
g_link_name = new UGooString (link_name); g_link_name = new GooString (link_name);
if (g_link_name) { if (g_link_name) {
link_dest = document->doc->findDest (g_link_name); link_dest = document->doc->findDest (g_link_name);
......
...@@ -332,7 +332,7 @@ poppler_page_render (PopplerPage *page, ...@@ -332,7 +332,7 @@ poppler_page_render (PopplerPage *page,
0, 0, 0, 0,
(int) ceil (page->page->getCropWidth ()), (int) ceil (page->page->getCropWidth ()),
(int) ceil (page->page->getCropHeight ()), (int) ceil (page->page->getCropHeight ()),
NULL, /* links */ gFalse, /* printing */
page->document->doc->getCatalog ()); page->document->doc->getCatalog ());
output_dev->setCairo (NULL); output_dev->setCairo (NULL);
...@@ -378,7 +378,7 @@ poppler_page_render_to_pixbuf (PopplerPage *page, ...@@ -378,7 +378,7 @@ poppler_page_render_to_pixbuf (PopplerPage *page,
gTrue, /* Crop */ gTrue, /* Crop */
src_x, src_y, src_x, src_y,
src_width, src_height, src_width, src_height,
NULL, /* links */ gFalse, /* printing */
page->document->doc->getCatalog ()); page->document->doc->getCatalog ());
poppler_page_copy_to_pixbuf (page, pixbuf, &data); poppler_page_copy_to_pixbuf (page, pixbuf, &data);
...@@ -395,7 +395,7 @@ poppler_page_get_text_output_dev (PopplerPage *page) ...@@ -395,7 +395,7 @@ poppler_page_get_text_output_dev (PopplerPage *page)
gFalse, /* useMediaBox */ gFalse, /* useMediaBox */
gTrue, /* Crop */ gTrue, /* Crop */
-1, -1, -1, -1, -1, -1, -1, -1,
NULL, /* links */ gFalse, /* printing */
page->document->doc->getCatalog (), page->document->doc->getCatalog (),
NULL, NULL, NULL, NULL); NULL, NULL, NULL, NULL);
...@@ -744,7 +744,7 @@ poppler_page_find_text (PopplerPage *page, ...@@ -744,7 +744,7 @@ poppler_page_find_text (PopplerPage *page,
poppler_page_get_size (page, NULL, &height); poppler_page_get_size (page, NULL, &height);
page->page->display (output_dev, 72, 72, 0, gFalse, page->page->display (output_dev, 72, 72, 0, gFalse,
gTrue, NULL, doc->getCatalog()); gTrue, gFalse, doc->getCatalog());
matches = NULL; matches = NULL;
xMin = 0; xMin = 0;
......
...@@ -18,13 +18,17 @@ ...@@ -18,13 +18,17 @@
#include "FixedPoint.h" #include "FixedPoint.h"
#define ln2 ((FixedPoint)0.69314718)
#define ln2 ((FixedPoint)0.69314718)
FixedPoint FixedPoint::sqrt(FixedPoint x) { FixedPoint FixedPoint::sqrt(FixedPoint x) {
FixedPoint y0, y1, z; FixedPoint y0, y1, z;
if (x.val <= 0) { if (x.val <= 0) {
y1.val = 0; y1.val = 0;
} else { } else {
y1.val = x.val >> 1; y1.val = x.val == 1 ? 2 : x.val >> 1;
do { do {
y0.val = y1.val; y0.val = y1.val;
z = x / y0; z = x / y0;
...@@ -34,10 +38,9 @@ FixedPoint FixedPoint::sqrt(FixedPoint x) { ...@@ -34,10 +38,9 @@ FixedPoint FixedPoint::sqrt(FixedPoint x) {
return y1; return y1;
} }
//~ this is not very accurate
FixedPoint FixedPoint::pow(FixedPoint x, FixedPoint y) { FixedPoint FixedPoint::pow(FixedPoint x, FixedPoint y) {
FixedPoint t, t2, lnx0, lnx, z0, z; FixedPoint t, t2, lnx0, lnx, z0, z;
int d, i; int d, n, i;
if (y.val <= 0) { if (y.val <= 0) {
z.val = 0; z.val = 0;
...@@ -56,6 +59,8 @@ FixedPoint FixedPoint::pow(FixedPoint x, FixedPoint y) { ...@@ -56,6 +59,8 @@ FixedPoint FixedPoint::pow(FixedPoint x, FixedPoint y) {
lnx.val <<= 1; lnx.val <<= 1;
t = y * lnx; t = y * lnx;
// exp(y * ln(x)) // exp(y * ln(x))
n = floor(t / ln2);
t -= ln2 * n;
t2 = t; t2 = t;
d = 1; d = 1;
i = 1; i = 1;
...@@ -67,6 +72,11 @@ FixedPoint FixedPoint::pow(FixedPoint x, FixedPoint y) { ...@@ -67,6 +72,11 @@ FixedPoint FixedPoint::pow(FixedPoint x, FixedPoint y) {
++i; ++i;
d *= i; d *= i;
} while (::abs(z.val - z0.val) > 2 && d < (1 << fixptShift)); } while (::abs(z.val - z0.val) > 2 && d < (1 << fixptShift));
if (n >= 0) {
z.val <<= n;
} else if (n < 0) {
z.val >>= -n;
}
} }
return z; return z;
} }
...@@ -92,4 +102,19 @@ int FixedPoint::div(int x, int y) { ...@@ -92,4 +102,19 @@ int FixedPoint::div(int x, int y) {
#endif #endif
} }
GBool FixedPoint::divCheck(FixedPoint x, FixedPoint y, FixedPoint *result) {
#if 1 //~tmp
FixPtInt64 z;
z = ((FixPtInt64)x.val << fixptShift) / y.val;