mirror of
https://github.com/gnustep/libs-back.git
synced 2025-02-21 02:41:15 +00:00
Initial revision
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/back/trunk@13249 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
commit
669a4955e9
103 changed files with 35415 additions and 0 deletions
504
COPYING.LIB
Normal file
504
COPYING.LIB
Normal file
|
@ -0,0 +1,504 @@
|
|||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
Version 2.1, February 1999
|
||||
|
||||
Copyright (C) 1991, 1999 Free Software Foundation, Inc.
|
||||
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
[This is the first released version of the Lesser GPL. It also counts
|
||||
as the successor of the GNU Library Public License, version 2, hence
|
||||
the version number 2.1.]
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
Licenses are intended to guarantee your freedom to share and change
|
||||
free software--to make sure the software is free for all its users.
|
||||
|
||||
This license, the Lesser General Public License, applies to some
|
||||
specially designated software packages--typically libraries--of the
|
||||
Free Software Foundation and other authors who decide to use it. You
|
||||
can use it too, but we suggest you first think carefully about whether
|
||||
this license or the ordinary General Public License is the better
|
||||
strategy to use in any particular case, based on the explanations below.
|
||||
|
||||
When we speak of free software, we are referring to freedom of use,
|
||||
not price. Our General Public Licenses are designed to make sure that
|
||||
you have the freedom to distribute copies of free software (and charge
|
||||
for this service if you wish); that you receive source code or can get
|
||||
it if you want it; that you can change the software and use pieces of
|
||||
it in new free programs; and that you are informed that you can do
|
||||
these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
distributors to deny you these rights or to ask you to surrender these
|
||||
rights. These restrictions translate to certain responsibilities for
|
||||
you if you distribute copies of the library or if you modify it.
|
||||
|
||||
For example, if you distribute copies of the library, whether gratis
|
||||
or for a fee, you must give the recipients all the rights that we gave
|
||||
you. You must make sure that they, too, receive or can get the source
|
||||
code. If you link other code with the library, you must provide
|
||||
complete object files to the recipients, so that they can relink them
|
||||
with the library after making changes to the library and recompiling
|
||||
it. And you must show them these terms so they know their rights.
|
||||
|
||||
We protect your rights with a two-step method: (1) we copyright the
|
||||
library, and (2) we offer you this license, which gives you legal
|
||||
permission to copy, distribute and/or modify the library.
|
||||
|
||||
To protect each distributor, we want to make it very clear that
|
||||
there is no warranty for the free library. Also, if the library is
|
||||
modified by someone else and passed on, the recipients should know
|
||||
that what they have is not the original version, so that the original
|
||||
author's reputation will not be affected by problems that might be
|
||||
introduced by others.
|
||||
|
||||
Finally, software patents pose a constant threat to the existence of
|
||||
any free program. We wish to make sure that a company cannot
|
||||
effectively restrict the users of a free program by obtaining a
|
||||
restrictive license from a patent holder. Therefore, we insist that
|
||||
any patent license obtained for a version of the library must be
|
||||
consistent with the full freedom of use specified in this license.
|
||||
|
||||
Most GNU software, including some libraries, is covered by the
|
||||
ordinary GNU General Public License. This license, the GNU Lesser
|
||||
General Public License, applies to certain designated libraries, and
|
||||
is quite different from the ordinary General Public License. We use
|
||||
this license for certain libraries in order to permit linking those
|
||||
libraries into non-free programs.
|
||||
|
||||
When a program is linked with a library, whether statically or using
|
||||
a shared library, the combination of the two is legally speaking a
|
||||
combined work, a derivative of the original library. The ordinary
|
||||
General Public License therefore permits such linking only if the
|
||||
entire combination fits its criteria of freedom. The Lesser General
|
||||
Public License permits more lax criteria for linking other code with
|
||||
the library.
|
||||
|
||||
We call this license the "Lesser" General Public License because it
|
||||
does Less to protect the user's freedom than the ordinary General
|
||||
Public License. It also provides other free software developers Less
|
||||
of an advantage over competing non-free programs. These disadvantages
|
||||
are the reason we use the ordinary General Public License for many
|
||||
libraries. However, the Lesser license provides advantages in certain
|
||||
special circumstances.
|
||||
|
||||
For example, on rare occasions, there may be a special need to
|
||||
encourage the widest possible use of a certain library, so that it becomes
|
||||
a de-facto standard. To achieve this, non-free programs must be
|
||||
allowed to use the library. A more frequent case is that a free
|
||||
library does the same job as widely used non-free libraries. In this
|
||||
case, there is little to gain by limiting the free library to free
|
||||
software only, so we use the Lesser General Public License.
|
||||
|
||||
In other cases, permission to use a particular library in non-free
|
||||
programs enables a greater number of people to use a large body of
|
||||
free software. For example, permission to use the GNU C Library in
|
||||
non-free programs enables many more people to use the whole GNU
|
||||
operating system, as well as its variant, the GNU/Linux operating
|
||||
system.
|
||||
|
||||
Although the Lesser General Public License is Less protective of the
|
||||
users' freedom, it does ensure that the user of a program that is
|
||||
linked with the Library has the freedom and the wherewithal to run
|
||||
that program using a modified version of the Library.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow. Pay close attention to the difference between a
|
||||
"work based on the library" and a "work that uses the library". The
|
||||
former contains code derived from the library, whereas the latter must
|
||||
be combined with the library in order to run.
|
||||
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License Agreement applies to any software library or other
|
||||
program which contains a notice placed by the copyright holder or
|
||||
other authorized party saying it may be distributed under the terms of
|
||||
this Lesser General Public License (also called "this License").
|
||||
Each licensee is addressed as "you".
|
||||
|
||||
A "library" means a collection of software functions and/or data
|
||||
prepared so as to be conveniently linked with application programs
|
||||
(which use some of those functions and data) to form executables.
|
||||
|
||||
The "Library", below, refers to any such software library or work
|
||||
which has been distributed under these terms. A "work based on the
|
||||
Library" means either the Library or any derivative work under
|
||||
copyright law: that is to say, a work containing the Library or a
|
||||
portion of it, either verbatim or with modifications and/or translated
|
||||
straightforwardly into another language. (Hereinafter, translation is
|
||||
included without limitation in the term "modification".)
|
||||
|
||||
"Source code" for a work means the preferred form of the work for
|
||||
making modifications to it. For a library, complete source code means
|
||||
all the source code for all modules it contains, plus any associated
|
||||
interface definition files, plus the scripts used to control compilation
|
||||
and installation of the library.
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running a program using the Library is not restricted, and output from
|
||||
such a program is covered only if its contents constitute a work based
|
||||
on the Library (independent of the use of the Library in a tool for
|
||||
writing it). Whether that is true depends on what the Library does
|
||||
and what the program that uses the Library does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Library's
|
||||
complete source code as you receive it, in any medium, provided that
|
||||
you conspicuously and appropriately publish on each copy an
|
||||
appropriate copyright notice and disclaimer of warranty; keep intact
|
||||
all the notices that refer to this License and to the absence of any
|
||||
warranty; and distribute a copy of this License along with the
|
||||
Library.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy,
|
||||
and you may at your option offer warranty protection in exchange for a
|
||||
fee.
|
||||
|
||||
2. You may modify your copy or copies of the Library or any portion
|
||||
of it, thus forming a work based on the Library, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) The modified work must itself be a software library.
|
||||
|
||||
b) You must cause the files modified to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
c) You must cause the whole of the work to be licensed at no
|
||||
charge to all third parties under the terms of this License.
|
||||
|
||||
d) If a facility in the modified Library refers to a function or a
|
||||
table of data to be supplied by an application program that uses
|
||||
the facility, other than as an argument passed when the facility
|
||||
is invoked, then you must make a good faith effort to ensure that,
|
||||
in the event an application does not supply such function or
|
||||
table, the facility still operates, and performs whatever part of
|
||||
its purpose remains meaningful.
|
||||
|
||||
(For example, a function in a library to compute square roots has
|
||||
a purpose that is entirely well-defined independent of the
|
||||
application. Therefore, Subsection 2d requires that any
|
||||
application-supplied function or table used by this function must
|
||||
be optional: if the application does not supply it, the square
|
||||
root function must still compute square roots.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Library,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Library, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote
|
||||
it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Library.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Library
|
||||
with the Library (or with a work based on the Library) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may opt to apply the terms of the ordinary GNU General Public
|
||||
License instead of this License to a given copy of the Library. To do
|
||||
this, you must alter all the notices that refer to this License, so
|
||||
that they refer to the ordinary GNU General Public License, version 2,
|
||||
instead of to this License. (If a newer version than version 2 of the
|
||||
ordinary GNU General Public License has appeared, then you can specify
|
||||
that version instead if you wish.) Do not make any other change in
|
||||
these notices.
|
||||
|
||||
Once this change is made in a given copy, it is irreversible for
|
||||
that copy, so the ordinary GNU General Public License applies to all
|
||||
subsequent copies and derivative works made from that copy.
|
||||
|
||||
This option is useful when you wish to copy part of the code of
|
||||
the Library into a program that is not a library.
|
||||
|
||||
4. You may copy and distribute the Library (or a portion or
|
||||
derivative of it, under Section 2) in object code or executable form
|
||||
under the terms of Sections 1 and 2 above provided that you accompany
|
||||
it with the complete corresponding machine-readable source code, which
|
||||
must be distributed under the terms of Sections 1 and 2 above on a
|
||||
medium customarily used for software interchange.
|
||||
|
||||
If distribution of object code is made by offering access to copy
|
||||
from a designated place, then offering equivalent access to copy the
|
||||
source code from the same place satisfies the requirement to
|
||||
distribute the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
5. A program that contains no derivative of any portion of the
|
||||
Library, but is designed to work with the Library by being compiled or
|
||||
linked with it, is called a "work that uses the Library". Such a
|
||||
work, in isolation, is not a derivative work of the Library, and
|
||||
therefore falls outside the scope of this License.
|
||||
|
||||
However, linking a "work that uses the Library" with the Library
|
||||
creates an executable that is a derivative of the Library (because it
|
||||
contains portions of the Library), rather than a "work that uses the
|
||||
library". The executable is therefore covered by this License.
|
||||
Section 6 states terms for distribution of such executables.
|
||||
|
||||
When a "work that uses the Library" uses material from a header file
|
||||
that is part of the Library, the object code for the work may be a
|
||||
derivative work of the Library even though the source code is not.
|
||||
Whether this is true is especially significant if the work can be
|
||||
linked without the Library, or if the work is itself a library. The
|
||||
threshold for this to be true is not precisely defined by law.
|
||||
|
||||
If such an object file uses only numerical parameters, data
|
||||
structure layouts and accessors, and small macros and small inline
|
||||
functions (ten lines or less in length), then the use of the object
|
||||
file is unrestricted, regardless of whether it is legally a derivative
|
||||
work. (Executables containing this object code plus portions of the
|
||||
Library will still fall under Section 6.)
|
||||
|
||||
Otherwise, if the work is a derivative of the Library, you may
|
||||
distribute the object code for the work under the terms of Section 6.
|
||||
Any executables containing that work also fall under Section 6,
|
||||
whether or not they are linked directly with the Library itself.
|
||||
|
||||
6. As an exception to the Sections above, you may also combine or
|
||||
link a "work that uses the Library" with the Library to produce a
|
||||
work containing portions of the Library, and distribute that work
|
||||
under terms of your choice, provided that the terms permit
|
||||
modification of the work for the customer's own use and reverse
|
||||
engineering for debugging such modifications.
|
||||
|
||||
You must give prominent notice with each copy of the work that the
|
||||
Library is used in it and that the Library and its use are covered by
|
||||
this License. You must supply a copy of this License. If the work
|
||||
during execution displays copyright notices, you must include the
|
||||
copyright notice for the Library among them, as well as a reference
|
||||
directing the user to the copy of this License. Also, you must do one
|
||||
of these things:
|
||||
|
||||
a) Accompany the work with the complete corresponding
|
||||
machine-readable source code for the Library including whatever
|
||||
changes were used in the work (which must be distributed under
|
||||
Sections 1 and 2 above); and, if the work is an executable linked
|
||||
with the Library, with the complete machine-readable "work that
|
||||
uses the Library", as object code and/or source code, so that the
|
||||
user can modify the Library and then relink to produce a modified
|
||||
executable containing the modified Library. (It is understood
|
||||
that the user who changes the contents of definitions files in the
|
||||
Library will not necessarily be able to recompile the application
|
||||
to use the modified definitions.)
|
||||
|
||||
b) Use a suitable shared library mechanism for linking with the
|
||||
Library. A suitable mechanism is one that (1) uses at run time a
|
||||
copy of the library already present on the user's computer system,
|
||||
rather than copying library functions into the executable, and (2)
|
||||
will operate properly with a modified version of the library, if
|
||||
the user installs one, as long as the modified version is
|
||||
interface-compatible with the version that the work was made with.
|
||||
|
||||
c) Accompany the work with a written offer, valid for at
|
||||
least three years, to give the same user the materials
|
||||
specified in Subsection 6a, above, for a charge no more
|
||||
than the cost of performing this distribution.
|
||||
|
||||
d) If distribution of the work is made by offering access to copy
|
||||
from a designated place, offer equivalent access to copy the above
|
||||
specified materials from the same place.
|
||||
|
||||
e) Verify that the user has already received a copy of these
|
||||
materials or that you have already sent this user a copy.
|
||||
|
||||
For an executable, the required form of the "work that uses the
|
||||
Library" must include any data and utility programs needed for
|
||||
reproducing the executable from it. However, as a special exception,
|
||||
the materials to be distributed need not include anything that is
|
||||
normally distributed (in either source or binary form) with the major
|
||||
components (compiler, kernel, and so on) of the operating system on
|
||||
which the executable runs, unless that component itself accompanies
|
||||
the executable.
|
||||
|
||||
It may happen that this requirement contradicts the license
|
||||
restrictions of other proprietary libraries that do not normally
|
||||
accompany the operating system. Such a contradiction means you cannot
|
||||
use both them and the Library together in an executable that you
|
||||
distribute.
|
||||
|
||||
7. You may place library facilities that are a work based on the
|
||||
Library side-by-side in a single library together with other library
|
||||
facilities not covered by this License, and distribute such a combined
|
||||
library, provided that the separate distribution of the work based on
|
||||
the Library and of the other library facilities is otherwise
|
||||
permitted, and provided that you do these two things:
|
||||
|
||||
a) Accompany the combined library with a copy of the same work
|
||||
based on the Library, uncombined with any other library
|
||||
facilities. This must be distributed under the terms of the
|
||||
Sections above.
|
||||
|
||||
b) Give prominent notice with the combined library of the fact
|
||||
that part of it is a work based on the Library, and explaining
|
||||
where to find the accompanying uncombined form of the same work.
|
||||
|
||||
8. You may not copy, modify, sublicense, link with, or distribute
|
||||
the Library except as expressly provided under this License. Any
|
||||
attempt otherwise to copy, modify, sublicense, link with, or
|
||||
distribute the Library is void, and will automatically terminate your
|
||||
rights under this License. However, parties who have received copies,
|
||||
or rights, from you under this License will not have their licenses
|
||||
terminated so long as such parties remain in full compliance.
|
||||
|
||||
9. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Library or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Library (or any work based on the
|
||||
Library), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Library or works based on it.
|
||||
|
||||
10. Each time you redistribute the Library (or any work based on the
|
||||
Library), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute, link with or modify the Library
|
||||
subject to these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties with
|
||||
this License.
|
||||
|
||||
11. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Library at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Library by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Library.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under any
|
||||
particular circumstance, the balance of the section is intended to apply,
|
||||
and the section as a whole is intended to apply in other circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
12. If the distribution and/or use of the Library is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Library under this License may add
|
||||
an explicit geographical distribution limitation excluding those countries,
|
||||
so that distribution is permitted only in or among countries not thus
|
||||
excluded. In such case, this License incorporates the limitation as if
|
||||
written in the body of this License.
|
||||
|
||||
13. The Free Software Foundation may publish revised and/or new
|
||||
versions of the Lesser General Public License from time to time.
|
||||
Such new versions will be similar in spirit to the present version,
|
||||
but may differ in detail to address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Library
|
||||
specifies a version number of this License which applies to it and
|
||||
"any later version", you have the option of following the terms and
|
||||
conditions either of that version or of any later version published by
|
||||
the Free Software Foundation. If the Library does not specify a
|
||||
license version number, you may choose any version ever published by
|
||||
the Free Software Foundation.
|
||||
|
||||
14. If you wish to incorporate parts of the Library into other free
|
||||
programs whose distribution conditions are incompatible with these,
|
||||
write to the author to ask for permission. For software which is
|
||||
copyrighted by the Free Software Foundation, write to the Free
|
||||
Software Foundation; we sometimes make exceptions for this. Our
|
||||
decision will be guided by the two goals of preserving the free status
|
||||
of all derivatives of our free software and of promoting the sharing
|
||||
and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
|
||||
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
|
||||
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
|
||||
OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
|
||||
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
|
||||
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
|
||||
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
|
||||
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
|
||||
AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
|
||||
FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
|
||||
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
|
||||
LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
|
||||
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
|
||||
FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
|
||||
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
||||
DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Libraries
|
||||
|
||||
If you develop a new library, and you want it to be of the greatest
|
||||
possible use to the public, we recommend making it free software that
|
||||
everyone can redistribute and change. You can do so by permitting
|
||||
redistribution under these terms (or, alternatively, under the terms of the
|
||||
ordinary General Public License).
|
||||
|
||||
To apply these terms, attach the following notices to the library. It is
|
||||
safest to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least the
|
||||
"copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the library's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the library, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the
|
||||
library `Frob' (a library for tweaking knobs) written by James Random Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1990
|
||||
Ty Coon, President of Vice
|
||||
|
||||
That's all there is to it!
|
||||
|
||||
|
4
ChangeLog
Normal file
4
ChangeLog
Normal file
|
@ -0,0 +1,4 @@
|
|||
2002-03-27 Adam Fedor <fedor@gnu.org>
|
||||
|
||||
* Version: Initial version (most code extracted from xgps).
|
||||
|
91
Documentation/GNUmakefile
Normal file
91
Documentation/GNUmakefile
Normal file
|
@ -0,0 +1,91 @@
|
|||
#
|
||||
# Documentation makefile for the GNUstep Backend Library
|
||||
# Copyright (C) 1995 Free Software Foundation, Inc.
|
||||
#
|
||||
# Written by: Adam Fedor <fedor@gnu.org>
|
||||
#
|
||||
# This file is part of the GNUstep Backend Library.
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Library General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This library is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# Library General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Library General Public
|
||||
# License along with this library; if not, write to the Free
|
||||
# Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
|
||||
|
||||
# Install into the system root by default
|
||||
GNUSTEP_INSTALLATION_DIR = $(GNUSTEP_SYSTEM_ROOT)
|
||||
|
||||
GNUSTEP_MAKEFILES = $(GNUSTEP_SYSTEM_ROOT)/Makefiles
|
||||
|
||||
GNUSTEP_LOCAL_ADDITIONAL_MAKEFILES=../back.make
|
||||
include $(GNUSTEP_MAKEFILES)/common.make
|
||||
|
||||
include ../Version
|
||||
|
||||
# The documents to be generated
|
||||
DOCUMENT_NAME =
|
||||
|
||||
# The text documents to be generated
|
||||
DOCUMENT_TEXT_NAME = \
|
||||
INSTALL NEWS README ANNOUNCE
|
||||
|
||||
TOP_DOC_FILES = INSTALL NEWS README ANNOUNCE
|
||||
|
||||
INSTALL_TEXI_FILES = version.texi
|
||||
INSTALL_TEXT_MAIN = install.texi
|
||||
INSTALL_DOC_INSTALL_DIR = Developer/Back/ReleaseNotes/$(VERSION)
|
||||
|
||||
NEWS_TEXI_FILES = version.texi
|
||||
NEWS_TEXT_MAIN = news.texi
|
||||
NEWS_DOC_INSTALL_DIR = Developer/Back/ReleaseNotes/$(VERSION)
|
||||
|
||||
README_TEXI_FILES = version.texi
|
||||
README_TEXT_MAIN = readme.texi
|
||||
README_DOC_INSTALL_DIR = Developer/Back/ReleaseNotes/$(VERSION)
|
||||
|
||||
ANNOUNCE_TEXI_FILES = version.texi
|
||||
ANNOUNCE_TEXT_MAIN = announce.texi
|
||||
ANNOUNCE_DOC_INSTALL_DIR = Developer/Back/ReleaseNotes/$(VERSION)
|
||||
|
||||
-include Makefile.preamble
|
||||
|
||||
-include GNUmakefile.local
|
||||
|
||||
include $(GNUSTEP_MAKEFILES)/documentation.make
|
||||
|
||||
-include Makefile.postamble
|
||||
|
||||
regenerate: $(DOCUMENT_TEXT_NAME)
|
||||
mv $(TOP_DOC_FILES) ..
|
||||
|
||||
version.texi: ../Version
|
||||
rm -f version.texi
|
||||
echo '@set GNUSTEP-BACK-VERSION' $(GNUSTEP_BACK_VERSION) \
|
||||
> version.texi
|
||||
echo '@set GNUSTEP-BACK-GCC $(GNUSTEP_BACK_GCC)' \
|
||||
>> version.texi
|
||||
echo '@set GNUSTEP-BACK-DGS $(GNUSTEP_BACK_DGS)' \
|
||||
>> version.texi
|
||||
if [ $(GNUSTEP_BACK_FTP_MACHINE) ]; then \
|
||||
echo '@set GNUSTEP-BACK-FTP-MACHINE $(GNUSTEP_BACK_FTP_MACHINE)' \
|
||||
>> version.texi; fi
|
||||
if [ $(GNUSTEP_BACK_FTP_DIRECTORY) ]; then \
|
||||
echo '@set GNUSTEP-BACK-FTP-DIRECTORY \
|
||||
$(GNUSTEP_BACK_FTP_DIRECTORY)' \
|
||||
>> version.texi; fi
|
||||
if [ $(GNUSTEP_BACK_SNAP_FTP_MACHINE) ]; then \
|
||||
echo '@set GNUSTEP-BACK-SNAP-FTP-MACHINE \
|
||||
$(GNUSTEP_BACK_SNAP_FTP_MACHINE)' \
|
||||
>> version.texi; fi
|
||||
if [ $(GNUSTEP_BACK_SNAP_FTP_DIRECTORY) ]; then \
|
||||
echo '@set GNUSTEP-BACK-SNAP-FTP-DIRECTORY \
|
||||
$(GNUSTEP_BACK_SNAP_FTP_DIRECTORY)' \
|
||||
>> version.texi; fi
|
48
Documentation/announce.texi
Normal file
48
Documentation/announce.texi
Normal file
|
@ -0,0 +1,48 @@
|
|||
@c -*- texinfo -*-
|
||||
@chapter ANNOUNCE
|
||||
@ifset TEXT-ONLY
|
||||
@include version.texi
|
||||
@end ifset
|
||||
|
||||
This is version @value{GNUSTEP-BACK-VERSION} of the GNUstep GUI Backend
|
||||
(@samp{gnustep-back}).
|
||||
|
||||
@section What is the GNUstep GUI Backend?
|
||||
|
||||
It is a back-end component for the GNUstep GUI Library. The
|
||||
implementation of the GNUstep GUI Library is designed in two parts. The
|
||||
first part is the front-end component which is independent of platform
|
||||
and display system. This front-end is combined with a back-end
|
||||
component which handles all of the display system dependent such as
|
||||
specific calls to the X Window System. This design allows the GNUstep
|
||||
applications to have the "look and feel" of the underlying display
|
||||
system without any changes to the application, and the library can be
|
||||
easily ported to other display systems.
|
||||
|
||||
The GNUstep GUI Backend is for platforms using the X-Window System and
|
||||
in the future, Window's Systems. It works via a DPS emulation engine to
|
||||
emulate the DPS functions required by the front-end system.
|
||||
|
||||
@set ANNOUNCE-ONLY
|
||||
@include news.texi
|
||||
@clear ANNOUNCE-ONLY
|
||||
|
||||
@section Where can you get it? How can you compile it?
|
||||
|
||||
@ifset GNUSTEP-BACK-FTP-MACHINE
|
||||
The gstep-back-@value{GNUSTEP-BACK-VERSION}.tar.gz distribution
|
||||
file has been placed on @samp{@value{GNUSTEP-BACK-FTP-MACHINE}} in
|
||||
@samp{@value{GNUSTEP-BACK-FTP-DIRECTORY}}.
|
||||
@end ifset
|
||||
|
||||
@section Where do I send bug reports?
|
||||
|
||||
Bug reports can be sent to the GNUstep bug list
|
||||
@email{bug-gnustep@@gnu.org}
|
||||
|
||||
@section Obtaining GNU Software
|
||||
|
||||
Check out the GNUstep web site. (@url{http://www.gnustep.org/}) and the
|
||||
GNU web site. (@url{http://www.gnu.org/})
|
||||
|
||||
|
54
Documentation/install.texi
Normal file
54
Documentation/install.texi
Normal file
|
@ -0,0 +1,54 @@
|
|||
@c -*- texinfo -*-
|
||||
@chapter Installation
|
||||
|
||||
@node Top, Introduction, (dir), (dir)
|
||||
@include version.texi
|
||||
|
||||
@menu
|
||||
* Introduction::
|
||||
* Configuration::
|
||||
* Compilation::
|
||||
* Installing::
|
||||
@end menu
|
||||
|
||||
|
||||
@node Introduction, Configuration, Top, Top
|
||||
@section Introduction
|
||||
|
||||
This file documents the installation of the GNUstep Backend Library,
|
||||
@samp{gnustep-back}. If you are installing this package as part of the
|
||||
GNUstep core package, read the file GNUstep-HOWTO for more complete
|
||||
instructions on how to install the entire GNUstep package (including
|
||||
this library). GNUstep-HOWTO is located at @url{http://www.gnustep.org}
|
||||
|
||||
You must have installed gnustep-gui before installing this library.
|
||||
|
||||
@node Configuration, Compilation, Introduction, Top
|
||||
@section Configuration
|
||||
|
||||
Configuration is performed by running the @file{configure} program at a
|
||||
shell prompt. You may want to use some of the optional arguments to the
|
||||
@file{configure} program. Type @code{configure --help} for a list. GNUstep
|
||||
specific options are at the end of this list (if any).
|
||||
|
||||
@node Compilation, Installing, Configuration, Top
|
||||
@section Compilation
|
||||
|
||||
To compile this library, type make. After this is complete, type make
|
||||
install (make sure you are the root user). Some additional options you
|
||||
can use with make are @samp{debug=yes} to make a debugging version of
|
||||
the library and @samp{shared=no} to make a static version of the
|
||||
library. See the gstep-make package for more information on these options.
|
||||
|
||||
@node Installing, , Compilation, Top
|
||||
@section Installing
|
||||
|
||||
To install, type
|
||||
|
||||
@example
|
||||
make install
|
||||
@end example
|
||||
|
||||
@bye
|
||||
|
||||
|
19
Documentation/news.texi
Normal file
19
Documentation/news.texi
Normal file
|
@ -0,0 +1,19 @@
|
|||
@c -*-texinfo-*-
|
||||
@ifclear ANNOUNCE-ONLY
|
||||
@chapter NEWS
|
||||
@end ifclear
|
||||
|
||||
@ifset TEXT-ONLY
|
||||
@include version.texi
|
||||
@end ifset
|
||||
|
||||
@section Noteworthy changes in version @samp{0.7.7}
|
||||
First release. Most components extracted from xgps.
|
||||
@end itemize
|
||||
|
||||
@c ====================================================================
|
||||
@c Keep the next line just below the list of changes in most recent version.
|
||||
@ifclear ANNOUNCE-ONLY
|
||||
|
||||
|
||||
@end ifclear
|
35
Documentation/readme.texi
Normal file
35
Documentation/readme.texi
Normal file
|
@ -0,0 +1,35 @@
|
|||
@c -*-texinfo-*-
|
||||
@chapter README
|
||||
|
||||
@ifset TEXT-ONLY
|
||||
@include version.texi
|
||||
@end ifset
|
||||
|
||||
This is version @value{GNUSTEP-BACK-VERSION} of the GNUstep GUI Backend
|
||||
(@samp{gnustep-back}).
|
||||
|
||||
Here is some introductory info to get you started:
|
||||
|
||||
@section Initial reading
|
||||
|
||||
@itemize @bullet
|
||||
@item
|
||||
The file @file{ANNOUNCE} contains a very brief overview of the library.
|
||||
It also tells you where to get the most recent version.
|
||||
|
||||
@item
|
||||
The file @file{NEWS} has the library's feature history.
|
||||
|
||||
@item
|
||||
The file @file{INSTALL} gives instructions for installing the library.
|
||||
@end itemize
|
||||
|
||||
@section How can you help?
|
||||
|
||||
@itemize @bullet
|
||||
|
||||
@item
|
||||
Give us feedback! Tell us what you like; tell us what you think
|
||||
could be better. Send us bug reports at @email{bug-gnustep@@gnu.org}.
|
||||
|
||||
@end itemize
|
51
GNUmakefile
Normal file
51
GNUmakefile
Normal file
|
@ -0,0 +1,51 @@
|
|||
#
|
||||
# Top level makefile for GNUstep Backend
|
||||
#
|
||||
# Copyright (C) 2002 Free Software Foundation, Inc.
|
||||
#
|
||||
# Author: Adam Fedor <fedor@gnu.org>
|
||||
#
|
||||
# This file is part of the GNUstep Backend.
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Library General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This library is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# Library General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Library General Public
|
||||
# License along with this library; see the file COPYING.LIB.
|
||||
# If not, write to the Free Software Foundation,
|
||||
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
# Install into the system root by default
|
||||
GNUSTEP_INSTALLATION_DIR = $(GNUSTEP_SYSTEM_ROOT)
|
||||
|
||||
RPM_DISABLE_RELOCATABLE=YES
|
||||
PACKAGE_NEEDS_CONFIGURE = YES
|
||||
|
||||
CVS_MODULE_NAME = back
|
||||
|
||||
GNUSTEP_MAKEFILES = $(GNUSTEP_SYSTEM_ROOT)/Makefiles
|
||||
|
||||
GNUSTEP_LOCAL_ADDITIONAL_MAKEFILES=back.make
|
||||
include $(GNUSTEP_MAKEFILES)/common.make
|
||||
|
||||
PACKAGE_NAME = gnustep-back
|
||||
|
||||
include ./Version
|
||||
|
||||
#
|
||||
# The list of subproject directories
|
||||
#
|
||||
SUBPROJECTS = Source Tools
|
||||
|
||||
-include GNUmakefile.preamble
|
||||
|
||||
include $(GNUSTEP_MAKEFILES)/aggregate.make
|
||||
|
||||
-include GNUmakefile.postamble
|
71
GNUmakefile.postamble
Normal file
71
GNUmakefile.postamble
Normal file
|
@ -0,0 +1,71 @@
|
|||
# -*-makefile-*-
|
||||
# GNUmakefile.postamble
|
||||
#
|
||||
# Copyright (C) 2002 Free Software Foundation, Inc.
|
||||
#
|
||||
# Author: Adam Fedor <fedor@gnu.org>
|
||||
#
|
||||
# This file is part of the GNUstep Backend.
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Library General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This library is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# Library General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Library General Public
|
||||
# License along with this library; see the file COPYING.LIB.
|
||||
# If not, write to the Free Software Foundation,
|
||||
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
# Things to do before compiling
|
||||
# before-all::
|
||||
|
||||
# Things to do after compiling
|
||||
# after-all::
|
||||
|
||||
$(INSTALL_ROOT_DIR)/$(GNUSTEP_MAKEFILES)/Additional:
|
||||
$(MKDIRS) $(INSTALL_ROOT_DIR)/$(GNUSTEP_MAKEFILES)/Additional
|
||||
|
||||
# Things to do before installing
|
||||
before-install:: $(INSTALL_ROOT_DIR)/$(GNUSTEP_MAKEFILES)/Additional
|
||||
$(INSTALL_DATA) back.make \
|
||||
$(INSTALL_ROOT_DIR)/$(GNUSTEP_MAKEFILES)/Additional/back.make
|
||||
|
||||
# Things to do after installing
|
||||
# after-install::
|
||||
|
||||
# Things to do before uninstalling
|
||||
# before-uninstall::
|
||||
|
||||
# Things to do after uninstalling
|
||||
# after-uninstall::
|
||||
|
||||
# Things to do before cleaning
|
||||
# before-clean::
|
||||
|
||||
# Things to do after cleaning
|
||||
# after-clean::
|
||||
|
||||
# Things to do before distcleaning
|
||||
# before-distclean::
|
||||
|
||||
# Things to do after distcleaning
|
||||
after-distclean::
|
||||
rm -f config.status config.log config.cache TAGS config.make back.make
|
||||
|
||||
back.make: back.make.in
|
||||
./configure
|
||||
|
||||
confige.mak: confige.mak.in
|
||||
./configure
|
||||
|
||||
# Things to do before checking
|
||||
# before-check::
|
||||
|
||||
# Things to do after checking
|
||||
# after-check::
|
86
Headers/gsc/GSContext.h
Normal file
86
Headers/gsc/GSContext.h
Normal file
|
@ -0,0 +1,86 @@
|
|||
/* <title>GSContext</title>
|
||||
|
||||
<abstract>Generic backend drawing context.</abstract>
|
||||
|
||||
Copyright (C) 2002 Free Software Foundation, Inc.
|
||||
|
||||
Written By: Adam Fedor <fedor@gnu.org>
|
||||
Date: Mar 2002
|
||||
|
||||
This file is part of the GNU Objective C User Interface library.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
|
||||
*/
|
||||
|
||||
#ifndef _GSContext_h_INCLUDE
|
||||
#define _GSContext_h_INCLUDE
|
||||
|
||||
#include <Foundation/NSMapTable.h>
|
||||
#include <AppKit/NSGraphicsContext.h>
|
||||
|
||||
@class GSGState;
|
||||
@class GSDisplayServer;
|
||||
|
||||
@interface GSContext : NSGraphicsContext
|
||||
{
|
||||
@public
|
||||
GSDisplayServer *server;
|
||||
void *opstack;
|
||||
void *gstack;
|
||||
GSGState *gstate;
|
||||
NSMapTable *gtable;
|
||||
}
|
||||
|
||||
- (GSGState *) currentGState;
|
||||
|
||||
@end
|
||||
|
||||
/* Error Macros */
|
||||
#define DPS_WARN(type, resp) \
|
||||
NSDebugLLog(@"GSContext", type, resp)
|
||||
#define DPS_ERROR(type, resp) \
|
||||
NSLog(type, resp)
|
||||
|
||||
/* Current keys used for the info dictionary:
|
||||
Key: Value:
|
||||
DisplayName -- (NSString)name of X server
|
||||
ScreenNumber -- (NSNumber)screen number
|
||||
DebugContext -- (NSNumber)YES or NO
|
||||
*/
|
||||
|
||||
extern NSString *DPSconfigurationerror;
|
||||
extern NSString *DPSinvalidaccess;
|
||||
extern NSString *DPSinvalidcontext;
|
||||
extern NSString *DPSinvalidexit;
|
||||
extern NSString *DPSinvalidfileaccess;
|
||||
extern NSString *DPSinvalidfont;
|
||||
extern NSString *DPSinvalidid;
|
||||
extern NSString *DPSinvalidrestore;
|
||||
extern NSString *DPSinvalidparam;
|
||||
extern NSString *DPSioerror;
|
||||
extern NSString *DPSlimitcheck;
|
||||
extern NSString *DPSnocurrentpoint;
|
||||
extern NSString *DPSnulloutput;
|
||||
extern NSString *DPSrangecheck;
|
||||
extern NSString *DPSstackoverflow;
|
||||
extern NSString *DPSstackunderflow;
|
||||
extern NSString *DPStypecheck;
|
||||
extern NSString *DPSundefined;
|
||||
extern NSString *DPSundefinedfilename;
|
||||
extern NSString *DPSundefinedresult;
|
||||
extern NSString *DPSVMerror;
|
||||
|
||||
#endif /* _GSContext_h_INCLUDE */
|
||||
|
86
Headers/gsc/GSGState.h
Normal file
86
Headers/gsc/GSGState.h
Normal file
|
@ -0,0 +1,86 @@
|
|||
/* GSGState - Implements generic graphic state drawing for non-PS backends
|
||||
|
||||
Copyright (C) 1995 Free Software Foundation, Inc.
|
||||
|
||||
Written by: Adam Fedor <fedor@boulder.colorado.edu>
|
||||
Date: Nov 1995
|
||||
Extracted from XGPS: Fred Kiefer <FredKiefer@gmx.de>
|
||||
Date: March 2002
|
||||
|
||||
This file is part of the GNU Objective C User Interface Library.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
|
||||
*/
|
||||
|
||||
#ifndef _GSGState_h_INCLUDE
|
||||
#define _GSGState_h_INCLUDE
|
||||
|
||||
#include <AppKit/NSGraphicsContext.h> // needed for NSCompositingOperation
|
||||
#include <Foundation/NSArray.h>
|
||||
#include <Foundation/NSObject.h>
|
||||
|
||||
@class NSAffineTransform;
|
||||
@class NSBezierPath;
|
||||
@class NSFont;
|
||||
@class GSContext;
|
||||
|
||||
typedef enum {
|
||||
path_stroke, path_fill, path_eofill, path_clip, path_eoclip
|
||||
} ctxt_object_t;
|
||||
|
||||
@interface GSGState : NSObject
|
||||
{
|
||||
@public
|
||||
GSContext *drawcontext;
|
||||
NSAffineTransform *ctm;
|
||||
NSPoint offset; /* Offset from Drawable origin */
|
||||
NSBezierPath *path; /* current path */
|
||||
NSFont *font;
|
||||
|
||||
BOOL viewIsFlipped;
|
||||
}
|
||||
|
||||
- initWithDrawContext: (GSContext *)context;
|
||||
- deepen;
|
||||
|
||||
- (void) setOffset: (NSPoint)theOffset;
|
||||
- (NSPoint) offset;
|
||||
|
||||
- (void) setFont: (NSFont*)font;
|
||||
- (NSFont*) currentFont;
|
||||
|
||||
- (void) compositeGState: (GSGState *)source
|
||||
fromRect: (NSRect)aRect
|
||||
toPoint: (NSPoint)aPoint
|
||||
op: (NSCompositingOperation)op;
|
||||
|
||||
- (void) dissolveGState: (GSGState *)source
|
||||
fromRect: (NSRect)aRect
|
||||
toPoint: (NSPoint)aPoint
|
||||
delta: (float)delta;
|
||||
|
||||
- (void) compositerect: (NSRect)aRect
|
||||
op: (NSCompositingOperation)op;
|
||||
|
||||
- (NSPoint) pointInMatrixSpace: (NSPoint)point;
|
||||
- (NSPoint) deltaPointInMatrixSpace: (NSPoint)point;
|
||||
- (NSRect) rectInMatrixSpace: (NSRect)rect;
|
||||
|
||||
@end
|
||||
|
||||
#include "GSGStateOps.h"
|
||||
|
||||
#endif /* _GSGState_h_INCLUDE */
|
||||
|
137
Headers/gsc/GSGStateOps.h
Normal file
137
Headers/gsc/GSGStateOps.h
Normal file
|
@ -0,0 +1,137 @@
|
|||
/* GSGStateOPS - Ops for GSGState
|
||||
|
||||
Copyright (C) 1998 Free Software Foundation, Inc.
|
||||
|
||||
Written by: Adam Fedor <fedor@gnu.org>
|
||||
Date: Nov 1998
|
||||
|
||||
This file is part of the GNU Objective C User Interface Library.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
|
||||
*/
|
||||
|
||||
#ifndef _GSGStateOps_h_INCLUDE
|
||||
#define _GSGStateOps_h_INCLUDE
|
||||
|
||||
@interface GSGState (Ops)
|
||||
/* ----------------------------------------------------------------------- */
|
||||
/* Color operations */
|
||||
/* ----------------------------------------------------------------------- */
|
||||
- (void) DPScurrentalpha: (float*)a;
|
||||
- (void) DPScurrentcmykcolor: (float*)c : (float*)m : (float*)y : (float*)k;
|
||||
- (void) DPScurrentgray: (float*)gray;
|
||||
- (void) DPScurrenthsbcolor: (float*)h : (float*)s : (float*)b;
|
||||
- (void) DPScurrentrgbcolor: (float*)r : (float*)g : (float*)b;
|
||||
- (void) DPSsetalpha: (float)a;
|
||||
- (void) DPSsetcmykcolor: (float)c : (float)m : (float)y : (float)k;
|
||||
- (void) DPSsetgray: (float)gray;
|
||||
- (void) DPSsethsbcolor: (float)h : (float)s : (float)b;
|
||||
- (void) DPSsetrgbcolor: (float)r : (float)g : (float)b;
|
||||
|
||||
- (void) GSSetFillColorspace: (NSDictionary *)dict;
|
||||
- (void) GSSetStrokeColorspace: (NSDictionary *)dict;
|
||||
- (void) GSSetFillColor: (float *)values;
|
||||
- (void) GSSetStrokeColor: (float *)values;
|
||||
|
||||
/* ----------------------------------------------------------------------- */
|
||||
/* Text operations */
|
||||
/* ----------------------------------------------------------------------- */
|
||||
- (void) DPSashow: (float)x : (float)y : (const char*)s;
|
||||
- (void) DPSawidthshow: (float)cx : (float)cy : (int)c : (float)ax : (float)ay
|
||||
: (const char*)s;
|
||||
- (void) DPScharpath: (const char*)s : (int)b;
|
||||
- (void) DPSshow: (const char*)s;
|
||||
- (void) DPSwidthshow: (float)x : (float)y : (int)c : (const char*)s;
|
||||
- (void) DPSxshow: (const char*)s : (const float*)numarray : (int)size;
|
||||
- (void) DPSxyshow: (const char*)s : (const float*)numarray : (int)size;
|
||||
- (void) DPSyshow: (const char*)s : (const float*)numarray : (int)size;
|
||||
|
||||
/* ----------------------------------------------------------------------- */
|
||||
/* Gstate operations */
|
||||
/* ----------------------------------------------------------------------- */
|
||||
- (void) DPSinitgraphics;
|
||||
|
||||
- (void) DPScurrentflat: (float*)flatness;
|
||||
- (void) DPScurrentlinecap: (int*)linecap;
|
||||
- (void) DPScurrentlinejoin: (int*)linejoin;
|
||||
- (void) DPScurrentlinewidth: (float*)width;
|
||||
- (void) DPScurrentmiterlimit: (float*)limit;
|
||||
- (void) DPScurrentpoint: (float*)x : (float*)y;
|
||||
- (void) DPScurrentstrokeadjust: (int*)b;
|
||||
- (void) DPSsetdash: (const float*)pat : (int)size : (float)offset;
|
||||
- (void) DPSsetflat: (float)flatness;
|
||||
- (void) DPSsetlinecap: (int)linecap;
|
||||
- (void) DPSsetlinejoin: (int)linejoin;
|
||||
- (void) DPSsetlinewidth: (float)width;
|
||||
- (void) DPSsetmiterlimit: (float)limit;
|
||||
- (void) DPSsetstrokeadjust: (int)b;
|
||||
|
||||
/* ----------------------------------------------------------------------- */
|
||||
/* Matrix operations */
|
||||
/* ----------------------------------------------------------------------- */
|
||||
- (void) DPSconcat: (const float*)m;
|
||||
- (void) DPSinitmatrix;
|
||||
- (void) DPSrotate: (float)angle;
|
||||
- (void) DPSscale: (float)x : (float)y;
|
||||
- (void) DPStranslate: (float)x : (float)y;
|
||||
|
||||
- (NSAffineTransform *) GSCurrentCTM;
|
||||
- (void) GSSetCTM: (NSAffineTransform *)ctm;
|
||||
- (void) GSConcatCTM: (NSAffineTransform *)ctm;
|
||||
|
||||
/* ----------------------------------------------------------------------- */
|
||||
/* Paint operations */
|
||||
/* ----------------------------------------------------------------------- */
|
||||
- (void) DPSarc: (float)x : (float)y : (float)r : (float)angle1
|
||||
: (float)angle2;
|
||||
- (void) DPSarcn: (float)x : (float)y : (float)r : (float)angle1
|
||||
: (float)angle2;
|
||||
- (void) DPSarct: (float)x1 : (float)y1 : (float)x2 : (float)y2 : (float)r;
|
||||
- (void) DPSclip;
|
||||
- (void) DPSclosepath;
|
||||
- (void) DPScurveto: (float)x1 : (float)y1 : (float)x2 : (float)y2
|
||||
: (float)x3 : (float)y3;
|
||||
- (void) DPSeoclip;
|
||||
- (void) DPSeofill;
|
||||
- (void) DPSfill;
|
||||
- (void) DPSflattenpath;
|
||||
- (void) DPSinitclip;
|
||||
- (void) DPSlineto: (float)x : (float)y;
|
||||
- (void) DPSmoveto: (float)x : (float)y;
|
||||
- (void) DPSnewpath;
|
||||
- (void) DPSpathbbox: (float*)llx : (float*)lly : (float*)urx : (float*)ury;
|
||||
- (void) DPSrcurveto: (float)x1 : (float)y1 : (float)x2 : (float)y2
|
||||
: (float)x3 : (float)y3;
|
||||
- (void) DPSrectclip: (float)x : (float)y : (float)w : (float)h;
|
||||
- (void) DPSrectfill: (float)x : (float)y : (float)w : (float)h;
|
||||
- (void) DPSrectstroke: (float)x : (float)y : (float)w : (float)h;
|
||||
- (void) DPSreversepath;
|
||||
- (void) DPSrlineto: (float)x : (float)y;
|
||||
- (void) DPSrmoveto: (float)x : (float)y;
|
||||
- (void) DPSstroke;
|
||||
|
||||
- (void) GSSendBezierPath: (NSBezierPath *)path;
|
||||
- (void) GSRectFillList: (const NSRect *)rects : (int) count;
|
||||
|
||||
- (void)DPSimage: (NSAffineTransform*) matrix
|
||||
: (int) pixelsWide : (int) pixelsHigh
|
||||
: (int) bitsPerSample : (int) samplesPerPixel
|
||||
: (int) bitsPerPixel : (int) bytesPerRow : (BOOL) isPlanar
|
||||
: (BOOL) hasAlpha : (NSString *) colorSpaceName
|
||||
: (const unsigned char *const [5]) data;
|
||||
|
||||
@end
|
||||
|
||||
#endif
|
42
Headers/gsc/GSStreamContext.h
Normal file
42
Headers/gsc/GSStreamContext.h
Normal file
|
@ -0,0 +1,42 @@
|
|||
/* GSStreamContext - Output Postscript to a stream
|
||||
|
||||
Copyright (C) 1999 Free Software Foundation, Inc.
|
||||
|
||||
Written by: Adam Fedor <fedor@gnu.org>
|
||||
Date: Mar 1999
|
||||
|
||||
This file is part of the GNU Objective C User Interface library.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
|
||||
*/
|
||||
|
||||
#ifndef _GSStreamContext_h_INCLUDE
|
||||
#define _GSStreamContext_h_INCLUDE
|
||||
|
||||
#include <stdio.h>
|
||||
#include <AppKit/NSGraphicsContext.h>
|
||||
|
||||
@class GSGState;
|
||||
|
||||
@interface GSStreamContext : NSGraphicsContext
|
||||
{
|
||||
FILE *gstream;
|
||||
}
|
||||
|
||||
- (GSGState *) currentGState;
|
||||
|
||||
@end
|
||||
|
||||
#endif /* _GSStreamContext_h_INCLUDE */
|
112
Headers/x11/StdCmap.h
Normal file
112
Headers/x11/StdCmap.h
Normal file
|
@ -0,0 +1,112 @@
|
|||
/* $XConsortium: StdCmap.h,v 1.4 94/04/17 20:16:15 converse Exp $ */
|
||||
|
||||
/*
|
||||
|
||||
Copyright (c) 1988 X Consortium
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
||||
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
Except as contained in this notice, the name of the X Consortium shall not be
|
||||
used in advertising or otherwise to promote the sale, use or other dealings
|
||||
in this Software without prior written authorization from the X Consortium.
|
||||
|
||||
*/
|
||||
|
||||
/*
|
||||
* The interfaces described by this header file are for miscellaneous utilities
|
||||
* and are not part of the Xlib standard.
|
||||
*/
|
||||
|
||||
#ifndef _XMU_STDCMAP_H_
|
||||
#define _XMU_STDCMAP_H_
|
||||
|
||||
#include <X11/Xfuncproto.h>
|
||||
|
||||
_XFUNCPROTOBEGIN
|
||||
|
||||
Status XmuAllStandardColormaps(
|
||||
#if NeedFunctionPrototypes
|
||||
Display* /* dpy */
|
||||
#endif
|
||||
);
|
||||
|
||||
Status XmuCreateColormap(
|
||||
#if NeedFunctionPrototypes
|
||||
Display* /* dpy */,
|
||||
XStandardColormap* /* colormap */
|
||||
#endif
|
||||
);
|
||||
|
||||
void XmuDeleteStandardColormap(
|
||||
#if NeedFunctionPrototypes
|
||||
Display* /* dpy */,
|
||||
int /* screen */,
|
||||
Atom /* property */
|
||||
#endif
|
||||
);
|
||||
|
||||
Status XmuGetColormapAllocation(
|
||||
#if NeedFunctionPrototypes
|
||||
XVisualInfo* /* vinfo */,
|
||||
Atom /* property */,
|
||||
unsigned long* /* red_max_return */,
|
||||
unsigned long* /* green_max_return */,
|
||||
unsigned long* /* blue_max_return */
|
||||
#endif
|
||||
);
|
||||
|
||||
Status XmuLookupStandardColormap(
|
||||
#if NeedFunctionPrototypes
|
||||
Display* /* dpy */,
|
||||
int /* screen */,
|
||||
VisualID /* visualid */,
|
||||
unsigned int /* depth */,
|
||||
Atom /* property */,
|
||||
Bool /* replace */,
|
||||
Bool /* retain */
|
||||
#endif
|
||||
);
|
||||
|
||||
XStandardColormap *XmuStandardColormap(
|
||||
#if NeedFunctionPrototypes
|
||||
Display* /* dpy */,
|
||||
int /* screen */,
|
||||
VisualID /* visualid */,
|
||||
unsigned int /* depth */,
|
||||
Atom /* property */,
|
||||
Colormap /* cmap */,
|
||||
unsigned long /* red_max */,
|
||||
unsigned long /* green_max */,
|
||||
unsigned long /* blue_max */
|
||||
#endif
|
||||
);
|
||||
|
||||
Status XmuVisualStandardColormaps(
|
||||
#if NeedFunctionPrototypes
|
||||
Display* /* dpy */,
|
||||
int /* screen */,
|
||||
VisualID /* visualid */,
|
||||
unsigned int /* depth */,
|
||||
Bool /* replace */,
|
||||
Bool /* retain */
|
||||
#endif
|
||||
);
|
||||
|
||||
_XFUNCPROTOEND
|
||||
|
||||
#endif /* _XMU_STDCMAP_H_ */
|
120
Headers/x11/XGDragView.h
Normal file
120
Headers/x11/XGDragView.h
Normal file
|
@ -0,0 +1,120 @@
|
|||
/* -*- mode: ObjC -*-
|
||||
<title>XGDragView</title>
|
||||
|
||||
<abstract>View that is dragged during drag and drop</abstract>
|
||||
|
||||
Written By: <author name="Wim Oudshoorn"><email>woudshoo@xs4all.nl</email></author>
|
||||
Date: Nov 2001
|
||||
|
||||
This file is part of the GNU Objective C User Interface library.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
|
||||
*/
|
||||
|
||||
#include <AppKit/NSCell.h>
|
||||
#include <AppKit/NSEvent.h>
|
||||
#include <Foundation/NSGeometry.h>
|
||||
#include "x11/xdnd.h"
|
||||
#include "x11/XGServerWindow.h"
|
||||
|
||||
/*"
|
||||
Drag and drop support functions
|
||||
"*/
|
||||
|
||||
void GSEnsureDndIsInitialized (void);
|
||||
DndClass xdnd (void);
|
||||
Atom GSActionForDragOperation(unsigned int op);
|
||||
NSDragOperation GSDragOperationForAction(Atom xaction);
|
||||
|
||||
|
||||
/*
|
||||
used in the operation mask to indicate that the
|
||||
user can not change the drag action by
|
||||
pressing modifiers.
|
||||
*/
|
||||
|
||||
#define NSDragOperationIgnoresModifiers 0xffff
|
||||
|
||||
/*"
|
||||
WRO (notes made 18 Nov 2001)
|
||||
|
||||
The object that is dragged over the screen.
|
||||
It hijacks the event loop and manages the complete
|
||||
drag and drop sequence.
|
||||
"*/
|
||||
@interface XGDragView : NSView <NSDraggingInfo>
|
||||
{
|
||||
|
||||
NSCell *dragCell; /*" the graphics that is dragged"*/
|
||||
NSPasteboard *dragPasteboard;
|
||||
NSPoint dragPoint; /*" in base coordinates, only valid when dragWindow != nil "*/
|
||||
gswindow_device_t *dragWindev;
|
||||
|
||||
/* information used in the drag and drop event loop */
|
||||
NSPoint offset; /*" offset of image w.r.t. cursor "*/
|
||||
NSPoint dragPosition; /*" in screen coordinates "*/
|
||||
NSPoint newPosition; /*" position, not yet processed "*/
|
||||
int wx, wy; /*" position of image in X-coordinates "*/
|
||||
Window targetWindow; /*" XWindow that is the current drag target "*/
|
||||
|
||||
int dragSequence;
|
||||
id dragSource;
|
||||
|
||||
unsigned int dragMask; /*" Operations supported by the source "*/
|
||||
unsigned int operationMask; /*" user specified operation mask (key modifiers).
|
||||
this is either a mask of type _NSDragOperation,
|
||||
or NSDragOperationIgnoresModifiers, which
|
||||
is defined as 0xffff "*/
|
||||
unsigned int targetMask; /*" Operations supported by the target, only valid if
|
||||
targetIsDndAware is true "*/
|
||||
|
||||
id dragWindow; /*" NSWindow in this application that is the current target "*/
|
||||
Atom *typelist;
|
||||
BOOL dragExternal; /*" YES if target and source are in a different application "*/
|
||||
BOOL isDragging; /*" Yes if we are currently dragging "*/
|
||||
BOOL slideBack; /*" slide back when drag fails? "*/
|
||||
NSMutableDictionary *cursors;
|
||||
}
|
||||
|
||||
+ (XGDragView*) sharedDragView;
|
||||
|
||||
- (BOOL) isDragging;
|
||||
|
||||
- (void) setupDragInfoFromXEvent: (XEvent *)xEvent;
|
||||
- (void) updateDragInfoFromEvent: (NSEvent *)event;
|
||||
- (void) resetDragInfo;
|
||||
- (void) _sendLocalEvent: (GSAppKitSubtype)subtype
|
||||
action: (NSDragOperation)action
|
||||
position: (NSPoint)eventLocation
|
||||
timestamp: (NSTimeInterval)time
|
||||
toWindow: (NSWindow*)dWindow;
|
||||
- (void) dragImage: (NSImage*)anImage
|
||||
at: (NSPoint)screenLocation
|
||||
offset: (NSSize)initialOffset
|
||||
event: (NSEvent*)event
|
||||
pasteboard: (NSPasteboard*)pboard
|
||||
source: (id)sourceObject
|
||||
slideBack: (BOOL)slideFlag;
|
||||
- (void) postDragEvent: (NSEvent *)theEvent;
|
||||
- (void) _setCursor;
|
||||
- (void) _handleDrag: (NSEvent*)theEvent;
|
||||
- (void) _handleEventDuringDragging: (NSEvent*) theEvent;
|
||||
- (void) _updateAndMoveImageToCorrectPosition;
|
||||
- (void) _moveDraggedImageToNewPosition;
|
||||
- (void) _slideDraggedImageTo: (NSPoint)screenPoint
|
||||
numberOfSteps: (int) steps
|
||||
waitAfterSlide: (BOOL) waitFlag;
|
||||
- (Window) _xWindowAcceptingDnDunderX: (int) x Y: (int) y;
|
||||
@end
|
99
Headers/x11/XGGeneric.h
Normal file
99
Headers/x11/XGGeneric.h
Normal file
|
@ -0,0 +1,99 @@
|
|||
/* Generic header info common to X backends for GNUstep
|
||||
|
||||
Copyright (C) 2000 Free Software Foundation, Inc.
|
||||
|
||||
Written by: Richard Frith-Macdonald <rfm@gnu.org>
|
||||
Date: Mar 2000
|
||||
|
||||
This file is part of the GNUstep project
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
|
||||
*/
|
||||
|
||||
#ifndef INCLUDED_XGGENERIC_H
|
||||
#define INCLUDED_XGGENERIC_H
|
||||
|
||||
/*
|
||||
* Flags to indicate which protocols the WindowManager follows
|
||||
*/
|
||||
typedef enum {
|
||||
XGWM_UNKNOWN = 0,
|
||||
XGWM_WINDOWMAKER = 1,
|
||||
XGWM_GNOME = 2,
|
||||
XGWM_KDE = 4,
|
||||
XGWM_EWMH = 8
|
||||
} XGWMProtocols;
|
||||
|
||||
typedef struct {
|
||||
Atom win_type_atom;
|
||||
Atom win_desktop_atom;
|
||||
Atom win_normal_atom;
|
||||
Atom win_floating_atom;
|
||||
Atom win_menu_atom;
|
||||
Atom win_dock_atom;
|
||||
Atom win_modal_atom;
|
||||
} XGWMWinTypes;
|
||||
|
||||
/*
|
||||
* Structure containing ivars that are common to all X backend contexts.
|
||||
*/
|
||||
struct XGGeneric {
|
||||
int wm;
|
||||
struct {
|
||||
unsigned useWindowMakerIcons:1;
|
||||
unsigned borderedBorderless:1;
|
||||
unsigned doubleParentWindow:1;
|
||||
} flags;
|
||||
Time lastTime;
|
||||
Time lastClick;
|
||||
Window lastClickWindow;
|
||||
int lastClickX;
|
||||
int lastClickY;
|
||||
Time lastMotion;
|
||||
Atom protocols_atom;
|
||||
Atom delete_win_atom;
|
||||
Atom take_focus_atom;
|
||||
Atom miniaturize_atom;
|
||||
Atom win_decor_atom;
|
||||
Atom titlebar_state_atom;
|
||||
char *rootName;
|
||||
long currentFocusWindow;
|
||||
long desiredFocusWindow;
|
||||
long focusRequestNumber;
|
||||
unsigned char lMouse;
|
||||
unsigned char mMouse;
|
||||
unsigned char rMouse;
|
||||
unsigned char upMouse;
|
||||
unsigned char downMouse;
|
||||
int lMouseMask;
|
||||
int mMouseMask;
|
||||
int rMouseMask;
|
||||
Window appRootWindow;
|
||||
void *cachedWindow; // last gswindow_device_t used.
|
||||
XPoint parent_offset; // WM defined parent info
|
||||
XGWMWinTypes wintypes;
|
||||
};
|
||||
|
||||
/* GNOME Window layers */
|
||||
#define WIN_LAYER_DESKTOP 0
|
||||
#define WIN_LAYER_BELOW 2
|
||||
#define WIN_LAYER_NORMAL 4
|
||||
#define WIN_LAYER_ONTOP 6
|
||||
#define WIN_LAYER_DOCK 8
|
||||
#define WIN_LAYER_ABOVE_DOCK 10
|
||||
#define WIN_LAYER_MENU 12
|
||||
|
||||
#endif
|
||||
|
57
Headers/x11/XGInputServer.h
Normal file
57
Headers/x11/XGInputServer.h
Normal file
|
@ -0,0 +1,57 @@
|
|||
/* XGInputServer - Keyboard input handling
|
||||
|
||||
Copyright (C) 2002 Free Software Foundation, Inc.
|
||||
|
||||
Author: Adam Fedor <fedor@gnu.org>
|
||||
Date: January 2002
|
||||
|
||||
This file is part of the GNUstep GUI Library.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; see the file COPYING.LIB.
|
||||
If not, write to the Free Software Foundation,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef _GNUstep_H_XGInputServer
|
||||
#define _GNUstep_H_XGInputServer
|
||||
|
||||
#include <AppKit/NSInputServer.h>
|
||||
#include <x11/XGServerWindow.h>
|
||||
|
||||
@protocol XInputFiltering
|
||||
- (BOOL) filterEvent: (XEvent *)event;
|
||||
- (NSString *) lookupStringForEvent: (XKeyEvent *)event
|
||||
window: (gswindow_device_t *)window
|
||||
keysym: (KeySym *)keysymptr;
|
||||
@end
|
||||
|
||||
|
||||
@interface XIMInputServer: NSInputServer <XInputFiltering>
|
||||
{
|
||||
id delegate;
|
||||
NSString *server_name;
|
||||
XIM xim;
|
||||
XIMStyle xim_style;
|
||||
NSMutableData *dbuf;
|
||||
NSStringEncoding encoding;
|
||||
}
|
||||
|
||||
- (id) initWithDelegate: (id)aDelegate
|
||||
display: (Display *)dpy
|
||||
name: (NSString *)name;
|
||||
- (void) ximFocusICWindow: (gswindow_device_t *)windev;
|
||||
- (void) ximCloseIC: (XIC)xic;
|
||||
@end
|
||||
|
||||
#endif
|
85
Headers/x11/XGServer.h
Normal file
85
Headers/x11/XGServer.h
Normal file
|
@ -0,0 +1,85 @@
|
|||
/* <title>XGServer</title>
|
||||
|
||||
<abstract>Backend server using the X11.</abstract>
|
||||
|
||||
Copyright (C) 2002 Free Software Foundation, Inc.
|
||||
|
||||
Author: Adam Fedor <fedor@gnu.org>
|
||||
Date: Mar 2002
|
||||
|
||||
This file is part of the GNUstep Backend.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
|
||||
*/
|
||||
|
||||
#ifndef _XGServer_h_INCLUDE
|
||||
#define _XGServer_h_INCLUDE
|
||||
|
||||
#include <AppKit/GSDisplayServer.h>
|
||||
#include <X11/Xatom.h>
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xutil.h>
|
||||
#include "x11/XGGeneric.h"
|
||||
|
||||
/*
|
||||
* Enumerated type to say how we should draw pixels to the X display - used
|
||||
* to select different drawing mechanisms to try to optimise.
|
||||
*/
|
||||
typedef enum {
|
||||
XGDM_FAST15,
|
||||
XGDM_FAST16,
|
||||
XGDM_FAST32,
|
||||
XGDM_FAST32_BGR,
|
||||
XGDM_PORTABLE
|
||||
} XGDrawMechanism;
|
||||
|
||||
@interface XGServer : GSDisplayServer
|
||||
{
|
||||
@public
|
||||
void *context;
|
||||
Window grabWindow;
|
||||
XGDrawMechanism drawMechanism;
|
||||
struct XGGeneric generic;
|
||||
id inputServer;
|
||||
}
|
||||
|
||||
+ (Display*) currentXDisplay;
|
||||
- (XGDrawMechanism) drawMechanism;
|
||||
- (Display*)xDisplay;
|
||||
- (Window)xDisplayRootWindow;
|
||||
- (Window)xAppRootWindow;
|
||||
|
||||
- (XColor)xColorFromColor: (XColor)color;
|
||||
|
||||
- (void *) xrContext;
|
||||
|
||||
+ (void) waitAllContexts;
|
||||
@end
|
||||
|
||||
/*
|
||||
* Synchronize with X event queue - soak up events.
|
||||
* Waits for up to 1 second for event.
|
||||
*/
|
||||
@interface XGServer (XSync)
|
||||
- (BOOL) xSyncMap: (void*)window;
|
||||
@end
|
||||
|
||||
@interface XGServer (XGGeneric)
|
||||
- (NSRect) _OSFrameToXFrame: (NSRect)o for: (void*)window;
|
||||
- (NSRect) _OSFrameToXHints: (NSRect)o for: (void*)window;
|
||||
- (NSRect) _XFrameToOSFrame: (NSRect)x for: (void*)window;
|
||||
@end
|
||||
|
||||
#endif /* _XGServer_h_INCLUDE */
|
112
Headers/x11/XGServerWindow.h
Normal file
112
Headers/x11/XGServerWindow.h
Normal file
|
@ -0,0 +1,112 @@
|
|||
/* Window ops for X11 server
|
||||
|
||||
Copyright (C) 1999 Free Software Foundation, Inc.
|
||||
|
||||
Written by: Adam Fedor <fedor@gnu.org>
|
||||
Date: Nov 1999
|
||||
|
||||
This file is part of the GNU Objective C User Interface library.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
|
||||
*/
|
||||
|
||||
#ifndef _XGServerWindow_h_INCLUDE
|
||||
#define _XGServerWindow_h_INCLUDE
|
||||
|
||||
#define BOOL XWINDOWSBOOL // prevent X windows BOOL
|
||||
#include <X11/Xmd.h> // warning
|
||||
#undef BOOL
|
||||
#include <x11/XGServer.h>
|
||||
|
||||
//
|
||||
// WindowMaker window manager interaction
|
||||
//
|
||||
typedef struct {
|
||||
CARD32 flags;
|
||||
CARD32 window_style;
|
||||
CARD32 window_level;
|
||||
CARD32 reserved;
|
||||
Pixmap miniaturize_pixmap; // pixmap for miniaturize button
|
||||
Pixmap close_pixmap; // pixmap for close button
|
||||
Pixmap miniaturize_mask; // miniaturize pixmap mask
|
||||
Pixmap close_mask; // close pixmap mask
|
||||
CARD32 extra_flags;
|
||||
} GNUstepWMAttributes;
|
||||
|
||||
#define GSWindowStyleAttr (1<<0)
|
||||
#define GSWindowLevelAttr (1<<1)
|
||||
#define GSMiniaturizePixmapAttr (1<<3)
|
||||
#define GSClosePixmapAttr (1<<4)
|
||||
#define GSMiniaturizeMaskAttr (1<<5)
|
||||
#define GSCloseMaskAttr (1<<6)
|
||||
#define GSExtraFlagsAttr (1<<7)
|
||||
|
||||
#define GSDocumentEditedFlag (1<<0)
|
||||
#define GSWindowWillResizeNotificationsFlag (1<<1)
|
||||
#define GSWindowWillMoveNotificationsFlag (1<<2)
|
||||
#define GSNoApplicationIconFlag (1<<5)
|
||||
#define WMFHideOtherApplications 10
|
||||
#define WMFHideApplication 12
|
||||
|
||||
typedef struct _gswindow_device_t {
|
||||
Display *display;
|
||||
Window ident;
|
||||
Window root;
|
||||
Window parent;
|
||||
int screen;
|
||||
GC gc;
|
||||
long number;
|
||||
int depth;
|
||||
int border;
|
||||
int map_state;
|
||||
int visibility;
|
||||
NSBackingStoreType type;
|
||||
NSRect xframe;
|
||||
Drawable buffer;
|
||||
Drawable alpha_buffer;
|
||||
BOOL is_exposed;
|
||||
NSMutableArray *exposedRects;
|
||||
Region region; // Used between several expose events
|
||||
XWMHints gen_hints;
|
||||
XSizeHints siz_hints;
|
||||
GNUstepWMAttributes win_attrs;
|
||||
XSetWindowAttributes xwn_attrs;
|
||||
int xoff;
|
||||
int yoff;
|
||||
int boff;
|
||||
Atom protocols[4];
|
||||
int numProtocols;
|
||||
XIC ic;
|
||||
} gswindow_device_t;
|
||||
|
||||
#define GET_XDRAWABLE(win) ((win)->buffer ? (win)->buffer: (win)->ident)
|
||||
|
||||
@interface XGServer (DPSWindow)
|
||||
+ (gswindow_device_t *) _windowForXWindow: (Window)xWindow;
|
||||
+ (gswindow_device_t *) _windowForXParent: (Window)xWindow;
|
||||
+ (gswindow_device_t *) _windowWithTag: (int)windowNumber;
|
||||
- (void) _addExposedRectangle: (XRectangle)rectangle : (int)win;
|
||||
- (void) _processExposedRectangles: (int)win;
|
||||
- (void) _initializeCursorForXWindow: (Window) win;
|
||||
- (void) _destroyServerWindows;
|
||||
|
||||
/* This needs to go in GSDisplayServer */
|
||||
- (void) _DPSsetcursor: (Cursor)c : (BOOL)set;
|
||||
@end
|
||||
|
||||
extern Pixmap
|
||||
xgps_cursor_mask(Display *xdpy, Drawable draw, const char *data,
|
||||
int w, int h, int colors);
|
||||
#endif
|
43
Headers/x11/XGSlideView.h
Normal file
43
Headers/x11/XGSlideView.h
Normal file
|
@ -0,0 +1,43 @@
|
|||
/** -*- mode: ObjC -*-
|
||||
<title>XGSlideView</title>
|
||||
|
||||
<abstract>View that is slid by NSWorkspace</abstract>
|
||||
|
||||
Copyright (C) 2002 Free Software Foundation, Inc.
|
||||
|
||||
Written By: <author name="Enrico Sersale"><email>enrico@imago.ro</email></author>
|
||||
Date: Jan 2002
|
||||
|
||||
This file is part of the GNU Objective C User Interface library.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
|
||||
*/
|
||||
|
||||
#include <AppKit/NSView.h>
|
||||
#include <Foundation/NSGeometry.h>
|
||||
#include "x11/XGServerWindow.h"
|
||||
|
||||
@class NSCell;
|
||||
|
||||
@interface XGSlideView : NSView
|
||||
{
|
||||
NSCell *slideCell;
|
||||
gswindow_device_t *slideWindev;
|
||||
}
|
||||
|
||||
+ (BOOL) _slideImage: (NSImage*)image
|
||||
from: (NSPoint)fromPoint
|
||||
to: (NSPoint)toPoint;
|
||||
@end
|
459
Headers/x11/wraster.h
Normal file
459
Headers/x11/wraster.h
Normal file
|
@ -0,0 +1,459 @@
|
|||
/*
|
||||
* Raster graphics library
|
||||
*
|
||||
* Copyright (c) 1997 ~ 2000 Alfredo K. Kojima
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free
|
||||
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Environment variables:
|
||||
*
|
||||
* WRASTER_GAMMA <rgamma>/<ggamma>/<bgamma>
|
||||
* gamma correction value. Must be greater than 0
|
||||
* Only for PseudoColor visuals.
|
||||
*
|
||||
* Default:
|
||||
* WRASTER_GAMMA 1/1/1
|
||||
*
|
||||
*
|
||||
* If you want a specific value for a screen, append the screen number
|
||||
* preceded by a hash to the variable name as in
|
||||
* WRASTER_GAMMA#1
|
||||
* for screen number 1
|
||||
*/
|
||||
|
||||
#ifndef RLRASTER_H_
|
||||
#define RLRASTER_H_
|
||||
|
||||
|
||||
/* version of the header for the library: 0.20 */
|
||||
#define WRASTER_HEADER_VERSION 20
|
||||
|
||||
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xutil.h>
|
||||
|
||||
#ifdef XSHM
|
||||
#include <X11/extensions/XShm.h>
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/* RBestMatchRendering or RDitheredRendering */
|
||||
#define RC_RenderMode (1<<0)
|
||||
|
||||
/* number of colors per channel for colormap in PseudoColor mode */
|
||||
#define RC_ColorsPerChannel (1<<1)
|
||||
|
||||
/* do gamma correction */
|
||||
#define RC_GammaCorrection (1<<2)
|
||||
|
||||
/* visual id to use */
|
||||
#define RC_VisualID (1<<3)
|
||||
|
||||
/* shared memory usage */
|
||||
#define RC_UseSharedMemory (1<<4)
|
||||
|
||||
/* use default instead of best visual */
|
||||
#define RC_DefaultVisual (1<<5)
|
||||
|
||||
/* filter type for smoothed scaling */
|
||||
#define RC_ScalingFilter (1<<6)
|
||||
|
||||
/* standard colormap usage */
|
||||
#define RC_StandardColormap (1<<7)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* std colormap usage/creation modes */
|
||||
enum {
|
||||
RUseStdColormap, /* default. fallbacks to RIgnore.. if
|
||||
there is none defined */
|
||||
RCreateStdColormap,
|
||||
RIgnoreStdColormap
|
||||
};
|
||||
|
||||
|
||||
|
||||
typedef struct RContextAttributes {
|
||||
int flags;
|
||||
int render_mode;
|
||||
int colors_per_channel; /* for PseudoColor */
|
||||
float rgamma; /* gamma correction for red, */
|
||||
float ggamma; /* green, */
|
||||
float bgamma; /* and blue */
|
||||
VisualID visualid; /* visual ID to use */
|
||||
int use_shared_memory; /* True of False */
|
||||
int scaling_filter;
|
||||
int standard_colormap_mode; /* what to do with std cma */
|
||||
} RContextAttributes;
|
||||
|
||||
|
||||
/*
|
||||
* describes a screen in terms of depth, visual, number of colors
|
||||
* we can use, if we should do dithering, and what colors to use for
|
||||
* dithering.
|
||||
*/
|
||||
typedef struct RContext {
|
||||
Display *dpy;
|
||||
int screen_number;
|
||||
Colormap cmap;
|
||||
|
||||
RContextAttributes *attribs;
|
||||
|
||||
GC copy_gc;
|
||||
|
||||
Visual *visual;
|
||||
int depth;
|
||||
Window drawable; /* window to pass for XCreatePixmap().*/
|
||||
/* generally = root */
|
||||
int vclass;
|
||||
|
||||
unsigned long black;
|
||||
unsigned long white;
|
||||
|
||||
int red_offset; /* only used in 24bpp */
|
||||
int green_offset;
|
||||
int blue_offset;
|
||||
|
||||
/* only used for pseudocolor and grayscale */
|
||||
|
||||
XStandardColormap *std_rgb_map; /* standard RGB colormap */
|
||||
XStandardColormap *std_gray_map; /* standard grayscale colormap */
|
||||
|
||||
int ncolors; /* total number of colors we can use */
|
||||
XColor *colors; /* internal colormap */
|
||||
unsigned long *pixels; /* RContext->colors[].pixel */
|
||||
|
||||
struct {
|
||||
unsigned int use_shared_pixmap:1;
|
||||
unsigned int optimize_for_speed:1;
|
||||
} flags;
|
||||
} RContext;
|
||||
|
||||
|
||||
typedef struct RColor {
|
||||
unsigned char red;
|
||||
unsigned char green;
|
||||
unsigned char blue;
|
||||
unsigned char alpha;
|
||||
} RColor;
|
||||
|
||||
|
||||
typedef struct RHSVColor {
|
||||
unsigned short hue; /* 0-359 */
|
||||
unsigned char saturation; /* 0-255 */
|
||||
unsigned char value; /* 0-255 */
|
||||
} RHSVColor;
|
||||
|
||||
|
||||
|
||||
typedef struct RPoint {
|
||||
int x, y;
|
||||
} RPoint;
|
||||
|
||||
|
||||
typedef struct RSegment {
|
||||
int x1, y1, x2, y2;
|
||||
} RSegment;
|
||||
|
||||
|
||||
|
||||
/* image formats */
|
||||
enum RImageFormat {
|
||||
RRGBFormat,
|
||||
RRGBAFormat
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* internal 24bit+alpha image representation
|
||||
*/
|
||||
typedef struct RImage {
|
||||
unsigned char *data; /* image data RGBA or RGB */
|
||||
unsigned width, height; /* size of the image */
|
||||
enum RImageFormat format;
|
||||
RColor background; /* background color */
|
||||
} RImage;
|
||||
|
||||
|
||||
/*
|
||||
* internal wrapper for XImage. Used for shm abstraction
|
||||
*/
|
||||
typedef struct RXImage {
|
||||
XImage *image;
|
||||
|
||||
/* Private data. Do not access */
|
||||
#ifdef XSHM
|
||||
XShmSegmentInfo info;
|
||||
char is_shared;
|
||||
#endif
|
||||
} RXImage;
|
||||
|
||||
|
||||
/* image display modes */
|
||||
enum {
|
||||
RDitheredRendering = 0,
|
||||
RBestMatchRendering = 1
|
||||
};
|
||||
|
||||
|
||||
/* smoothed scaling filter types */
|
||||
enum {
|
||||
RBoxFilter,
|
||||
RTriangleFilter,
|
||||
RBellFilter,
|
||||
RBSplineFilter,
|
||||
RLanczos3Filter,
|
||||
RMitchellFilter
|
||||
};
|
||||
|
||||
|
||||
/* note that not all operations are supported in all functions */
|
||||
enum {
|
||||
RClearOperation, /* clear with 0 */
|
||||
RCopyOperation,
|
||||
RNormalOperation, /* same as combine */
|
||||
RAddOperation,
|
||||
RSubtractOperation
|
||||
};
|
||||
|
||||
|
||||
enum {
|
||||
RAbsoluteCoordinates = 0,
|
||||
RRelativeCoordinates = 1
|
||||
};
|
||||
|
||||
|
||||
enum {
|
||||
RSunkenBevel = -1,
|
||||
RNoBevel = 0,
|
||||
RRaisedBevel = 1
|
||||
};
|
||||
/* bw compat */
|
||||
#define RBEV_SUNKEN RSunkenBevel
|
||||
/* 1 pixel wide */
|
||||
#define RBEV_RAISED RRaisedBevel
|
||||
/* 1 pixel wide on top/left 2 on bottom/right */
|
||||
#define RBEV_RAISED2 2
|
||||
/* 2 pixel width */
|
||||
#define RBEV_RAISED3 3
|
||||
|
||||
enum {
|
||||
RHorizontalGradient = 2,
|
||||
RVerticalGradient = 3,
|
||||
RDiagonalGradient = 4
|
||||
};
|
||||
/* for backwards compatibility */
|
||||
#define RGRD_HORIZONTAL RHorizontalGradient
|
||||
#define RGRD_VERTICAL RVerticalGradient
|
||||
#define RGRD_DIAGONAL RDiagonalGradient
|
||||
|
||||
|
||||
|
||||
/* error codes */
|
||||
#define RERR_NONE 0
|
||||
#define RERR_OPEN 1 /* cant open file */
|
||||
#define RERR_READ 2 /* error reading from file */
|
||||
#define RERR_WRITE 3 /* error writing to file */
|
||||
#define RERR_NOMEMORY 4 /* out of memory */
|
||||
#define RERR_NOCOLOR 5 /* out of color cells */
|
||||
#define RERR_BADIMAGEFILE 6 /* image file is corrupted or invalid */
|
||||
#define RERR_BADFORMAT 7 /* image file format is unknown */
|
||||
#define RERR_BADINDEX 8 /* no such image index in file */
|
||||
|
||||
#define RERR_BADVISUALID 16 /* invalid visual ID requested for context */
|
||||
#define RERR_STDCMAPFAIL 17 /* failed to created std colormap */
|
||||
|
||||
#define RERR_XERROR 127 /* internal X error */
|
||||
#define RERR_INTERNAL 128 /* should not happen */
|
||||
|
||||
|
||||
/*
|
||||
* Returns a NULL terminated array of strings containing the
|
||||
* supported formats, such as: TIFF, XPM, PNG, JPEG, PPM, GIF
|
||||
* Do not free the returned data.
|
||||
*/
|
||||
char **RSupportedFileFormats(void);
|
||||
|
||||
|
||||
char *RGetImageFileFormat(char *file);
|
||||
|
||||
/*
|
||||
* Xlib contexts
|
||||
*/
|
||||
RContext *RCreateContext(Display *dpy, int screen_number,
|
||||
RContextAttributes *attribs);
|
||||
|
||||
void RDestroyContext(RContext *context);
|
||||
|
||||
Bool RGetClosestXColor(RContext *context, RColor *color, XColor *retColor);
|
||||
|
||||
/*
|
||||
* RImage creation
|
||||
*/
|
||||
RImage *RCreateImage(unsigned width, unsigned height, int alpha);
|
||||
|
||||
RImage *RCreateImageFromXImage(RContext *context, XImage *image, XImage *mask);
|
||||
|
||||
RImage *RCreateImageFromDrawable(RContext *context, Drawable drawable,
|
||||
Pixmap mask);
|
||||
|
||||
RImage *RLoadImage(RContext *context, char *file, int index);
|
||||
|
||||
|
||||
void RDestroyImage(RImage *image);
|
||||
|
||||
RImage *RGetImageFromXPMData(RContext *context, char **xpmData);
|
||||
|
||||
/*
|
||||
* RImage storing
|
||||
*/
|
||||
Bool RSaveImage(RImage *image, char *filename, char *format);
|
||||
|
||||
/*
|
||||
* Area manipulation
|
||||
*/
|
||||
RImage *RCloneImage(RImage *image);
|
||||
|
||||
RImage *RGetSubImage(RImage *image, int x, int y, unsigned width,
|
||||
unsigned height);
|
||||
|
||||
void RCombineImageWithColor(RImage *image, RColor *color);
|
||||
|
||||
void RCombineImages(RImage *image, RImage *src);
|
||||
|
||||
void RCombineArea(RImage *image, RImage *src, int sx, int sy, unsigned width,
|
||||
unsigned height, int dx, int dy);
|
||||
|
||||
void RCombineImagesWithOpaqueness(RImage *image, RImage *src, int opaqueness);
|
||||
|
||||
void RCombineAreaWithOpaqueness(RImage *image, RImage *src, int sx, int sy,
|
||||
unsigned width, unsigned height, int dx, int dy,
|
||||
int opaqueness);
|
||||
|
||||
RImage *RScaleImage(RImage *image, unsigned new_width, unsigned new_height);
|
||||
|
||||
RImage *RSmoothScaleImage(RImage *src, unsigned new_width,
|
||||
unsigned new_height);
|
||||
|
||||
RImage *RRotateImage(RImage *image, float angle);
|
||||
|
||||
|
||||
RImage *RMakeTiledImage(RImage *tile, unsigned width, unsigned height);
|
||||
|
||||
RImage* RMakeCenteredImage(RImage *image, unsigned width, unsigned height,
|
||||
RColor *color);
|
||||
|
||||
/*
|
||||
* Drawing
|
||||
*/
|
||||
Bool RGetPixel(RImage *image, int x, int y, RColor *color);
|
||||
|
||||
void RPutPixel(RImage *image, int x, int y, RColor *color);
|
||||
|
||||
void ROperatePixel(RImage *image, int operation, int x, int y, RColor *color);
|
||||
|
||||
void RPutPixels(RImage *image, RPoint *points, int npoints, int mode,
|
||||
RColor *color);
|
||||
|
||||
void ROperatePixels(RImage *image, int operation, RPoint *points,
|
||||
int npoints, int mode, RColor *color);
|
||||
|
||||
int RDrawLine(RImage *image, int x0, int y0, int x1, int y1, RColor *color);
|
||||
|
||||
int ROperateLine(RImage *image, int operation, int x0, int y0, int x1, int y1,
|
||||
RColor *color);
|
||||
|
||||
void RDrawLines(RImage *image, RPoint *points, int npoints, int mode,
|
||||
RColor *color);
|
||||
|
||||
void ROperateLines(RImage *image, int operation, RPoint *points, int npoints,
|
||||
int mode, RColor *color);
|
||||
|
||||
void RDrawSegments(RImage *image, RSegment *segs, int nsegs, RColor *color);
|
||||
|
||||
void ROperateSegments(RImage *image, int operation, RSegment *segs, int nsegs,
|
||||
RColor *color);
|
||||
|
||||
/*
|
||||
* Color convertion
|
||||
*/
|
||||
void RRGBtoHSV(RColor *color, RHSVColor *hsv);
|
||||
void RHSVtoRGB(RHSVColor *hsv, RColor *rgb);
|
||||
|
||||
/*
|
||||
* Painting
|
||||
*/
|
||||
void RClearImage(RImage *image, RColor *color);
|
||||
|
||||
void RFillImage(RImage *image, RColor *color);
|
||||
|
||||
void RBevelImage(RImage *image, int bevel_type);
|
||||
|
||||
RImage *RRenderGradient(unsigned width, unsigned height, RColor *from,
|
||||
RColor *to, int style);
|
||||
|
||||
|
||||
RImage *RRenderMultiGradient(unsigned width, unsigned height, RColor **colors,
|
||||
int style);
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Convertion into X Pixmaps
|
||||
*/
|
||||
int RConvertImage(RContext *context, RImage *image, Pixmap *pixmap);
|
||||
|
||||
int RConvertImageMask(RContext *context, RImage *image, Pixmap *pixmap,
|
||||
Pixmap *mask, int threshold);
|
||||
|
||||
|
||||
/*
|
||||
* misc. utilities
|
||||
*/
|
||||
RXImage *RCreateXImage(RContext *context, int depth,
|
||||
unsigned width, unsigned height);
|
||||
|
||||
RXImage *RGetXImage(RContext *context, Drawable d, int x, int y,
|
||||
unsigned width, unsigned height);
|
||||
|
||||
void RDestroyXImage(RContext *context, RXImage *ximage);
|
||||
|
||||
void RPutXImage(RContext *context, Drawable d, GC gc, RXImage *ximage,
|
||||
int src_x, int src_y, int dest_x, int dest_y,
|
||||
unsigned width, unsigned height);
|
||||
|
||||
/* do not free the returned string! */
|
||||
const char *RMessageForError(int errorCode);
|
||||
|
||||
int RBlurImage(RImage *image);
|
||||
|
||||
/****** Global Variables *******/
|
||||
|
||||
extern int RErrorCode;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif
|
133
Headers/x11/xdnd.h
Normal file
133
Headers/x11/xdnd.h
Normal file
|
@ -0,0 +1,133 @@
|
|||
/*
|
||||
xdnd.c, xdnd.h - C program library for handling the Xdnd protocol
|
||||
|
||||
Copyright (C) 1998 Paul Sheer
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
|
||||
|
||||
Further info can also be obtained by emailing the author at,
|
||||
psheer@obsidian.co.za
|
||||
*/
|
||||
|
||||
#ifndef _X_DND_H
|
||||
#define _X_DND_H
|
||||
|
||||
#define XDND_VERSION 2
|
||||
|
||||
/* XdndEnter */
|
||||
#define XDND_THREE 3
|
||||
#define XDND_ENTER_SOURCE_WIN(e) ((e)->xclient.data.l[0])
|
||||
#define XDND_ENTER_THREE_TYPES(e) (((e)->xclient.data.l[1] & 0x1UL) == 0)
|
||||
#define XDND_ENTER_THREE_TYPES_SET(e,b) (e)->xclient.data.l[1] = ((e)->xclient.data.l[1] & ~0x1UL) | (((b) == 0) ? 0 : 0x1UL)
|
||||
#define XDND_ENTER_VERSION(e) ((e)->xclient.data.l[1] >> 24)
|
||||
#define XDND_ENTER_VERSION_SET(e,v) (e)->xclient.data.l[1] = ((e)->xclient.data.l[1] & ~(0xFF << 24)) | ((v) << 24)
|
||||
#define XDND_ENTER_TYPE(e,i) ((e)->xclient.data.l[2 + i]) /* i => (0, 1, 2) */
|
||||
|
||||
/* XdndPosition */
|
||||
#define XDND_POSITION_SOURCE_WIN(e) ((e)->xclient.data.l[0])
|
||||
#define XDND_POSITION_ROOT_X(e) ((e)->xclient.data.l[2] >> 16)
|
||||
#define XDND_POSITION_ROOT_Y(e) ((e)->xclient.data.l[2] & 0xFFFFUL)
|
||||
#define XDND_POSITION_ROOT_SET(e,x,y) (e)->xclient.data.l[2] = ((x) << 16) | ((y) & 0xFFFFUL)
|
||||
#define XDND_POSITION_TIME(e) ((e)->xclient.data.l[3])
|
||||
#define XDND_POSITION_ACTION(e) ((e)->xclient.data.l[4])
|
||||
|
||||
/* XdndStatus */
|
||||
#define XDND_STATUS_TARGET_WIN(e) ((e)->xclient.data.l[0])
|
||||
#define XDND_STATUS_WILL_ACCEPT(e) ((e)->xclient.data.l[1] & 0x1L)
|
||||
#define XDND_STATUS_WILL_ACCEPT_SET(e,b) (e)->xclient.data.l[1] = ((e)->xclient.data.l[1] & ~0x1UL) | (((b) == 0) ? 0 : 0x1UL)
|
||||
#define XDND_STATUS_WANT_POSITION(e) ((e)->xclient.data.l[1] & 0x2UL)
|
||||
#define XDND_STATUS_WANT_POSITION_SET(e,b) (e)->xclient.data.l[1] = ((e)->xclient.data.l[1] & ~0x2UL) | (((b) == 0) ? 0 : 0x2UL)
|
||||
#define XDND_STATUS_RECT_X(e) ((e)->xclient.data.l[2] >> 16)
|
||||
#define XDND_STATUS_RECT_Y(e) ((e)->xclient.data.l[2] & 0xFFFFL)
|
||||
#define XDND_STATUS_RECT_WIDTH(e) ((e)->xclient.data.l[3] >> 16)
|
||||
#define XDND_STATUS_RECT_HEIGHT(e) ((e)->xclient.data.l[3] & 0xFFFFL)
|
||||
#define XDND_STATUS_RECT_SET(e,x,y,w,h) {(e)->xclient.data.l[2] = ((x) << 16) | ((y) & 0xFFFFUL); (e)->xclient.data.l[3] = ((w) << 16) | ((h) & 0xFFFFUL); }
|
||||
#define XDND_STATUS_ACTION(e) ((e)->xclient.data.l[4])
|
||||
|
||||
/* XdndLeave */
|
||||
#define XDND_LEAVE_SOURCE_WIN(e) ((e)->xclient.data.l[0])
|
||||
|
||||
/* XdndDrop */
|
||||
#define XDND_DROP_SOURCE_WIN(e) ((e)->xclient.data.l[0])
|
||||
#define XDND_DROP_TIME(e) ((e)->xclient.data.l[2])
|
||||
|
||||
/* XdndFinished */
|
||||
#define XDND_FINISHED_TARGET_WIN(e) ((e)->xclient.data.l[0])
|
||||
|
||||
typedef struct _DndClass DndClass;
|
||||
|
||||
struct _DndClass {
|
||||
|
||||
Display *display;
|
||||
|
||||
Atom XdndAware;
|
||||
Atom XdndSelection;
|
||||
Atom XdndEnter;
|
||||
Atom XdndLeave;
|
||||
Atom XdndPosition;
|
||||
Atom XdndDrop;
|
||||
Atom XdndFinished;
|
||||
Atom XdndStatus;
|
||||
Atom XdndActionCopy;
|
||||
Atom XdndActionMove;
|
||||
Atom XdndActionLink;
|
||||
Atom XdndActionAsk;
|
||||
Atom XdndActionPrivate;
|
||||
Atom XdndTypeList;
|
||||
Atom XdndActionList;
|
||||
Atom XdndActionDescription;
|
||||
Atom Xdnd_NON_PROTOCOL_ATOM;
|
||||
Atom version;
|
||||
Window root_window;
|
||||
|
||||
#define XDND_DROP_STAGE_IDLE 0
|
||||
#define XDND_DRAG_STAGE_DRAGGING 1
|
||||
#define XDND_DRAG_STAGE_ENTERED 2
|
||||
#define XDND_DROP_STAGE_CONVERTING 3
|
||||
#define XDND_DROP_STAGE_ENTERED 4
|
||||
int stage;
|
||||
int dragging_version;
|
||||
int internal_drag;
|
||||
int want_position;
|
||||
int ready_to_drop;
|
||||
int will_accept;
|
||||
XRectangle rectangle;
|
||||
Window dropper_window, dragger_window;
|
||||
Atom *dragger_typelist;
|
||||
Atom desired_type;
|
||||
Atom supported_action;
|
||||
Time time;
|
||||
/* drop position from last XdndPosition */
|
||||
int x, y;
|
||||
|
||||
/* block for only this many seconds on not receiving a XdndFinished from target, default : 10 */
|
||||
int time_out;
|
||||
};
|
||||
|
||||
void xdnd_init (DndClass * dnd, Display * display);
|
||||
void xdnd_set_dnd_aware (DndClass * dnd, Window window, Atom * typelist);
|
||||
int xdnd_is_dnd_aware (DndClass * dnd, Window window, int *version, Atom * typelist);
|
||||
void xdnd_set_type_list (DndClass * dnd, Window window, Atom * typelist);
|
||||
void xdnd_send_enter (DndClass * dnd, Window window, Window from, Atom * typelist);
|
||||
void xdnd_send_position (DndClass * dnd, Window window, Window from, Atom action, int x, int y, unsigned long etime);
|
||||
void xdnd_send_status (DndClass * dnd, Window window, Window from, int will_accept,
|
||||
int want_position, int x, int y, int w, int h, Atom action);
|
||||
void xdnd_send_leave (DndClass * dnd, Window window, Window from);
|
||||
void xdnd_send_drop (DndClass * dnd, Window window, Window from, unsigned long etime);
|
||||
void xdnd_send_finished (DndClass * dnd, Window window, Window from, int error);
|
||||
int xdnd_convert_selection (DndClass * dnd, Window window, Window requester, Atom type);
|
||||
void xdnd_selection_send (DndClass * dnd, XSelectionRequestEvent * request, unsigned char *data, int length);
|
||||
|
||||
#endif /* !_X_DND_H */
|
136
Headers/xdps/NSDPSContext.h
Normal file
136
Headers/xdps/NSDPSContext.h
Normal file
|
@ -0,0 +1,136 @@
|
|||
/*
|
||||
NSDPSContext.h
|
||||
|
||||
Encapsulation of Display Postscript contexts
|
||||
|
||||
Copyright (C) 1996 Free Software Foundation, Inc.
|
||||
|
||||
Author: Scott Christley <scottc@net-community.com>
|
||||
Date: 1996
|
||||
|
||||
This file is part of the GNUstep GUI Library.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; see the file COPYING.LIB.
|
||||
If not, write to the Free Software Foundation, Inc.,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef _GNUstep_H_NSDPSContext
|
||||
#define _GNUstep_H_NSDPSContext
|
||||
|
||||
/* Define this to avoid including redefinitions of ps functions introduced
|
||||
by NSGraphicsContext */
|
||||
#define _PSOperators_h_INCLUDE
|
||||
|
||||
#define BOOL XWINDOWSBOOL // prevent X windows BOOL
|
||||
#include <X11/Xmd.h> // warning
|
||||
#undef BOOL
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xutil.h>
|
||||
#include <X11/Xatom.h>
|
||||
#include <DPS/dpsclient.h>
|
||||
#include <DPS/psops.h>
|
||||
#include <Foundation/NSObject.h>
|
||||
#include <AppKit/AppKit.h>
|
||||
#include <AppKit/NSGraphicsContext.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
typedef enum {
|
||||
ALPHAIMAGE_EXT = 1,
|
||||
COMPOSITE_EXT = 2,
|
||||
COMPOSITERECT_EXT = 4,
|
||||
DISSOLVE_EXT = 8,
|
||||
READIMAGE_EXT = 16,
|
||||
SETALPHA_EXT = 32,
|
||||
FLUSHPAGE_EXT = 64
|
||||
} op_extensions_t;
|
||||
|
||||
@class NSData;
|
||||
@class NSMutableData;
|
||||
@class NSAffineTransform;
|
||||
@class GSDisplayServer;
|
||||
|
||||
//
|
||||
// NSDPSContext class interface
|
||||
//
|
||||
@interface NSDPSContext : NSGraphicsContext
|
||||
{
|
||||
DPSContext dps_context;
|
||||
BOOL is_screen_context;
|
||||
DPSErrorProc error_proc;
|
||||
DPSTextProc text_proc;
|
||||
NSDPSContext *chained_parent;
|
||||
NSDPSContext *chained_child;
|
||||
BOOL is_output_traced;
|
||||
BOOL is_synchronized;
|
||||
float ctm[6], invctm[6];
|
||||
int dps_revision;
|
||||
op_extensions_t ext_flags;
|
||||
|
||||
NSDPSContext *next_context;
|
||||
GSDisplayServer *server;
|
||||
|
||||
@public
|
||||
void *context;
|
||||
}
|
||||
|
||||
- (void)wait;
|
||||
|
||||
//
|
||||
// Managing Returned Text and Errors
|
||||
//
|
||||
+ (NSString *)stringForDPSError:(const DPSBinObjSeqRec *)error;
|
||||
- (DPSErrorProc)errorProc;
|
||||
- (void)setErrorProc:(DPSErrorProc)proc;
|
||||
- (void)setTextProc:(DPSTextProc)proc;
|
||||
- (DPSTextProc)textProc;
|
||||
|
||||
//
|
||||
// Managing Chained Contexts
|
||||
//
|
||||
- (void)chainChildContext:(NSDPSContext *)child;
|
||||
- (NSDPSContext *)childContext;
|
||||
- (NSDPSContext *)parentContext;
|
||||
- (void)unchainContext;
|
||||
|
||||
//
|
||||
// Debugging Aids
|
||||
//
|
||||
+ (BOOL)areAllContextsOutputTraced;
|
||||
+ (BOOL)areAllContextsSynchronized;
|
||||
+ (void)setAllContextsOutputTraced:(BOOL)flag;
|
||||
+ (void)setAllContextsSynchronized:(BOOL)flag;
|
||||
- (BOOL)isOutputTraced;
|
||||
- (BOOL)isSynchronized;
|
||||
- (void)setOutputTraced:(BOOL)flag;
|
||||
- (void)setSynchronized:(BOOL)flag;
|
||||
|
||||
@end
|
||||
|
||||
@interface NSDPSContext (GNUstepXDPS)
|
||||
|
||||
- (Display *)xDisplay;
|
||||
- (DPSContext)xDPSContext;
|
||||
- (void *)xrContext;
|
||||
|
||||
- (NSPoint) userPointFromXPoint: (NSPoint)xPoint;
|
||||
- (NSPoint) XPointFromUserPoint: (NSPoint)userPoint;
|
||||
- (NSRect) userRectFromXRect: (NSRect)xrect;
|
||||
- (NSRect) XRectFromUserRect: (NSRect)urect;
|
||||
|
||||
- (op_extensions_t) operatorExtensions;
|
||||
|
||||
@end
|
||||
|
||||
#endif /* _GNUstep_H_NSDPSContext */
|
47
Headers/xlib/XGContext.h
Normal file
47
Headers/xlib/XGContext.h
Normal file
|
@ -0,0 +1,47 @@
|
|||
/* <title>XGContext</title>
|
||||
|
||||
<abstract>Backend drawing context using the Xlib library.</abstract>
|
||||
|
||||
Copyright (C) 1995 Free Software Foundation, Inc.
|
||||
|
||||
Written By: Adam Fedor <fedor@gnu.org>
|
||||
Date: Nov 1998
|
||||
|
||||
This file is part of the GNU Objective C User Interface library.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
|
||||
*/
|
||||
|
||||
#ifndef _XGContext_h_INCLUDE
|
||||
#define _XGContext_h_INCLUDE
|
||||
|
||||
#include "gsc/GSContext.h"
|
||||
#include "x11/XGServer.h"
|
||||
#include <X11/Xatom.h>
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xutil.h>
|
||||
|
||||
@interface XGContext : GSContext
|
||||
{
|
||||
XGDrawMechanism drawMechanism;
|
||||
}
|
||||
|
||||
- (XGDrawMechanism) drawMechanism;
|
||||
- (Display*) xDisplay;
|
||||
- (void *) xrContext;
|
||||
|
||||
@end
|
||||
|
||||
#endif /* _XGContext_h_INCLUDE */
|
78
Headers/xlib/XGGState.h
Normal file
78
Headers/xlib/XGGState.h
Normal file
|
@ -0,0 +1,78 @@
|
|||
/* XGGState - Implements graphic state drawing for Xlib
|
||||
|
||||
Copyright (C) 1995 Free Software Foundation, Inc.
|
||||
|
||||
Written by: Adam Fedor <fedor@boulder.colorado.edu>
|
||||
Date: Nov 1995
|
||||
|
||||
This file is part of the GNU Objective C User Interface Library.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
|
||||
*/
|
||||
|
||||
#ifndef _XGGState_h_INCLUDE
|
||||
#define _XGGState_h_INCLUDE
|
||||
|
||||
#include <Foundation/NSArray.h>
|
||||
#include <Foundation/NSObject.h>
|
||||
#include "gsc/GSGState.h"
|
||||
#include "xlib/xrtools.h"
|
||||
|
||||
@class NSBezierPath;
|
||||
@class NSFont;
|
||||
|
||||
@interface XGGState : GSGState
|
||||
{
|
||||
@public
|
||||
void *context;
|
||||
GC xgcntxt;
|
||||
int window;
|
||||
XGCValues gcv;
|
||||
Drawable draw;
|
||||
Drawable alpha_buffer;
|
||||
Region clipregion;
|
||||
xr_device_color_t color;
|
||||
|
||||
BOOL drawingAlpha;
|
||||
BOOL sharedGC; /* Do we own the GC or share it? */
|
||||
}
|
||||
|
||||
- (void) setWindow: (int)win;
|
||||
- (void) setDrawable: (Drawable)theDrawable;
|
||||
- (void) setGraphicContext: (GC)xGraphicContext;
|
||||
- (void) setGCValues: (XGCValues)values withMask: (int)mask;
|
||||
- (void) setClipMask;
|
||||
- (Region) xClipRegion;
|
||||
- (void) setColor: (xr_device_color_t)acolor;
|
||||
|
||||
- (BOOL) hasDrawable;
|
||||
- (BOOL) hasGraphicContext;
|
||||
- (Drawable) drawable;
|
||||
- (GC) graphicContext;
|
||||
- (NSPoint) offset;
|
||||
- (NSRect) clipRect;
|
||||
|
||||
- (void) setFont: (NSFont*)font;
|
||||
- (NSFont*) currentFont;
|
||||
|
||||
- (XPoint) viewPointToX: (NSPoint)aPoint;
|
||||
- (XRectangle) viewRectToX: (NSRect)aRect;
|
||||
- (XPoint) windowPointToX: (NSPoint)aPoint;
|
||||
- (XRectangle) windowRectToX: (NSRect)aRect;
|
||||
|
||||
@end
|
||||
|
||||
#endif /* _XGGState_h_INCLUDE */
|
||||
|
250
Headers/xlib/XGGeometry.h
Normal file
250
Headers/xlib/XGGeometry.h
Normal file
|
@ -0,0 +1,250 @@
|
|||
/* -*- mode: ObjC -*-
|
||||
|
||||
<title>XGGeometry</title>
|
||||
|
||||
<abstract>Point and rectangle manipulations for X-structures</abstract>
|
||||
|
||||
Written by: <author name="Wim Oudshoorn"><email>woudshoo@xs4all.nl</email></author>
|
||||
Date: Nov, 2001
|
||||
|
||||
This file is part of the GNU Objective C User Interface Library.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
|
||||
*/
|
||||
|
||||
/*
|
||||
This file implements the NSGeometry manipulation functions for
|
||||
the XPoint and XRectangle structures.
|
||||
|
||||
So most code is copied from NSGeometry, with only the structs changed
|
||||
*/
|
||||
|
||||
#ifndef _XGGeometry_h_INCLUDE
|
||||
#define _XGGeometry_h_INCLUDE
|
||||
|
||||
#include <AppKit/NSAffineTransform.h>
|
||||
#include <X11/Xlib.h>
|
||||
#include "xlib/XGGState.h"
|
||||
#include "x11/XGServerWindow.h"
|
||||
|
||||
XRectangle
|
||||
accessibleRectForWindow (gswindow_device_t *win);
|
||||
|
||||
void
|
||||
clipXRectsForCopying (gswindow_device_t* winA, XRectangle* rectA,
|
||||
gswindow_device_t* winB, XRectangle* rectB);
|
||||
|
||||
static inline XPoint
|
||||
XGMakePoint (short x, short y)
|
||||
{
|
||||
XPoint p;
|
||||
|
||||
p.x = x;
|
||||
p.y = y;
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
static inline XRectangle
|
||||
XGMakeRect (short x, short y, unsigned short w, unsigned short h)
|
||||
{
|
||||
XRectangle rect;
|
||||
|
||||
rect.x = x;
|
||||
rect.y = y;
|
||||
rect.width = w;
|
||||
rect.height = h;
|
||||
|
||||
return rect;
|
||||
}
|
||||
|
||||
|
||||
static inline short
|
||||
XGMinX (XRectangle aRect)
|
||||
{
|
||||
return aRect.x;
|
||||
}
|
||||
|
||||
static inline short
|
||||
XGMinY (XRectangle aRect)
|
||||
{
|
||||
return aRect.y;
|
||||
}
|
||||
|
||||
|
||||
static inline short
|
||||
XGMaxX (XRectangle aRect)
|
||||
{
|
||||
return aRect.x + aRect.width;
|
||||
}
|
||||
|
||||
static inline short
|
||||
XGMaxY (XRectangle aRect)
|
||||
{
|
||||
return aRect.y + aRect.height;
|
||||
}
|
||||
|
||||
static inline short
|
||||
XGWidth (XRectangle aRect)
|
||||
{
|
||||
return aRect.width;
|
||||
}
|
||||
|
||||
static inline short
|
||||
XGHeight (XRectangle aRect)
|
||||
{
|
||||
return aRect.height;
|
||||
}
|
||||
|
||||
|
||||
static inline XRectangle
|
||||
XGIntersectionRect (XRectangle aRect, XRectangle bRect)
|
||||
{
|
||||
if (XGMaxX (aRect) <= XGMinX (bRect) || XGMaxX (bRect) <= XGMinX (aRect)
|
||||
|| XGMaxY (aRect) <= XGMinY (bRect) || XGMaxY (bRect) <= XGMinY (aRect))
|
||||
{
|
||||
return XGMakeRect (0, 0, 0, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
XRectangle rect;
|
||||
|
||||
if (XGMinX (aRect) <= XGMinX (bRect))
|
||||
rect.x = bRect.x;
|
||||
else
|
||||
rect.x = aRect.x;
|
||||
|
||||
if (XGMaxX (aRect) >= XGMaxX (bRect))
|
||||
rect.width = XGMaxX (bRect) - rect.x;
|
||||
else
|
||||
rect.width = XGMaxX (aRect) - rect.x;
|
||||
|
||||
if (XGMinY (aRect) <= XGMinY (bRect))
|
||||
rect.y = bRect.y;
|
||||
else
|
||||
rect.y = aRect.y;
|
||||
|
||||
if (XGMaxY (aRect) >= XGMaxY (bRect))
|
||||
rect.height = XGMaxY (bRect) - rect.y;
|
||||
else
|
||||
rect.height = XGMaxY (aRect) - rect.y;
|
||||
|
||||
return rect;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static inline BOOL
|
||||
XGIsEmptyRect (XRectangle aRect)
|
||||
{
|
||||
if (aRect.width == 0 || aRect.height == 0)
|
||||
return YES;
|
||||
else
|
||||
return NO;
|
||||
}
|
||||
|
||||
|
||||
// Just in case this are not defined on a system
|
||||
#ifndef SHRT_MAX
|
||||
#define SHRT_MAX 32767
|
||||
#endif
|
||||
#ifndef SHRT_MIN
|
||||
#define SHRT_MIN (-32768)
|
||||
#endif
|
||||
|
||||
/* Quick floor using C casts <called gs_floor only to avoid clashes if
|
||||
math.h is included>. This casts to short as this is the type X uses
|
||||
for all geometry. */
|
||||
static inline short gs_floor (float f)
|
||||
{
|
||||
if (f >= 0)
|
||||
{
|
||||
if (f > SHRT_MAX)
|
||||
return SHRT_MAX;
|
||||
else
|
||||
return (short)f;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (f < SHRT_MIN)
|
||||
return SHRT_MIN;
|
||||
else
|
||||
{
|
||||
int g = (int)f;
|
||||
|
||||
if (f - ((float)g) > 0)
|
||||
{
|
||||
return g - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return g;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Inline functions to convert from OpenStep view coordinates or
|
||||
* OpenStep window coordinates to X window coordinates.
|
||||
*/
|
||||
static inline XPoint
|
||||
XGWindowPointToX (XGGState *s, NSPoint p)
|
||||
{
|
||||
XPoint newPoint;
|
||||
|
||||
newPoint.x = gs_floor(p.x + s->offset.x);
|
||||
|
||||
newPoint.y = gs_floor(s->offset.y - p.y);
|
||||
|
||||
return newPoint;
|
||||
}
|
||||
|
||||
static inline XRectangle
|
||||
XGWindowRectToX (XGGState *s, NSRect r)
|
||||
{
|
||||
XRectangle newRect;
|
||||
|
||||
newRect.x = gs_floor(r.origin.x + s->offset.x);
|
||||
/* We gs_floor the extreme points, and get the width as the difference */
|
||||
newRect.width = gs_floor(r.origin.x + s->offset.x + r.size.width)
|
||||
- newRect.x;
|
||||
|
||||
newRect.y = gs_floor(s->offset.y - r.origin.y - r.size.height);
|
||||
newRect.height = gs_floor(s->offset.y - r.origin.y) - newRect.y;
|
||||
|
||||
return newRect;
|
||||
}
|
||||
|
||||
/*
|
||||
* Inline functions to convert from OpenStep view coordinates or
|
||||
* OpenStep window coordinates to X window coordinates.
|
||||
*/
|
||||
|
||||
static inline XPoint
|
||||
XGViewPointToX(XGGState *s, NSPoint p)
|
||||
{
|
||||
p = [s->ctm pointInMatrixSpace: p];
|
||||
return XGWindowPointToX(s, p);
|
||||
}
|
||||
|
||||
static inline XRectangle
|
||||
XGViewRectToX(XGGState *s, NSRect r)
|
||||
{
|
||||
r = [s->ctm rectInMatrixSpace: r];
|
||||
return XGWindowRectToX(s, r);
|
||||
}
|
||||
|
||||
#endif /* _XGGeometry_h_INCLUDE */
|
99
Headers/xlib/XGPrivate.h
Normal file
99
Headers/xlib/XGPrivate.h
Normal file
|
@ -0,0 +1,99 @@
|
|||
/*
|
||||
XGPrivate.h
|
||||
|
||||
Copyright (C) 2002 Free Software Foundation, Inc.
|
||||
|
||||
Author: Adam Fedor <fedor@gnu.org>
|
||||
Date: Mar 2002
|
||||
|
||||
This file is part of the GNUstep GUI X/GPS Backend.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; see the file COPYING.LIB.
|
||||
If not, write to the Free Software Foundation,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef _XGPrivate_h_INCLUDE
|
||||
#define _XGPrivate_h_INCLUDE
|
||||
|
||||
#include "xlib/XGContext.h"
|
||||
#include "xlib/xrtools.h"
|
||||
#include <AppKit/GSFontInfo.h>
|
||||
|
||||
/* Font function (defined in XGFontManager) */
|
||||
extern NSString *XGXFontName(NSString *fontName, float size);
|
||||
|
||||
/* Font functions (defined in XGCommonFont) */
|
||||
extern NSString *XGFontName(Display *dpy, XFontStruct *font_struct);
|
||||
extern NSString *XGFontFamily(Display *dpy, XFontStruct *font_struct);
|
||||
extern float XGFontPointSize(Display *dpy, XFontStruct *font_struct);
|
||||
extern int XGWeightOfFont(Display *dpy, XFontStruct *info);
|
||||
extern NSFontTraitMask XGTraitsOfFont(Display *dpy, XFontStruct *info);
|
||||
extern BOOL XGFontIsFixedPitch(Display *dpy, XFontStruct *font_struct);
|
||||
extern NSString *XGFontPropString(Display *dpy, XFontStruct *font_struct,
|
||||
Atom atom);
|
||||
extern unsigned long XGFontPropULong(Display *dpy, XFontStruct *font_struct,
|
||||
Atom atom);
|
||||
|
||||
@interface XGFontEnumerator : GSFontEnumerator
|
||||
{
|
||||
}
|
||||
@end
|
||||
|
||||
@interface XGFontInfo : GSFontInfo
|
||||
{
|
||||
XFontStruct *font_info;
|
||||
}
|
||||
@end
|
||||
|
||||
@interface GSFontInfo (XBackend)
|
||||
|
||||
- (void) drawString: (NSString*)string
|
||||
onDisplay: (Display*) xdpy drawable: (Drawable) draw
|
||||
with: (GC) xgcntxt at: (XPoint) xp;
|
||||
- (void) draw: (const char*) s lenght: (int) len
|
||||
onDisplay: (Display*) xdpy drawable: (Drawable) draw
|
||||
with: (GC) xgcntxt at: (XPoint) xp;
|
||||
- (float) widthOf: (const char*) s lenght: (int) len;
|
||||
- (void) setActiveFor: (Display*) xdpy gc: (GC) xgcntxt;
|
||||
|
||||
@end
|
||||
|
||||
/* In XGBitmap.m */
|
||||
extern int _pixmap_combine_alpha(RContext *context,
|
||||
RXImage *source_im, RXImage *source_alpha,
|
||||
RXImage *dest_im, RXImage *dest_alpha,
|
||||
XRectangle srect,
|
||||
NSCompositingOperation op,
|
||||
XGDrawMechanism drawMechanism,
|
||||
float fraction);
|
||||
|
||||
extern int _bitmap_combine_alpha(RContext *context,
|
||||
unsigned char * data_planes[5],
|
||||
int width, int height,
|
||||
int bits_per_sample, int samples_per_pixel,
|
||||
int bits_per_pixel, int bytes_per_row,
|
||||
int colour_space, BOOL one_is_black,
|
||||
BOOL is_planar, BOOL has_alpha, BOOL fast_min,
|
||||
RXImage *dest_im, RXImage *dest_alpha,
|
||||
XRectangle srect, XRectangle drect,
|
||||
NSCompositingOperation op,
|
||||
XGDrawMechanism drawMechanism);
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
51
Headers/xlib/XftFontInfo.h
Normal file
51
Headers/xlib/XftFontInfo.h
Normal file
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
XftFontInfo
|
||||
|
||||
NSFont helper for GNUstep GUI X/GPS Backend
|
||||
|
||||
Copyright (C) 1996 Free Software Foundation, Inc.
|
||||
|
||||
Author: Fred Kiefer <fredkiefer@gmx.de>
|
||||
Date: July 2001
|
||||
|
||||
This file is part of the GNUstep GUI X/GPS Backend.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; see the file COPYING.LIB.
|
||||
If not, write to the Free Software Foundation,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
// Include this before we include any objC defines, otherwise id is defined
|
||||
#include <X11/Xlib.h>
|
||||
#define id xwindowsid
|
||||
#include <X11/Xft/Xft.h>
|
||||
#undef id
|
||||
|
||||
#include <AppKit/GSFontInfo.h>
|
||||
|
||||
@interface XftFontInfo : GSFontInfo
|
||||
{
|
||||
XftFont *font_info;
|
||||
}
|
||||
|
||||
- (void) drawString: (NSString*)string
|
||||
onDisplay: (Display*) xdpy drawable: (Drawable) draw
|
||||
with: (GC) xgcntxt at: (XPoint) xp;
|
||||
- (void) draw: (const char*) s lenght: (int) len
|
||||
onDisplay: (Display*) xdpy drawable: (Drawable) draw
|
||||
with: (GC) xgcntxt at: (XPoint) xp;
|
||||
- (float) widthOf: (const char*) s lenght: (int) len;
|
||||
- (void) setActiveFor: (Display*) xdpy gc: (GC) xgcntxt;
|
||||
|
||||
@end
|
59
Headers/xlib/xrtools.h
Normal file
59
Headers/xlib/xrtools.h
Normal file
|
@ -0,0 +1,59 @@
|
|||
/* xrtools - Color conversion routines and other low-level X support
|
||||
|
||||
Copyright (C) 1995 Free Software Foundation, Inc.
|
||||
|
||||
Written by: Adam Fedor <fedor@boulder.colorado.edu>
|
||||
Date: Nov 1994
|
||||
|
||||
This file is part of the GNU Objective C User Interface Library.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
|
||||
*/
|
||||
|
||||
#ifndef _xrtools_h_INCLUDE
|
||||
#define _xrtools_h_INCLUDE
|
||||
|
||||
#ifdef HAVE_WRASTER_H
|
||||
#include "wraster.h"
|
||||
#else
|
||||
#include "x11/wraster.h"
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
gray_colorspace, rgb_colorspace, hsb_colorspace, cmyk_colorspace
|
||||
} xr_device_colorspace_t;
|
||||
|
||||
typedef struct _xr_device_color {
|
||||
xr_device_colorspace_t space;
|
||||
float field[6];
|
||||
} xr_device_color_t;
|
||||
|
||||
/* Internal conversion of colors to pixels values */
|
||||
extern u_long xrGrayToPixel(RContext * context, float gray);
|
||||
extern u_long xrRGBToPixel(RContext * context, float red,
|
||||
float green, float blue);
|
||||
extern u_long xrHSBToPixel(RContext * context, float h, float s, float b);
|
||||
extern u_long xrCMYKToPixel(RContext * context, float c, float m,
|
||||
float y, float k);
|
||||
extern u_long xrColorToPixel(RContext * context, xr_device_color_t color);
|
||||
|
||||
extern xr_device_color_t xrConvertToGray(xr_device_color_t color);
|
||||
extern xr_device_color_t xrConvertToRGB(xr_device_color_t color);
|
||||
extern xr_device_color_t xrConvertToHSB(xr_device_color_t color);
|
||||
extern xr_device_color_t xrConvertToCMYK(xr_device_color_t color);
|
||||
|
||||
#endif
|
||||
|
||||
|
3
Source/.cvsignore
Normal file
3
Source/.cvsignore
Normal file
|
@ -0,0 +1,3 @@
|
|||
ix86
|
||||
*_obj
|
||||
*.bundle
|
74
Source/GNUmakefile
Normal file
74
Source/GNUmakefile
Normal file
|
@ -0,0 +1,74 @@
|
|||
#
|
||||
# Top level makefile for GNUstep Backend
|
||||
#
|
||||
# Copyright (C) 2002 Free Software Foundation, Inc.
|
||||
#
|
||||
# Author: Adam Fedor <fedor@gnu.org>
|
||||
#
|
||||
# This file is part of the GNUstep Backend.
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Library General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This library is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# Library General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Library General Public
|
||||
# License along with this library; see the file COPYING.LIB.
|
||||
# If not, write to the Free Software Foundation,
|
||||
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
# Install into the system root by default
|
||||
GNUSTEP_INSTALLATION_DIR = $(GNUSTEP_SYSTEM_ROOT)
|
||||
|
||||
GNUSTEP_MAKEFILES = $(GNUSTEP_SYSTEM_ROOT)/Makefiles
|
||||
|
||||
include $(GNUSTEP_MAKEFILES)/common.make
|
||||
|
||||
include ../config.make
|
||||
|
||||
# The library to be compiled, as a library or as a bundle
|
||||
ifeq ($(BACKEND_BUNDLE),)
|
||||
LIBRARY_NAME=libgnustep-back
|
||||
else
|
||||
BUNDLE_NAME=libgnustep-back
|
||||
endif
|
||||
|
||||
#
|
||||
# The list of subproject directories
|
||||
#
|
||||
SUBPROJECTS = gsc
|
||||
ifneq ($(BUILD_XLIB),)
|
||||
SUBPROJECTS += xlib
|
||||
endif
|
||||
ifneq ($(BUILD_XDPS),)
|
||||
SUBPROJECTS += xdps
|
||||
endif
|
||||
ifneq ($(BUILD_X11),)
|
||||
SUBPROJECTS += x11
|
||||
endif
|
||||
ifneq ($(BUILD_WIN32),)
|
||||
SUBPROJECTS += win32
|
||||
endif
|
||||
ifneq ($(BUILD_WINLIB),)
|
||||
SUBPROJECTS += winlib
|
||||
endif
|
||||
libgnustep-back_SUBPROJECTS=$(SUBPROJECTS)
|
||||
|
||||
libgnustep-back_OBJC_FILES=GSBackend.m
|
||||
|
||||
libgnustep-back_PRINCIPAL_CLASS=GSBackend
|
||||
|
||||
-include GNUmakefile.preamble
|
||||
|
||||
ifeq ($(BACKEND_BUNDLE),)
|
||||
include $(GNUSTEP_MAKEFILES)/library.make
|
||||
else
|
||||
include $(GNUSTEP_MAKEFILES)/bundle.make
|
||||
endif
|
||||
|
||||
-include GNUmakefile.postamble
|
68
Source/GNUmakefile.postamble
Normal file
68
Source/GNUmakefile.postamble
Normal file
|
@ -0,0 +1,68 @@
|
|||
#
|
||||
# GNUakefile.postamble
|
||||
#
|
||||
# Copyright (C) 2002 Free Software Foundation, Inc.
|
||||
#
|
||||
# Author: Adam Fedor <fedor@gnu.org>
|
||||
#
|
||||
# This file is part of the GNUstep Backend.
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Library General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This library is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# Library General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Library General Public
|
||||
# License along with this library; see the file COPYING.LIB.
|
||||
# If not, write to the Free Software Foundation,
|
||||
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
# Things to do before compiling
|
||||
before-all:: $(GNUSTEP_TARGET_DIR)/config.h
|
||||
|
||||
# Things to do after compiling
|
||||
# after-all::
|
||||
|
||||
# Things to do before installing
|
||||
# before-install::
|
||||
|
||||
# Things to do after installing
|
||||
# after-install::
|
||||
|
||||
# Things to do before uninstalling
|
||||
# before-uninstall::
|
||||
|
||||
# Things to do after uninstalling
|
||||
# after-uninstall::
|
||||
|
||||
# Things to do before cleaning
|
||||
# before-clean::
|
||||
|
||||
# Things to do after cleaning
|
||||
# after-clean::
|
||||
|
||||
# Things to do before distcleaning
|
||||
# before-distclean::
|
||||
|
||||
# Things to do after distcleaning
|
||||
after-distclean::
|
||||
rm -rf $(GNUSTEP_TARGET_DIR)/config.h
|
||||
rm -rf $(GNUSTEP_TARGET_CPU)
|
||||
|
||||
# Things to do before checking
|
||||
# before-check::
|
||||
|
||||
# Things to do after checking
|
||||
# after-check::
|
||||
|
||||
#
|
||||
# The config.h file is specific to a target
|
||||
#
|
||||
$(GNUSTEP_TARGET_DIR)/config.h: ../config.status
|
||||
$(GNUSTEP_MAKEFILES)/mkinstalldirs $(GNUSTEP_TARGET_DIR)
|
||||
-cp ../config.h $(GNUSTEP_TARGET_DIR)
|
64
Source/GNUmakefile.preamble
Normal file
64
Source/GNUmakefile.preamble
Normal file
|
@ -0,0 +1,64 @@
|
|||
#
|
||||
# GNUmakefile.preamble
|
||||
#
|
||||
# Copyright (C) 2002 Free Software Foundation, Inc.
|
||||
#
|
||||
# Author: Adam Fedor <fedor@gnu.org>
|
||||
#
|
||||
# This file is part of the GNUstep Backend.
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Library General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This library is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# Library General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Library General Public
|
||||
# License along with this library; see the file COPYING.LIB.
|
||||
# If not, write to the Free Software Foundation,
|
||||
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
#
|
||||
# Flags dealing with compiling and linking
|
||||
#
|
||||
|
||||
# Additional flags to pass to the preprocessor
|
||||
ADDITIONAL_CPPFLAGS += -Wall
|
||||
|
||||
# Additional flags to pass to the Objective-C compiler
|
||||
#ADDITIONAL_OBJCFLAGS +=
|
||||
|
||||
# Additional flags to pass to the C compiler
|
||||
ADDITIONAL_CFLAGS +=
|
||||
|
||||
# Additional include directories the compiler should search
|
||||
ADDITIONAL_INCLUDE_DIRS += -I../Headers \
|
||||
-I$(GNUSTEP_TARGET_DIR)
|
||||
|
||||
# Additional LDFLAGS to pass to the linker
|
||||
#ADDITIONAL_LDFLAGS +=
|
||||
|
||||
# Additional library directories the linker should search
|
||||
#ADDITIONAL_LIB_DIRS +=
|
||||
|
||||
#
|
||||
# Flags dealing with installing and uninstalling
|
||||
#
|
||||
|
||||
# What are the libraries this library depends upon. This is needed for some
|
||||
# systems where building a shared library requires to pass to the linker
|
||||
# all the libraries the target library depends upon.
|
||||
|
||||
#LIBRARIES_DEPEND_UPON =
|
||||
|
||||
# Flags for compiling as a bundle
|
||||
ifneq ($(BACKEND_BUNDLE),)
|
||||
libgnustep-back_BUNDLE_LIBS = $(GRAPHIC_LIBS)
|
||||
ADDITIONAL_INCLUDE_DIRS += $(GRAPHIC_CFLAGS)
|
||||
ADDITIONAL_LIB_DIRS += $(GRAPHIC_LFLAGS)
|
||||
endif
|
||||
|
107
Source/GSBackend.m
Normal file
107
Source/GSBackend.m
Normal file
|
@ -0,0 +1,107 @@
|
|||
/* GSBackend - backend initialize class
|
||||
|
||||
Copyright (C) 2002 Free Software Foundation, Inc.
|
||||
|
||||
Author: Adam Fedor <fedor@gnu.org>
|
||||
Date: Mar 2002
|
||||
|
||||
This file is part of the GNUstep GUI Library.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; see the file COPYING.LIB.
|
||||
If not, write to the Free Software Foundation,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include <Foundation/NSObject.h>
|
||||
#include <Foundation/NSException.h>
|
||||
#include <Foundation/NSUserDefaults.h>
|
||||
|
||||
@interface GSBackend : NSObject
|
||||
{
|
||||
}
|
||||
+ (void) initializeBackend;
|
||||
@end
|
||||
|
||||
/* Call the correct initalization routines for the choosen
|
||||
backend. This depends both on configuration data and defaults.
|
||||
There is also a method to get a different backend class for different
|
||||
configure parameters (so you could only load in the backend configurations
|
||||
you wanted. But that is not implemented yet). */
|
||||
|
||||
#ifdef BUILD_X11
|
||||
#include <x11/XGServer.h>
|
||||
#endif
|
||||
#ifdef BUILD_XLIB
|
||||
#include <xlib/XGContext.h>
|
||||
#endif
|
||||
#ifdef BUILD_XDPS
|
||||
#include <xdps/NSDPSContext.h>
|
||||
#endif
|
||||
#ifdef BUILD_WIN32
|
||||
// win32 header here
|
||||
#endif
|
||||
#ifdef BUILD_WINLIB
|
||||
// winlib header here
|
||||
#endif
|
||||
|
||||
@implementation GSBackend
|
||||
|
||||
+ (void) initializeBackend
|
||||
{
|
||||
Class contextClass;
|
||||
NSString *context;
|
||||
NSUserDefaults *defs = [NSUserDefaults standardUserDefaults];
|
||||
|
||||
/* Load in only one server */
|
||||
#ifdef BUILD_X11
|
||||
[XGServer initializeBackend];
|
||||
#else
|
||||
#ifdef BUILD_WIN32
|
||||
// win32 initialize here
|
||||
#else
|
||||
[NSException raise: NSInternalInconsistencyException
|
||||
format: @"No Window Server configured in backend"];
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* The way the frontend is currently structured
|
||||
it's not possible to have more than one */
|
||||
#ifdef BUILD_XDPS
|
||||
context = @"xdps";
|
||||
#endif
|
||||
#ifdef BUILD_WINLIB
|
||||
context = @"xwin32";
|
||||
#endif
|
||||
#ifdef BUILD_XLIB
|
||||
context = @"xlib";
|
||||
#endif
|
||||
|
||||
/* What backend context? */
|
||||
if ([defs stringForKey: @"GSContext"])
|
||||
context = [defs stringForKey: @"GSContext"];
|
||||
|
||||
if ([context isEqual: @"xdps"])
|
||||
contextClass = objc_get_class("NSDPSContext");
|
||||
else if ([context isEqual: @"win32"])
|
||||
contextClass = objc_get_class("WIN32Context");
|
||||
else
|
||||
contextClass = objc_get_class("XGContext");
|
||||
|
||||
[contextClass initializeBackend];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
59
Source/gsc/GNUmakefile
Normal file
59
Source/gsc/GNUmakefile
Normal file
|
@ -0,0 +1,59 @@
|
|||
#
|
||||
# Main makefile for GNUstep Backend generic contexts/gstates
|
||||
#
|
||||
# Copyright (C) 2002 Free Software Foundation, Inc.
|
||||
#
|
||||
# Author: Adam Fedor <fedor@gnu.org>
|
||||
#
|
||||
# This file is part of the GNUstep Backend.
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Library General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This library is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# Library General Public License for more details.
|
||||
#
|
||||
# If you are interested in a warranty or support for this source code,
|
||||
# contact Scott Christley at scottc@net-community.com
|
||||
#
|
||||
# You should have received a copy of the GNU Library General Public
|
||||
# License along with this library; see the file COPYING.LIB.
|
||||
# If not, write to the Free Software Foundation,
|
||||
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
GNUSTEP_INSTALLATION_DIR = $(GNUSTEP_SYSTEM_ROOT)
|
||||
|
||||
GNUSTEP_MAKEFILES = $(GNUSTEP_SYSTEM_ROOT)/Makefiles
|
||||
|
||||
GNUSTEP_LOCAL_ADDITIONAL_MAKEFILES=../../back.make
|
||||
include $(GNUSTEP_MAKEFILES)/common.make
|
||||
|
||||
include ../../config.make
|
||||
|
||||
SUBPROJECT_NAME=gsc
|
||||
|
||||
# The Objective-C source files to be compiled
|
||||
gsc_OBJC_FILES = \
|
||||
GSContext.m \
|
||||
GSGState.m \
|
||||
GSStreamContext.m \
|
||||
externs.m
|
||||
|
||||
gsc_HEADER_FILES_DIR = ../../Headers/gsc
|
||||
gsc_HEADER_FILES_INSTALL_DIR = gnustep/gsc
|
||||
|
||||
gsc_HEADER_FILES = \
|
||||
GSContext.h \
|
||||
GSGState.h \
|
||||
GSGStateOps.h
|
||||
|
||||
-include GNUmakefile.preamble
|
||||
|
||||
include $(GNUSTEP_MAKEFILES)/subproject.make
|
||||
|
||||
-include GNUmakefile.postamble
|
||||
|
54
Source/gsc/GNUmakefile.preamble
Normal file
54
Source/gsc/GNUmakefile.preamble
Normal file
|
@ -0,0 +1,54 @@
|
|||
#
|
||||
# GNUmakefile.preamble
|
||||
#
|
||||
# Copyright (C) 2002 Free Software Foundation, Inc.
|
||||
#
|
||||
# Author: Adam Fedor <fedor@gnu.org>
|
||||
#
|
||||
# This file is part of the GNUstep Backend.
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Library General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This library is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# Library General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Library General Public
|
||||
# License along with this library; see the file COPYING.LIB.
|
||||
# If not, write to the Free Software Foundation,
|
||||
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
#
|
||||
# Flags dealing with compiling and linking
|
||||
#
|
||||
|
||||
# Additional flags to pass to the preprocessor
|
||||
GNUSTEP_INSTALL_LIBDIR=$(GNUSTEP_LIBRARIES_ROOT)
|
||||
ADDITIONAL_CPPFLAGS = -DGNUSTEP_INSTALL_LIBDIR=\"$(GNUSTEP_INSTALL_LIBDIR)\" \
|
||||
-DGNUSTEP_INSTALL_PREFIX=$(GNUSTEP_INSTALL_PREFIX) \
|
||||
$(CONFIG_SYSTEM_DEFS)
|
||||
|
||||
# Additional flags to pass to the Objective-C compiler
|
||||
#ADDITIONAL_OBJCFLAGS =
|
||||
|
||||
# Additional flags to pass to the C compiler
|
||||
#ADDITIONAL_CFLAGS =
|
||||
|
||||
# Additional include directories the compiler should search
|
||||
ADDITIONAL_INCLUDE_DIRS = -I../../Headers -I../$(GNUSTEP_TARGET_DIR)
|
||||
|
||||
# Additional LDFLAGS to pass to the linker
|
||||
#ADDITIONAL_LDFLAGS =
|
||||
|
||||
# Additional library directories the linker should search
|
||||
#ADDITIONAL_LIB_DIRS =
|
||||
|
||||
#
|
||||
# Flags dealing with installing and uninstalling
|
||||
#
|
||||
|
||||
|
937
Source/gsc/GSContext.m
Normal file
937
Source/gsc/GSContext.m
Normal file
|
@ -0,0 +1,937 @@
|
|||
/* -*- mode:ObjC -*-
|
||||
GSContext - Generic drawing context for non-PS backends
|
||||
|
||||
Copyright (C) 1998,1999 Free Software Foundation, Inc.
|
||||
|
||||
Written by: Adam Fedor <fedor@boulder.colorado.edu>
|
||||
Date: Nov 1998
|
||||
|
||||
This file is part of the GNU Objective C User Interface Library.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include <AppKit/AppKitExceptions.h>
|
||||
#include <AppKit/NSAffineTransform.h>
|
||||
#include <AppKit/NSColor.h>
|
||||
#include <AppKit/NSView.h>
|
||||
#include <AppKit/NSWindow.h>
|
||||
#include <AppKit/GSDisplayServer.h>
|
||||
#include <Foundation/NSException.h>
|
||||
#include <Foundation/NSArray.h>
|
||||
#include <Foundation/NSDictionary.h>
|
||||
#include <Foundation/NSData.h>
|
||||
#include <Foundation/NSValue.h>
|
||||
#include <Foundation/NSString.h>
|
||||
#include <Foundation/NSUserDefaults.h>
|
||||
#include <Foundation/NSDebug.h>
|
||||
|
||||
#include "gsc/GSContext.h"
|
||||
#include "gsc/GSStreamContext.h"
|
||||
#include "gsc/GSGState.h"
|
||||
|
||||
#define GSI_ARRAY_TYPES GSUNION_OBJ
|
||||
|
||||
#if GS_WITH_GC == 0
|
||||
#define GSI_ARRAY_RELEASE(A, X) [(X).obj release]
|
||||
#define GSI_ARRAY_RETAIN(A, X) [(X).obj retain]
|
||||
#else
|
||||
#define GSI_ARRAY_RELEASE(A, X)
|
||||
#define GSI_ARRAY_RETAIN(A, X) (X).obj
|
||||
#endif
|
||||
|
||||
#ifdef GSIArray
|
||||
#undef GSIArray
|
||||
#endif
|
||||
#include <base/GSIArray.h>
|
||||
|
||||
/* Error macros */
|
||||
#define CHECK_NULL_OUTPUT(outvar) \
|
||||
do { if (outvar == NULL) {\
|
||||
DPS_ERROR(DPSnulloutput, @"NULL output variable specified"); \
|
||||
return; } } while(0)
|
||||
|
||||
#define CHECK_INVALID_FONT(ident) \
|
||||
do { if (ident >= [fontid count]) { \
|
||||
DPS_ERROR(DPSinvalidfont, @"Cannot find indicated font"); \
|
||||
return; } } while(0)
|
||||
|
||||
#define CHECK_STACK_UNDERFLOW(stack) \
|
||||
do { if (GSIArrayCount((GSIArray)stack) == 0) { \
|
||||
DPS_ERROR(DPSstackunderflow, @"Attempt to pop from empty stack"); \
|
||||
return; } } while(0)
|
||||
|
||||
#if 0
|
||||
#define CHECK_TYPECHECK(obj, kind) \
|
||||
do { if ([kind class] != Nil && !GSObjCIsKindOf(GSObjCClass(obj), [kind class])) {\
|
||||
DPS_ERROR(DPStypecheck, @"Invalid object"); \
|
||||
return; } } while(0)
|
||||
#else
|
||||
#define CHECK_TYPECHECK(obj,kind)
|
||||
#endif
|
||||
|
||||
#define ctxt_pop(object, stack, kind) \
|
||||
do { \
|
||||
CHECK_STACK_UNDERFLOW(stack); \
|
||||
object = (GSIArrayLastItem((GSIArray)stack)).obj; \
|
||||
CHECK_TYPECHECK(object, kind); \
|
||||
AUTORELEASE(RETAIN(object)); \
|
||||
GSIArrayRemoveLastItem((GSIArray)stack); \
|
||||
} while (0)
|
||||
|
||||
#define ctxt_push(object, stack) \
|
||||
GSIArrayAddItem((GSIArray)stack, (GSIArrayItem)object)
|
||||
|
||||
/* Globally unique gstate number */
|
||||
static unsigned int unique_index = 0;
|
||||
|
||||
@interface GSContext (PrivateOps)
|
||||
- (void)DPSdefineuserobject;
|
||||
- (void)DPSexecuserobject: (int)index;
|
||||
- (void)DPSundefineuserobject: (int)index;
|
||||
- (void)DPSclear;
|
||||
- (void)DPScopy: (int)n;
|
||||
- (void)DPScount: (int *)n;
|
||||
- (void)DPSdup;
|
||||
- (void)DPSexch;
|
||||
- (void)DPSindex: (int)i;
|
||||
- (void)DPSpop;
|
||||
@end
|
||||
|
||||
/**
|
||||
<unit>
|
||||
<heading>GSContext</heading>
|
||||
<p>
|
||||
This class is a reasonable attempt at providing PostScript-like
|
||||
drawing operations. Don't even begin to think that this is a full
|
||||
PostScript implementation, however. Only operations that do not
|
||||
require stack handling are implemented. Some other functions that
|
||||
would require stack handling and are needed for drawing are
|
||||
implemented in a different way (e.g. colorspace and images). These
|
||||
functions should also allow for a reasonable simulation of Quartz
|
||||
functionality.
|
||||
</p>
|
||||
</unit> */
|
||||
@implementation GSContext
|
||||
|
||||
- (id) initWithContextInfo: (NSDictionary *)info
|
||||
{
|
||||
NSString *contextType;
|
||||
NSZone *z = [self zone];
|
||||
|
||||
contextType = [info objectForKey:
|
||||
NSGraphicsContextRepresentationFormatAttributeName];
|
||||
if (contextType && [contextType isEqual: NSGraphicsContextPSFormat])
|
||||
{
|
||||
/* Don't call self, since we aren't initialized */
|
||||
[super dealloc];
|
||||
return [[GSStreamContext allocWithZone: z] initWithContextInfo: info];
|
||||
}
|
||||
|
||||
/* A context is only associated with one server. Do not retain
|
||||
the server, however */
|
||||
server = GSCurrentServer();
|
||||
|
||||
/* Initialize lists and stacks */
|
||||
opstack = NSZoneMalloc(z, sizeof(GSIArray_t));
|
||||
GSIArrayInitWithZoneAndCapacity((GSIArray)opstack, z, 2);
|
||||
gstack = NSZoneMalloc(z, sizeof(GSIArray_t));
|
||||
GSIArrayInitWithZoneAndCapacity((GSIArray)gstack, z, 2);
|
||||
gtable = NSCreateMapTable(NSIntMapKeyCallBacks,
|
||||
NSObjectMapValueCallBacks, 20);
|
||||
|
||||
[super initWithContextInfo: info];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
/**
|
||||
Closes all backend resources and dealloc other ivars.
|
||||
*/
|
||||
- (void) dealloc
|
||||
{
|
||||
NSDebugLog(@"Destroying GS Context");
|
||||
GSIArrayEmpty((GSIArray)opstack);
|
||||
NSZoneFree([self zone], opstack);
|
||||
GSIArrayEmpty((GSIArray)gstack);
|
||||
NSZoneFree([self zone], gstack);
|
||||
NSFreeMapTable(gtable);
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
/**
|
||||
Returns YES, since this is a display context.
|
||||
*/
|
||||
- (BOOL)isDrawingToScreen
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
|
||||
/**
|
||||
Returns the current GSGState object
|
||||
*/
|
||||
- (GSGState *) currentGState
|
||||
{
|
||||
return gstate;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation GSContext (Ops)
|
||||
|
||||
/* ----------------------------------------------------------------------- */
|
||||
/* Color operations */
|
||||
/* ----------------------------------------------------------------------- */
|
||||
- (void) DPScurrentalpha: (float *)a
|
||||
{
|
||||
[gstate DPScurrentalpha: a];
|
||||
}
|
||||
|
||||
- (void) DPScurrentcmykcolor: (float*)c : (float*)m : (float*)y : (float*)k
|
||||
{
|
||||
[gstate DPScurrentcmykcolor:c :m :y :k];
|
||||
}
|
||||
|
||||
- (void) DPScurrentgray: (float*)gray
|
||||
{
|
||||
CHECK_NULL_OUTPUT(gray);
|
||||
[gstate DPScurrentgray: gray];
|
||||
}
|
||||
|
||||
- (void) DPScurrenthsbcolor: (float*)h : (float*)s : (float*)b
|
||||
{
|
||||
CHECK_NULL_OUTPUT(h);
|
||||
CHECK_NULL_OUTPUT(s);
|
||||
CHECK_NULL_OUTPUT(b);
|
||||
[gstate DPScurrenthsbcolor:h :s :b];
|
||||
}
|
||||
|
||||
- (void) DPScurrentrgbcolor: (float*)r : (float*)g : (float*)b
|
||||
{
|
||||
CHECK_NULL_OUTPUT(r);
|
||||
CHECK_NULL_OUTPUT(g);
|
||||
CHECK_NULL_OUTPUT(b);
|
||||
[gstate DPScurrentrgbcolor:r :g :b];
|
||||
}
|
||||
|
||||
- (void) DPSsetalpha: (float)a
|
||||
{
|
||||
[gstate DPSsetalpha: a];
|
||||
}
|
||||
|
||||
- (void) DPSsetcmykcolor: (float)c : (float)m : (float)y : (float)k
|
||||
{
|
||||
[gstate DPSsetcmykcolor:c :m :y :k];
|
||||
}
|
||||
|
||||
- (void) DPSsetgray: (float)gray
|
||||
{
|
||||
[gstate DPSsetgray: gray];
|
||||
}
|
||||
|
||||
- (void) DPSsethsbcolor: (float)h : (float)s : (float)b
|
||||
{
|
||||
[gstate DPSsethsbcolor:h :s :b];
|
||||
}
|
||||
|
||||
- (void) DPSsetrgbcolor: (float)r : (float)g : (float)b
|
||||
{
|
||||
[gstate DPSsetrgbcolor:r :g :b];
|
||||
}
|
||||
|
||||
- (void) GSSetFillColorspace: (NSDictionary *)dict
|
||||
{
|
||||
[self notImplemented: _cmd];
|
||||
}
|
||||
|
||||
- (void) GSSetStrokeColorspace: (NSDictionary *)dict
|
||||
{
|
||||
[self notImplemented: _cmd];
|
||||
}
|
||||
|
||||
- (void) GSSetFillColor: (float *)values
|
||||
{
|
||||
[self notImplemented: _cmd];
|
||||
}
|
||||
|
||||
- (void) GSSetStrokeColor: (float *)values
|
||||
{
|
||||
[self notImplemented: _cmd];
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------- */
|
||||
/* Text operations */
|
||||
/* ----------------------------------------------------------------------- */
|
||||
- (void) DPSashow: (float)x : (float)y : (const char *)s
|
||||
{
|
||||
[gstate DPSashow: x : y : s];
|
||||
}
|
||||
|
||||
- (void) DPSawidthshow: (float)cx : (float)cy : (int)c : (float)ax : (float)ay : (const char *)s
|
||||
{
|
||||
[gstate DPSawidthshow: cx : cy : c : ax : ay : s];
|
||||
}
|
||||
|
||||
- (void) DPScharpath: (const char *)s : (int)b
|
||||
{
|
||||
[gstate DPScharpath: s : b];
|
||||
}
|
||||
|
||||
- (void) DPSshow: (const char *)s
|
||||
{
|
||||
[gstate DPSshow: s];
|
||||
}
|
||||
|
||||
- (void) DPSwidthshow: (float)x : (float)y : (int)c : (const char *)s
|
||||
{
|
||||
[gstate DPSwidthshow: x : y : c : s];
|
||||
}
|
||||
|
||||
- (void) DPSxshow: (const char *)s : (const float*)numarray : (int)size
|
||||
{
|
||||
[gstate DPSxshow: s : numarray : size];
|
||||
}
|
||||
|
||||
- (void) DPSxyshow: (const char *)s : (const float*)numarray : (int)size
|
||||
{
|
||||
[gstate DPSxyshow: s : numarray : size];
|
||||
}
|
||||
|
||||
- (void) DPSyshow: (const char *)s : (const float*)numarray : (int)size
|
||||
{
|
||||
[gstate DPSyshow: s : numarray : size];
|
||||
}
|
||||
|
||||
- (void) GSSetCharacterSpacing: (float)extra
|
||||
{
|
||||
[self notImplemented: _cmd];
|
||||
}
|
||||
|
||||
- (void) GSSetFont: (NSFont*)font
|
||||
{
|
||||
[gstate setFont: font];
|
||||
}
|
||||
|
||||
- (void) GSSetFontSize: (float)size
|
||||
{
|
||||
[self notImplemented: _cmd];
|
||||
}
|
||||
|
||||
- (NSAffineTransform *) GSGetTextCTM
|
||||
{
|
||||
[self notImplemented: _cmd];
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (NSPoint) GSGetTextPosition
|
||||
{
|
||||
[self notImplemented: _cmd];
|
||||
return NSMakePoint(0,0);
|
||||
}
|
||||
|
||||
- (void) GSSetTextCTM: (NSAffineTransform *)ctm
|
||||
{
|
||||
[self notImplemented: _cmd];
|
||||
}
|
||||
|
||||
- (void) GSSetTextDrawingMode: (GSTextDrawingMode)mode
|
||||
{
|
||||
[self notImplemented: _cmd];
|
||||
}
|
||||
|
||||
- (void) GSSetTextPosition: (NSPoint)loc
|
||||
{
|
||||
[self notImplemented: _cmd];
|
||||
}
|
||||
|
||||
- (void) GSShowText: (const char *)string : (size_t) length
|
||||
{
|
||||
[self notImplemented: _cmd];
|
||||
}
|
||||
|
||||
- (void) GSShowGlyphs: (const NSGlyph *)glyphs : (size_t) length
|
||||
{
|
||||
[self notImplemented: _cmd];
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------- */
|
||||
/* Gstate Handling */
|
||||
/* ----------------------------------------------------------------------- */
|
||||
|
||||
- (void) DPScurrentgstate: (int)gst
|
||||
{
|
||||
if (gst)
|
||||
{
|
||||
/* Associate/copy current gstate with gst */
|
||||
ctxt_push([NSNumber numberWithInt: gst], opstack);
|
||||
ctxt_push(gstate, opstack);
|
||||
[self DPSdefineuserobject];
|
||||
[self DPSexecuserobject: gst];
|
||||
}
|
||||
}
|
||||
|
||||
- (void) DPSgrestore
|
||||
{
|
||||
if (GSIArrayCount((GSIArray)gstack) == 0)
|
||||
return;
|
||||
RELEASE(gstate);
|
||||
gstate = (GSIArrayLastItem((GSIArray)gstack)).obj;
|
||||
ctxt_pop(gstate, gstack, GSGState);
|
||||
RETAIN(gstate);
|
||||
}
|
||||
|
||||
- (void) DPSgsave
|
||||
{
|
||||
ctxt_push(gstate, gstack);
|
||||
AUTORELEASE(gstate);
|
||||
gstate = [gstate copy];
|
||||
}
|
||||
|
||||
- (void) DPSgstate
|
||||
{
|
||||
ctxt_push(AUTORELEASE([gstate copy]), opstack);
|
||||
}
|
||||
|
||||
- (void) DPSinitgraphics
|
||||
{
|
||||
[gstate DPSinitgraphics];
|
||||
}
|
||||
|
||||
- (void) DPSsetgstate: (int)gst
|
||||
{
|
||||
if (gst)
|
||||
{
|
||||
[self DPSexecuserobject: gst];
|
||||
RELEASE(gstate);
|
||||
ctxt_pop(gstate, opstack, GSGState);
|
||||
RETAIN(gstate);
|
||||
}
|
||||
else
|
||||
DESTROY(gstate);
|
||||
}
|
||||
|
||||
/* Should work the same as 'unique_index exch defineuserobject' */
|
||||
- (int) GSDefineGState
|
||||
{
|
||||
GSGState *obj;
|
||||
if(gstate == nil)
|
||||
{
|
||||
DPS_ERROR(DPSundefined, @"No gstate");
|
||||
return 0;
|
||||
}
|
||||
ctxt_pop(obj, opstack, GSGState);
|
||||
NSMapInsert(gtable, (void *)++unique_index, obj);
|
||||
return unique_index;
|
||||
}
|
||||
|
||||
- (void) GSUndefineGState: (int)gst
|
||||
{
|
||||
[self DPSundefineuserobject: gst];
|
||||
}
|
||||
|
||||
/* Should work the same as 'currentgstate pop' */
|
||||
- (void) GSReplaceGState: (int)gst
|
||||
{
|
||||
if(gst <= 0)
|
||||
return;
|
||||
NSMapInsert(gtable, (void *)gst, gstate);
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------- */
|
||||
/* Gstate operations */
|
||||
/* ----------------------------------------------------------------------- */
|
||||
- (void) DPScurrentflat: (float*)flatness
|
||||
{
|
||||
CHECK_NULL_OUTPUT(flatness);
|
||||
[gstate DPScurrentflat: flatness];
|
||||
}
|
||||
|
||||
- (void) DPScurrentlinecap: (int*)linecap
|
||||
{
|
||||
[gstate DPScurrentlinecap: linecap];
|
||||
}
|
||||
|
||||
- (void) DPScurrentlinejoin: (int*)linejoin
|
||||
{
|
||||
[gstate DPScurrentlinejoin: linejoin];
|
||||
}
|
||||
|
||||
- (void) DPScurrentlinewidth: (float*)width
|
||||
{
|
||||
[gstate DPScurrentlinewidth: width];
|
||||
}
|
||||
|
||||
- (void) DPScurrentmiterlimit: (float*)limit
|
||||
{
|
||||
CHECK_NULL_OUTPUT(limit);
|
||||
[gstate DPScurrentmiterlimit: limit];
|
||||
}
|
||||
|
||||
- (void) DPScurrentpoint: (float*)x : (float*)y
|
||||
{
|
||||
CHECK_NULL_OUTPUT(x);
|
||||
CHECK_NULL_OUTPUT(y);
|
||||
[gstate DPScurrentpoint:x :y];
|
||||
}
|
||||
|
||||
- (void) DPScurrentstrokeadjust: (int*)b
|
||||
{
|
||||
CHECK_NULL_OUTPUT(b);
|
||||
[gstate DPScurrentstrokeadjust: b];
|
||||
}
|
||||
|
||||
- (void) DPSsetdash: (const float*)pat : (int)size : (float)offset
|
||||
{
|
||||
[gstate DPSsetdash: pat : size : offset];
|
||||
}
|
||||
|
||||
- (void) DPSsetflat: (float)flatness
|
||||
{
|
||||
[gstate DPSsetflat: flatness];
|
||||
}
|
||||
|
||||
- (void) DPSsethalftonephase: (float)x : (float)y
|
||||
{
|
||||
[self notImplemented: _cmd];
|
||||
}
|
||||
|
||||
- (void) DPSsetlinecap: (int)linecap
|
||||
{
|
||||
[gstate DPSsetlinecap: linecap];
|
||||
}
|
||||
|
||||
- (void) DPSsetlinejoin: (int)linejoin
|
||||
{
|
||||
[gstate DPSsetlinejoin: linejoin];
|
||||
}
|
||||
|
||||
- (void) DPSsetlinewidth: (float)width
|
||||
{
|
||||
[gstate DPSsetlinewidth: width];
|
||||
}
|
||||
|
||||
- (void) DPSsetmiterlimit: (float)limit
|
||||
{
|
||||
[gstate DPSsetmiterlimit: limit];
|
||||
}
|
||||
|
||||
- (void) DPSsetstrokeadjust: (int)b
|
||||
{
|
||||
[gstate DPSsetstrokeadjust: b];
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------- */
|
||||
/* Matrix operations */
|
||||
/* ----------------------------------------------------------------------- */
|
||||
- (void) DPSconcat: (const float*)m
|
||||
{
|
||||
[gstate DPSconcat: m];
|
||||
}
|
||||
|
||||
- (void) DPSinitmatrix
|
||||
{
|
||||
[gstate DPSinitmatrix];
|
||||
}
|
||||
|
||||
- (void) DPSrotate: (float)angle
|
||||
{
|
||||
[gstate DPSrotate: angle];
|
||||
}
|
||||
|
||||
- (void) DPSscale: (float)x : (float)y
|
||||
{
|
||||
[gstate DPSscale:x :y];
|
||||
}
|
||||
|
||||
- (void) DPStranslate: (float)x : (float)y
|
||||
{
|
||||
[gstate DPStranslate:x :y];
|
||||
}
|
||||
|
||||
- (NSAffineTransform *) GSCurrentCTM
|
||||
{
|
||||
[self notImplemented: _cmd];
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (void) GSSetCTM: (NSAffineTransform *)ctm
|
||||
{
|
||||
[self notImplemented: _cmd];
|
||||
}
|
||||
|
||||
- (void) GSConcatCTM: (NSAffineTransform *)ctm
|
||||
{
|
||||
[self notImplemented: _cmd];
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------- */
|
||||
/* Paint operations */
|
||||
/* ----------------------------------------------------------------------- */
|
||||
- (void) DPSarc: (float)x : (float)y : (float)r : (float)angle1
|
||||
: (float)angle2
|
||||
{
|
||||
[gstate DPSarc: x : y : r : angle1 : angle2];
|
||||
}
|
||||
|
||||
- (void) DPSarcn: (float)x : (float)y : (float)r : (float)angle1
|
||||
: (float)angle2
|
||||
{
|
||||
[gstate DPSarcn: x : y : r : angle1 : angle2];
|
||||
}
|
||||
|
||||
- (void) DPSarct: (float)x1 : (float)y1 : (float)x2 : (float)y2 : (float)r;
|
||||
{
|
||||
[gstate DPSarct: x1 : y1 : x2 : y2 : r];
|
||||
}
|
||||
|
||||
- (void) DPSclip
|
||||
{
|
||||
[gstate DPSclip];
|
||||
}
|
||||
|
||||
- (void) DPSclosepath
|
||||
{
|
||||
[gstate DPSclosepath];
|
||||
}
|
||||
|
||||
- (void) DPScurveto: (float)x1 : (float)y1 : (float)x2 : (float)y2
|
||||
: (float)x3 : (float)y3
|
||||
{
|
||||
[gstate DPScurveto: x1 : y1 : x2 : y2 : x3 : y3];
|
||||
}
|
||||
|
||||
- (void) DPSeoclip
|
||||
{
|
||||
[gstate DPSeoclip];
|
||||
}
|
||||
|
||||
- (void) DPSeofill
|
||||
{
|
||||
[gstate DPSeofill];
|
||||
}
|
||||
|
||||
- (void) DPSfill
|
||||
{
|
||||
[gstate DPSfill];
|
||||
}
|
||||
|
||||
- (void) DPSflattenpath
|
||||
{
|
||||
[gstate DPSflattenpath];
|
||||
}
|
||||
|
||||
- (void) DPSinitclip
|
||||
{
|
||||
[gstate DPSinitclip];
|
||||
}
|
||||
|
||||
- (void) DPSlineto: (float)x : (float)y
|
||||
{
|
||||
[gstate DPSlineto: x : y];
|
||||
}
|
||||
|
||||
- (void) DPSmoveto: (float)x : (float)y
|
||||
{
|
||||
[gstate DPSmoveto: x : y];
|
||||
}
|
||||
|
||||
- (void) DPSnewpath
|
||||
{
|
||||
[gstate DPSnewpath];
|
||||
}
|
||||
|
||||
- (void) DPSpathbbox: (float*)llx : (float*)lly : (float*)urx : (float*)ury
|
||||
{
|
||||
[gstate DPSpathbbox: llx : lly : urx : ury];
|
||||
}
|
||||
|
||||
- (void) DPSrcurveto: (float)x1 : (float)y1 : (float)x2 : (float)y2
|
||||
: (float)x3 : (float)y3
|
||||
{
|
||||
[gstate DPSrcurveto: x1 : y1 : x2 : y2 : x3 : y3];
|
||||
}
|
||||
|
||||
- (void) DPSrectclip: (float)x : (float)y : (float)w : (float)h
|
||||
{
|
||||
[gstate DPSrectclip: x : y : w : h];
|
||||
}
|
||||
|
||||
- (void) DPSrectfill: (float)x : (float)y : (float)w : (float)h
|
||||
{
|
||||
[gstate DPSrectfill:x :y :w :h];
|
||||
}
|
||||
|
||||
- (void) DPSrectstroke: (float)x : (float)y : (float)w : (float)h
|
||||
{
|
||||
[gstate DPSrectstroke:x :y :w :h];
|
||||
}
|
||||
|
||||
- (void) DPSreversepath
|
||||
{
|
||||
[gstate DPSreversepath];
|
||||
}
|
||||
|
||||
- (void) DPSrlineto: (float)x : (float)y
|
||||
{
|
||||
[gstate DPSrlineto: x : y];
|
||||
}
|
||||
|
||||
- (void) DPSrmoveto: (float)x : (float)y
|
||||
{
|
||||
[gstate DPSrmoveto: x : y];
|
||||
}
|
||||
|
||||
- (void) DPSstroke
|
||||
{
|
||||
[gstate DPSstroke];
|
||||
}
|
||||
|
||||
- (void) GSSendBezierPath: (NSBezierPath *)path
|
||||
{
|
||||
[self notImplemented: _cmd];
|
||||
}
|
||||
|
||||
- (void) GSRectClipList: (const NSRect *)rects : (int) count
|
||||
{
|
||||
[self notImplemented: _cmd];
|
||||
}
|
||||
|
||||
- (void) GSRectFillList: (const NSRect *)rects : (int) count
|
||||
{
|
||||
[self notImplemented: _cmd];
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------- */
|
||||
/* Window system ops */
|
||||
/* ----------------------------------------------------------------------- */
|
||||
- (void) DPScurrentoffset: (int *)x : (int *)y
|
||||
{
|
||||
if (x && y)
|
||||
{
|
||||
NSPoint offset = [gstate offset];
|
||||
*x = offset.x;
|
||||
*y = offset.y;
|
||||
}
|
||||
}
|
||||
|
||||
- (void) DPSsetoffset: (short int)x : (short int)y
|
||||
{
|
||||
[gstate setOffset: NSMakePoint(x,y)];
|
||||
}
|
||||
|
||||
/*-------------------------------------------------------------------------*/
|
||||
/* Graphics Extension Ops */
|
||||
/*-------------------------------------------------------------------------*/
|
||||
- (void) DPScomposite: (float)x : (float)y : (float)w : (float)h
|
||||
: (int)gstateNum : (float)dx : (float)dy : (int)op
|
||||
{
|
||||
NSRect rect;
|
||||
NSPoint p;
|
||||
GSGState *g = gstate;
|
||||
|
||||
if (gstateNum)
|
||||
{
|
||||
[self DPSexecuserobject: gstateNum];
|
||||
ctxt_pop(g, opstack, GSGState);
|
||||
}
|
||||
|
||||
rect = NSMakeRect(x, y, w, h);
|
||||
p = NSMakePoint(dx, dy);
|
||||
|
||||
[gstate compositeGState: g fromRect: rect toPoint: p op: op];
|
||||
}
|
||||
|
||||
- (void) DPScompositerect: (float)x : (float)y : (float)w : (float)h : (int)op
|
||||
{
|
||||
[gstate compositerect: NSMakeRect(x, y, w, h) op: op];
|
||||
}
|
||||
|
||||
- (void) DPSdissolve: (float)x : (float)y : (float)w : (float)h
|
||||
: (int)gstateNum : (float)dx : (float)dy : (float)delta
|
||||
{
|
||||
NSRect rect;
|
||||
NSPoint p;
|
||||
GSGState *g = gstate;
|
||||
|
||||
if (gstateNum)
|
||||
{
|
||||
[self DPSexecuserobject: gstateNum];
|
||||
ctxt_pop(g, opstack, GSGState);
|
||||
}
|
||||
|
||||
rect = NSMakeRect(x, y, w, h);
|
||||
p = NSMakePoint(dx, dy);
|
||||
|
||||
[gstate dissolveGState: g fromRect: rect toPoint: p delta: delta];
|
||||
}
|
||||
|
||||
- (void) GSDrawImage: (NSRect) rect: (void *) imageref
|
||||
{
|
||||
[self notImplemented: _cmd];
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------- */
|
||||
/* Client functions */
|
||||
/* ----------------------------------------------------------------------- */
|
||||
- (void) DPSPrintf: (char *)fmt : (va_list)args
|
||||
{
|
||||
/* Do nothing. We can't parse PostScript */
|
||||
}
|
||||
|
||||
- (void) DPSWriteData: (char *)buf : (unsigned int)count
|
||||
{
|
||||
/* Do nothing. We can't parse PostScript */
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
/* ----------------------------------------------------------------------- */
|
||||
/* NSGraphics Ops */
|
||||
/* ----------------------------------------------------------------------- */
|
||||
@implementation GSContext (NSGraphics)
|
||||
/*
|
||||
* Render Bitmap Images
|
||||
*/
|
||||
- (void) NSDrawBitmap: (NSRect) rect : (int) pixelsWide : (int) pixelsHigh
|
||||
: (int) bitsPerSample : (int) samplesPerPixel
|
||||
: (int) bitsPerPixel : (int) bytesPerRow : (BOOL) isPlanar
|
||||
: (BOOL) hasAlpha : (NSString *) colorSpaceName
|
||||
: (const unsigned char *const [5]) data
|
||||
{
|
||||
NSAffineTransform *trans;
|
||||
NSSize scale;
|
||||
|
||||
// Compute the transformation matrix
|
||||
scale = NSMakeSize(NSWidth(rect) / pixelsWide,
|
||||
NSHeight(rect) / pixelsHigh);
|
||||
trans = [NSAffineTransform transform];
|
||||
[trans translateToPoint: rect.origin];
|
||||
[trans scaleBy: scale.width : scale.height];
|
||||
|
||||
/* This does essentially what the DPS...image operators do, so
|
||||
as to avoid an extra method call */
|
||||
[gstate DPSimage: trans
|
||||
: pixelsWide : pixelsHigh
|
||||
: bitsPerSample : samplesPerPixel
|
||||
: bitsPerPixel : bytesPerRow
|
||||
: isPlanar
|
||||
: hasAlpha : colorSpaceName
|
||||
: data];
|
||||
}
|
||||
|
||||
- (void) GSWSetViewIsFlipped: (BOOL) flipped
|
||||
{
|
||||
if(gstate)
|
||||
gstate->viewIsFlipped = flipped;
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------- */
|
||||
/* Data operations - Obsolete but possibly still useful */
|
||||
/* ----------------------------------------------------------------------- */
|
||||
|
||||
- (void)DPSdefineuserobject
|
||||
{
|
||||
int n;
|
||||
id obj;
|
||||
NSNumber *number;
|
||||
ctxt_pop(obj, opstack, NSObject);
|
||||
ctxt_pop(number, opstack, NSNumber);
|
||||
n = [number intValue];
|
||||
if (n < 0)
|
||||
DPS_ERROR(DPSinvalidparam, @"Invalid userobject index");
|
||||
else
|
||||
NSMapInsert(gtable, (void *)n, obj);
|
||||
}
|
||||
|
||||
- (void)DPSexecuserobject: (int)index
|
||||
{
|
||||
if (index < 0 || NSMapGet(gtable, (void *)index) == nil)
|
||||
{
|
||||
DPS_ERROR(DPSinvalidparam, @"Invalid userobject index");
|
||||
return;
|
||||
}
|
||||
ctxt_push((id)NSMapGet(gtable, (void *)index), opstack);
|
||||
}
|
||||
|
||||
- (void)DPSundefineuserobject: (int)index
|
||||
{
|
||||
if (index < 0 || NSMapGet(gtable, (void *)index) == nil)
|
||||
{
|
||||
DPS_ERROR(DPSinvalidparam, @"Invalid gstate index");
|
||||
return;
|
||||
}
|
||||
NSMapRemove(gtable, (void *)index);
|
||||
}
|
||||
|
||||
- (void)DPSclear
|
||||
{
|
||||
GSIArrayEmpty((GSIArray)opstack);
|
||||
GSIArrayInitWithZoneAndCapacity((GSIArray)opstack, [self zone], 2);
|
||||
}
|
||||
|
||||
- (void)DPScopy: (int)n
|
||||
{
|
||||
unsigned count = GSIArrayCount((GSIArray)opstack);
|
||||
int i;
|
||||
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
NSObject *obj = (GSIArrayItemAtIndex((GSIArray)opstack, count - n + i)).obj;
|
||||
|
||||
ctxt_push(obj, opstack);
|
||||
}
|
||||
}
|
||||
|
||||
- (void)DPScount: (int *)n
|
||||
{
|
||||
CHECK_NULL_OUTPUT(n);
|
||||
*n = GSIArrayCount((GSIArray)opstack);
|
||||
}
|
||||
|
||||
- (void)DPSdup
|
||||
{
|
||||
NSObject *obj = (GSIArrayLastItem((GSIArray)opstack)).obj;
|
||||
|
||||
ctxt_push(obj, opstack);
|
||||
}
|
||||
|
||||
- (void)DPSexch
|
||||
{
|
||||
unsigned count = GSIArrayCount((GSIArray)opstack);
|
||||
|
||||
if (count < 2)
|
||||
{
|
||||
DPS_ERROR(DPSstackunderflow, @"Attempt to exch in empty stack");
|
||||
return;
|
||||
}
|
||||
GSIArrayInsertItem((GSIArray)opstack,
|
||||
GSIArrayLastItem((GSIArray)opstack), count-2);
|
||||
GSIArrayRemoveLastItem((GSIArray)opstack);
|
||||
}
|
||||
|
||||
- (void)DPSindex: (int)i
|
||||
{
|
||||
unsigned count = GSIArrayCount((GSIArray)opstack);
|
||||
NSObject *obj = (GSIArrayItemAtIndex((GSIArray)opstack, count - i)).obj;
|
||||
|
||||
ctxt_push(obj, opstack);
|
||||
}
|
||||
|
||||
- (void)DPSpop
|
||||
{
|
||||
id obj;
|
||||
ctxt_pop(obj, opstack, NSObject);
|
||||
}
|
||||
@end
|
603
Source/gsc/GSGState.m
Normal file
603
Source/gsc/GSGState.m
Normal file
|
@ -0,0 +1,603 @@
|
|||
/* GSGState - Generic graphic state
|
||||
|
||||
Copyright (C) 1998 Free Software Foundation, Inc.
|
||||
|
||||
Written by: Adam Fedor <fedor@gnu.org>
|
||||
Date: Mar 2002
|
||||
|
||||
This file is part of the GNU Objective C User Interface Library.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include <Foundation/NSObjCRuntime.h>
|
||||
#include <AppKit/NSAffineTransform.h>
|
||||
#include <AppKit/NSBezierPath.h>
|
||||
#include <AppKit/NSFont.h>
|
||||
#include "gsc/GSContext.h"
|
||||
#include "gsc/GSGState.h"
|
||||
#include "math.h"
|
||||
|
||||
#define CHECK_PATH \
|
||||
if (!path) \
|
||||
{ \
|
||||
path = [NSBezierPath new]; \
|
||||
}
|
||||
|
||||
#define AINDEX 5
|
||||
|
||||
@implementation GSGState
|
||||
|
||||
/* Designated initializer. */
|
||||
- initWithDrawContext: (GSContext *)drawContext
|
||||
{
|
||||
[super init];
|
||||
|
||||
drawcontext = drawContext;
|
||||
ctm = [[NSAffineTransform allocWithZone: GSObjCZone(self)] init];
|
||||
path = nil;
|
||||
font = nil;
|
||||
offset = NSMakePoint(0, 0);
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
TEST_RELEASE(font);
|
||||
TEST_RELEASE(path);
|
||||
RELEASE(ctm);
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (id) deepen
|
||||
{
|
||||
NSZone *zone = GSObjCZone(self);
|
||||
|
||||
if (path)
|
||||
self->path = [path copyWithZone: zone];
|
||||
|
||||
self->ctm = [ctm copyWithZone: zone];
|
||||
|
||||
// Just retain the font
|
||||
if (font != nil)
|
||||
RETAIN(font);
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- copyWithZone: (NSZone *)zone
|
||||
{
|
||||
GSGState *new = (GSGState *)NSCopyObject(self, 0, zone);
|
||||
/* Do a deep copy since gstates are isolated from each other */
|
||||
return [new deepen];
|
||||
}
|
||||
|
||||
- (void) setFont: (NSFont*)newFont
|
||||
{
|
||||
if (font == newFont)
|
||||
return;
|
||||
ASSIGN(font, newFont);
|
||||
}
|
||||
|
||||
- (NSFont*) currentFont
|
||||
{
|
||||
return font;
|
||||
}
|
||||
|
||||
- (void) setOffset: (NSPoint)theOffset
|
||||
{
|
||||
offset = theOffset;
|
||||
}
|
||||
|
||||
- (NSPoint) offset
|
||||
{
|
||||
return offset;
|
||||
}
|
||||
|
||||
- (void) compositeGState: (GSGState *)source
|
||||
fromRect: (NSRect)aRect
|
||||
toPoint: (NSPoint)aPoint
|
||||
op: (NSCompositingOperation)op
|
||||
{
|
||||
[self subclassResponsibility: _cmd];
|
||||
}
|
||||
|
||||
- (void) dissolveGState: (GSGState *)source
|
||||
fromRect: (NSRect)aRect
|
||||
toPoint: (NSPoint)aPoint
|
||||
delta: (float)delta
|
||||
{
|
||||
[self subclassResponsibility: _cmd];
|
||||
}
|
||||
|
||||
- (void) compositerect: (NSRect)aRect
|
||||
op: (NSCompositingOperation)op
|
||||
{
|
||||
[self subclassResponsibility: _cmd];
|
||||
}
|
||||
|
||||
- (NSPoint) pointInMatrixSpace: (NSPoint)aPoint
|
||||
{
|
||||
return [ctm pointInMatrixSpace: aPoint];
|
||||
}
|
||||
|
||||
- (NSPoint) deltaPointInMatrixSpace: (NSPoint)aPoint
|
||||
{
|
||||
return [ctm deltaPointInMatrixSpace: aPoint];
|
||||
}
|
||||
|
||||
- (NSRect) rectInMatrixSpace: (NSRect)rect
|
||||
{
|
||||
return [ctm rectInMatrixSpace: rect];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation GSGState (Ops)
|
||||
|
||||
/* ----------------------------------------------------------------------- */
|
||||
/* Color operations */
|
||||
/* ----------------------------------------------------------------------- */
|
||||
- (void) DPScurrentalpha: (float*)a
|
||||
{
|
||||
[self notImplemented: _cmd];
|
||||
}
|
||||
|
||||
- (void) DPScurrentcmykcolor: (float*)c : (float*)m : (float*)y : (float*)k
|
||||
{
|
||||
[self notImplemented: _cmd];
|
||||
}
|
||||
|
||||
- (void) DPScurrentgray: (float*)gray
|
||||
{
|
||||
[self notImplemented: _cmd];
|
||||
}
|
||||
|
||||
- (void) DPScurrenthsbcolor: (float*)h : (float*)s : (float*)b
|
||||
{
|
||||
[self notImplemented: _cmd];
|
||||
}
|
||||
|
||||
- (void) DPScurrentrgbcolor: (float*)r : (float*)g : (float*)b
|
||||
{
|
||||
[self notImplemented: _cmd];
|
||||
}
|
||||
|
||||
- (void) DPSsetalpha: (float)a
|
||||
{
|
||||
[self notImplemented: _cmd];
|
||||
}
|
||||
|
||||
- (void) DPSsetcmykcolor: (float)c : (float)m : (float)y : (float)k
|
||||
{
|
||||
[self notImplemented: _cmd];
|
||||
}
|
||||
|
||||
- (void) DPSsetgray: (float)gray
|
||||
{
|
||||
[self notImplemented: _cmd];
|
||||
}
|
||||
|
||||
- (void) DPSsethsbcolor: (float)h : (float)s : (float)b
|
||||
{
|
||||
[self notImplemented: _cmd];
|
||||
}
|
||||
|
||||
- (void) DPSsetrgbcolor: (float)r : (float)g : (float)b
|
||||
{
|
||||
[self notImplemented: _cmd];
|
||||
}
|
||||
|
||||
|
||||
- (void) GSSetFillColorspace: (NSDictionary *)dict
|
||||
{
|
||||
[self notImplemented: _cmd];
|
||||
}
|
||||
|
||||
- (void) GSSetStrokeColorspace: (NSDictionary *)dict
|
||||
{
|
||||
[self notImplemented: _cmd];
|
||||
}
|
||||
|
||||
- (void) GSSetFillColor: (float *)values
|
||||
{
|
||||
[self notImplemented: _cmd];
|
||||
}
|
||||
|
||||
- (void) GSSetStrokeColor: (float *)values
|
||||
{
|
||||
[self notImplemented: _cmd];
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------- */
|
||||
/* Text operations */
|
||||
/* ----------------------------------------------------------------------- */
|
||||
- (void) DPSashow: (float)x : (float)y : (const char*)s
|
||||
{
|
||||
[self subclassResponsibility: _cmd];
|
||||
}
|
||||
|
||||
- (void) DPSawidthshow: (float)cx : (float)cy : (int)c : (float)ax : (float)ay
|
||||
: (const char*)s
|
||||
{
|
||||
[self subclassResponsibility: _cmd];
|
||||
}
|
||||
|
||||
- (void) DPScharpath: (const char*)s : (int)b
|
||||
{
|
||||
[self subclassResponsibility: _cmd];
|
||||
}
|
||||
|
||||
- (void) DPSshow: (const char*)s
|
||||
{
|
||||
[self subclassResponsibility: _cmd];
|
||||
}
|
||||
|
||||
- (void) DPSwidthshow: (float)x : (float)y : (int)c : (const char*)s
|
||||
{
|
||||
[self subclassResponsibility: _cmd];
|
||||
}
|
||||
|
||||
- (void) DPSxshow: (const char*)s : (const float*)numarray : (int)size
|
||||
{
|
||||
[self subclassResponsibility: _cmd];
|
||||
}
|
||||
|
||||
- (void) DPSxyshow: (const char*)s : (const float*)numarray : (int)size
|
||||
{
|
||||
[self subclassResponsibility: _cmd];
|
||||
}
|
||||
|
||||
- (void) DPSyshow: (const char*)s : (const float*)numarray : (int)size
|
||||
{
|
||||
[self subclassResponsibility: _cmd];
|
||||
}
|
||||
|
||||
|
||||
/* ----------------------------------------------------------------------- */
|
||||
/* Gstate operations */
|
||||
/* ----------------------------------------------------------------------- */
|
||||
- (void) DPSinitgraphics
|
||||
{
|
||||
[self subclassResponsibility: _cmd];
|
||||
}
|
||||
|
||||
- (void)DPScurrentflat: (float *)flatness
|
||||
{
|
||||
if (path)
|
||||
*flatness = [path flatness];
|
||||
else
|
||||
*flatness = 1.0;
|
||||
}
|
||||
|
||||
- (void) DPScurrentlinecap: (int*)linecap
|
||||
{
|
||||
[self subclassResponsibility: _cmd];
|
||||
}
|
||||
|
||||
- (void) DPScurrentlinejoin: (int*)linejoin
|
||||
{
|
||||
[self subclassResponsibility: _cmd];
|
||||
}
|
||||
|
||||
- (void) DPScurrentlinewidth: (float*)width
|
||||
{
|
||||
[self subclassResponsibility: _cmd];
|
||||
}
|
||||
|
||||
- (void) DPScurrentmiterlimit: (float*)limit
|
||||
{
|
||||
[self subclassResponsibility: _cmd];
|
||||
}
|
||||
|
||||
- (void)DPScurrentpoint: (float *)x : (float *)y
|
||||
{
|
||||
NSAffineTransform *ictm;
|
||||
NSPoint user;
|
||||
|
||||
// This is rather slow, but it is not used very often
|
||||
ictm = [ctm copyWithZone: GSObjCZone(self)];
|
||||
[ictm inverse];
|
||||
user = [ictm pointInMatrixSpace: [path currentPoint]];
|
||||
RELEASE(ictm);
|
||||
*x = user.x;
|
||||
*y = user.y;
|
||||
}
|
||||
|
||||
- (void) DPScurrentstrokeadjust: (int*)b
|
||||
{
|
||||
[self subclassResponsibility: _cmd];
|
||||
}
|
||||
|
||||
- (void) DPSsetdash: (const float*)pat : (int)size : (float)offset
|
||||
{
|
||||
[self subclassResponsibility: _cmd];
|
||||
}
|
||||
|
||||
- (void)DPSsetflat: (float)flatness
|
||||
{
|
||||
if (path)
|
||||
[path setFlatness: flatness];
|
||||
}
|
||||
|
||||
- (void) DPSsetlinecap: (int)linecap
|
||||
{
|
||||
[self subclassResponsibility: _cmd];
|
||||
}
|
||||
|
||||
- (void) DPSsetlinejoin: (int)linejoin
|
||||
{
|
||||
[self subclassResponsibility: _cmd];
|
||||
}
|
||||
|
||||
- (void) DPSsetlinewidth: (float)width
|
||||
{
|
||||
[self subclassResponsibility: _cmd];
|
||||
}
|
||||
|
||||
- (void) DPSsetmiterlimit: (float)limit
|
||||
{
|
||||
[self subclassResponsibility: _cmd];
|
||||
}
|
||||
|
||||
- (void) DPSsetstrokeadjust: (int)b
|
||||
{
|
||||
[self subclassResponsibility: _cmd];
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------- */
|
||||
/* Matrix operations */
|
||||
/* ----------------------------------------------------------------------- */
|
||||
- (void)DPSconcat: (const float *)m
|
||||
{
|
||||
[ctm concatenateWithMatrix: m];
|
||||
}
|
||||
|
||||
- (void)DPSinitmatrix
|
||||
{
|
||||
[ctm makeIdentityMatrix];
|
||||
}
|
||||
|
||||
- (void)DPSrotate: (float)angle
|
||||
{
|
||||
[ctm rotateByDegrees: angle];
|
||||
}
|
||||
|
||||
- (void)DPSscale: (float)x : (float)y
|
||||
{
|
||||
[ctm scaleBy: x : y];
|
||||
}
|
||||
|
||||
- (void)DPStranslate: (float)x : (float)y
|
||||
{
|
||||
[ctm translateToPoint: NSMakePoint(x, y)];
|
||||
}
|
||||
|
||||
- (NSAffineTransform *) GSCurrentCTM
|
||||
{
|
||||
return [ctm copy];
|
||||
}
|
||||
|
||||
- (void) GSSetCTM: (NSAffineTransform *)newctm
|
||||
{
|
||||
ASSIGN(ctm, newctm);
|
||||
}
|
||||
|
||||
- (void) GSConcatCTM: (NSAffineTransform *)newctm
|
||||
{
|
||||
[ctm concatenateWith: newctm];
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------- */
|
||||
/* Paint operations */
|
||||
/* ----------------------------------------------------------------------- */
|
||||
- (void) DPSarc: (float)x : (float)y : (float)r : (float)angle1 : (float)angle2
|
||||
{
|
||||
NSPoint center = [ctm pointInMatrixSpace: NSMakePoint(x, y)];
|
||||
NSSize radius = [ctm sizeInMatrixSpace: NSMakeSize(r, r)];
|
||||
|
||||
CHECK_PATH;
|
||||
[path appendBezierPathWithArcWithCenter: center
|
||||
radius: radius.width
|
||||
startAngle: angle1
|
||||
endAngle: angle2
|
||||
clockwise: NO];
|
||||
}
|
||||
|
||||
- (void) DPSarcn: (float)x : (float)y : (float)r : (float)angle1 : (float)angle2
|
||||
{
|
||||
NSPoint center = [ctm pointInMatrixSpace: NSMakePoint(x, y)];
|
||||
NSSize radius = [ctm sizeInMatrixSpace: NSMakeSize(r, r)];
|
||||
|
||||
CHECK_PATH;
|
||||
[path appendBezierPathWithArcWithCenter: center
|
||||
radius: radius.width
|
||||
startAngle: angle1
|
||||
endAngle: angle2
|
||||
clockwise: YES];
|
||||
}
|
||||
|
||||
- (void)DPSarct: (float)x1 : (float)y1 : (float)x2 : (float)y2 : (float)r
|
||||
{
|
||||
[self notImplemented: _cmd];
|
||||
}
|
||||
|
||||
- (void) DPSclip
|
||||
{
|
||||
[self subclassResponsibility: _cmd];
|
||||
}
|
||||
|
||||
- (void)DPSclosepath
|
||||
{
|
||||
CHECK_PATH;
|
||||
[path closePath];
|
||||
}
|
||||
|
||||
- (void)DPScurveto: (float)x1 : (float)y1 : (float)x2 : (float)y2 : (float)x3 : (float)y3
|
||||
{
|
||||
NSPoint p1 = [ctm pointInMatrixSpace: NSMakePoint(x1, y1)];
|
||||
NSPoint p2 = [ctm pointInMatrixSpace: NSMakePoint(x2, y2)];
|
||||
NSPoint p3 = [ctm pointInMatrixSpace: NSMakePoint(x3, y3)];
|
||||
|
||||
CHECK_PATH;
|
||||
[path curveToPoint: p3 controlPoint1: p1 controlPoint2: p2];
|
||||
}
|
||||
|
||||
- (void) DPSeoclip
|
||||
{
|
||||
[self subclassResponsibility: _cmd];
|
||||
}
|
||||
|
||||
- (void) DPSeofill
|
||||
{
|
||||
[self subclassResponsibility: _cmd];
|
||||
}
|
||||
|
||||
- (void) DPSfill
|
||||
{
|
||||
[self subclassResponsibility: _cmd];
|
||||
}
|
||||
|
||||
- (void)DPSflattenpath
|
||||
{
|
||||
if (path)
|
||||
ASSIGN(path, [path bezierPathByFlatteningPath]);
|
||||
}
|
||||
|
||||
- (void) DPSinitclip;
|
||||
{
|
||||
[self subclassResponsibility: _cmd];
|
||||
}
|
||||
|
||||
- (void)DPSlineto: (float)x : (float)y
|
||||
{
|
||||
NSPoint p = [ctm pointInMatrixSpace: NSMakePoint(x, y)];
|
||||
|
||||
CHECK_PATH;
|
||||
[path lineToPoint: p];
|
||||
}
|
||||
|
||||
- (void)DPSmoveto: (float)x : (float)y
|
||||
{
|
||||
NSPoint p = [ctm pointInMatrixSpace: NSMakePoint(x, y)];
|
||||
|
||||
CHECK_PATH;
|
||||
[path moveToPoint: p];
|
||||
}
|
||||
|
||||
- (void)DPSnewpath
|
||||
{
|
||||
if (path)
|
||||
[path removeAllPoints];
|
||||
}
|
||||
|
||||
- (void)DPSpathbbox: (float *)llx : (float *)lly : (float *)urx : (float *)ury
|
||||
{
|
||||
if (path)
|
||||
{
|
||||
NSRect rect = [path controlPointBounds];
|
||||
|
||||
// FIXME Should convert back to user space
|
||||
if (llx)
|
||||
*llx = NSMinX(rect);
|
||||
if (lly)
|
||||
*lly = NSMinY(rect);
|
||||
if (urx)
|
||||
*urx = NSMaxX(rect);
|
||||
if (ury)
|
||||
*ury = NSMaxY(rect);
|
||||
}
|
||||
}
|
||||
|
||||
- (void)DPSrcurveto: (float)x1 : (float)y1 : (float)x2 : (float)y2 : (float)x3 : (float)y3
|
||||
{
|
||||
NSPoint p1 = [ctm deltaPointInMatrixSpace: NSMakePoint(x1, y1)];
|
||||
NSPoint p2 = [ctm deltaPointInMatrixSpace: NSMakePoint(x2, y2)];
|
||||
NSPoint p3 = [ctm deltaPointInMatrixSpace: NSMakePoint(x3, y3)];
|
||||
|
||||
CHECK_PATH;
|
||||
[path relativeCurveToPoint: p3
|
||||
controlPoint1: p1
|
||||
controlPoint2: p2];
|
||||
}
|
||||
|
||||
- (void) DPSrectclip: (float)x : (float)y : (float)w : (float)h
|
||||
{
|
||||
[self subclassResponsibility: _cmd];
|
||||
}
|
||||
|
||||
- (void) DPSrectfill: (float)x : (float)y : (float)w : (float)h
|
||||
{
|
||||
[self subclassResponsibility: _cmd];
|
||||
}
|
||||
|
||||
- (void) DPSrectstroke: (float)x : (float)y : (float)w : (float)h
|
||||
{
|
||||
[self subclassResponsibility: _cmd];
|
||||
}
|
||||
|
||||
- (void)DPSreversepath
|
||||
{
|
||||
if (path)
|
||||
ASSIGN(path, [path bezierPathByReversingPath]);
|
||||
}
|
||||
|
||||
- (void)DPSrlineto: (float)x : (float)y
|
||||
{
|
||||
NSPoint p = [ctm deltaPointInMatrixSpace: NSMakePoint(x, y)];
|
||||
|
||||
CHECK_PATH;
|
||||
[path relativeLineToPoint: p];
|
||||
}
|
||||
|
||||
- (void)DPSrmoveto: (float)x : (float)y
|
||||
{
|
||||
NSPoint p = [ctm deltaPointInMatrixSpace: NSMakePoint(x, y)];
|
||||
|
||||
CHECK_PATH;
|
||||
[path relativeMoveToPoint: p];
|
||||
}
|
||||
|
||||
- (void) DPSstroke;
|
||||
{
|
||||
[self subclassResponsibility: _cmd];
|
||||
}
|
||||
|
||||
- (void) GSSendBezierPath: (NSBezierPath *)newpath
|
||||
{
|
||||
if (path)
|
||||
[path appendBezierPath: path];
|
||||
else
|
||||
ASSIGN(path, newpath);
|
||||
}
|
||||
|
||||
- (void) GSRectFillList: (const NSRect *)rects : (int) count
|
||||
{
|
||||
[self notImplemented: _cmd];
|
||||
}
|
||||
|
||||
- (void)DPSimage: (NSAffineTransform*) matrix
|
||||
: (int) pixelsWide : (int) pixelsHigh
|
||||
: (int) bitsPerSample : (int) samplesPerPixel
|
||||
: (int) bitsPerPixel : (int) bytesPerRow : (BOOL) isPlanar
|
||||
: (BOOL) hasAlpha : (NSString *) colorSpaceName
|
||||
: (const unsigned char *const [5]) data
|
||||
{
|
||||
[self subclassResponsibility: _cmd];
|
||||
}
|
||||
@end
|
||||
|
||||
|
790
Source/gsc/GSStreamContext.m
Normal file
790
Source/gsc/GSStreamContext.m
Normal file
|
@ -0,0 +1,790 @@
|
|||
/* -*- C++ -*-
|
||||
GSStreamContext - Drawing context using the XR Library.
|
||||
|
||||
Copyright (C) 1995 Free Software Foundation, Inc.
|
||||
|
||||
Written by: Adam Fedor <fedor@boulder.colorado.edu>
|
||||
Date: Nov 1995
|
||||
|
||||
This file is part of the GNU Objective C User Interface Library.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "gsc/GSContext.h"
|
||||
#include "gsc/GSStreamContext.h"
|
||||
#include <Foundation/NSArray.h>
|
||||
#include <Foundation/NSData.h>
|
||||
#include <Foundation/NSDebug.h>
|
||||
#include <Foundation/NSDictionary.h>
|
||||
#include <Foundation/NSString.h>
|
||||
#include <Foundation/NSUserDefaults.h>
|
||||
#include <Foundation/NSValue.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
@interface GSStreamContext (Private)
|
||||
|
||||
- (void) output: (const char*)s;
|
||||
|
||||
@end
|
||||
|
||||
@implementation GSStreamContext
|
||||
|
||||
- (void) destroyContext;
|
||||
{
|
||||
if (gstream)
|
||||
fclose(gstream);
|
||||
[super destroyContext];
|
||||
}
|
||||
|
||||
- initWithContextInfo: (NSDictionary *)info
|
||||
{
|
||||
if (info && [info objectForKey: @"NSOutputFile"])
|
||||
{
|
||||
NSString *path = [info objectForKey: @"NSOutputFile"];
|
||||
gstream = fopen([path fileSystemRepresentation], "w");
|
||||
if (!gstream)
|
||||
{
|
||||
NSDebugLLog(@"GSContext", @"%@: Could not open printer file %@",
|
||||
DPSinvalidfileaccess, path);
|
||||
return nil;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
NSDebugLLog(@"GSContext", @"%@: No stream file specified",
|
||||
DPSconfigurationerror);
|
||||
return nil;
|
||||
}
|
||||
|
||||
[super initWithContextInfo: info];
|
||||
return self;
|
||||
}
|
||||
|
||||
- (BOOL)isDrawingToScreen
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (GSGState *) currentGState
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation GSStreamContext (Ops)
|
||||
/* ----------------------------------------------------------------------- */
|
||||
/* Color operations */
|
||||
/* ----------------------------------------------------------------------- */
|
||||
- (void) DPScurrentalpha: (float*) a
|
||||
{
|
||||
NSLog(@"DPSinvalidcontext: getting values from stream context");
|
||||
}
|
||||
|
||||
- (void) DPScurrentcmykcolor: (float*) c: (float*) m: (float*) y: (float*) k
|
||||
{
|
||||
NSLog(@"DPSinvalidcontext: getting values from stream context");
|
||||
}
|
||||
|
||||
- (void) DPScurrentgray: (float*) gray
|
||||
{
|
||||
NSLog(@"DPSinvalidcontext: getting values from stream context");
|
||||
}
|
||||
|
||||
- (void) DPScurrenthsbcolor: (float*) h: (float*) s: (float*) b
|
||||
{
|
||||
NSLog(@"DPSinvalidcontext: getting values from stream context");
|
||||
}
|
||||
|
||||
- (void) DPScurrentrgbcolor: (float*) r: (float*) g: (float*) b
|
||||
{
|
||||
NSLog(@"DPSinvalidcontext: getting values from stream context");
|
||||
}
|
||||
|
||||
- (void) DPSsetalpha: (float) a
|
||||
{
|
||||
fprintf(gstream, "%g setalpha\n", a);
|
||||
}
|
||||
|
||||
- (void) DPSsetcmykcolor: (float) c: (float) m: (float) y: (float) k
|
||||
{
|
||||
fprintf(gstream, "%g %g %g %g setcmykcolor\n", c, m, y, k);
|
||||
}
|
||||
|
||||
- (void) DPSsetgray: (float) gray
|
||||
{
|
||||
fprintf(gstream, "%g setgray\n", gray);
|
||||
}
|
||||
|
||||
- (void) DPSsethsbcolor: (float) h: (float) s: (float) b
|
||||
{
|
||||
fprintf(gstream, "%g %g %g sethsbcolor\n", h, s, b);
|
||||
}
|
||||
|
||||
- (void) DPSsetrgbcolor: (float) r: (float) g: (float) b
|
||||
{
|
||||
fprintf(gstream, "%g %g %g setrgbcolor\n", r, g, b);
|
||||
}
|
||||
|
||||
|
||||
- (void) GSSetFillColorspace: (NSDictionary *) dict
|
||||
{
|
||||
[self notImplemented: _cmd];
|
||||
}
|
||||
|
||||
- (void) GSSetStrokeColorspace: (NSDictionary *) dict
|
||||
{
|
||||
[self notImplemented: _cmd];
|
||||
}
|
||||
|
||||
- (void) GSSetFillColor: (float *) values
|
||||
{
|
||||
[self notImplemented: _cmd];
|
||||
}
|
||||
|
||||
- (void) GSSetStrokeColor: (float *) values
|
||||
{
|
||||
[self notImplemented: _cmd];
|
||||
}
|
||||
|
||||
|
||||
/* ----------------------------------------------------------------------- */
|
||||
/* Text operations */
|
||||
/* ----------------------------------------------------------------------- */
|
||||
- (void) DPSashow: (float) x: (float) y: (const char*) s
|
||||
{
|
||||
fprintf(gstream, "%g %g %s ashow\n", x, y, s);
|
||||
}
|
||||
|
||||
- (void) DPSawidthshow: (float) cx: (float) cy: (int) c: (float) ax: (float) ay: (const char*) s
|
||||
{
|
||||
fprintf(gstream, "%g %g %d %g %g %s awidthshow\n", cx, cy, c, ax, ay, s);
|
||||
}
|
||||
|
||||
- (void) DPScharpath: (const char*) s: (int) b
|
||||
{
|
||||
fprintf(gstream, "%s %d charpath\n", s, b);
|
||||
}
|
||||
|
||||
- (void) DPSshow: (const char*) s
|
||||
{
|
||||
fprintf(gstream, "%s show\n", s);
|
||||
}
|
||||
|
||||
- (void) DPSwidthshow: (float) x: (float) y: (int) c: (const char*) s
|
||||
{
|
||||
fprintf(gstream, "%g %g %d %s widthshow\n", x, y, c, s);
|
||||
}
|
||||
|
||||
- (void) DPSxshow: (const char*) s: (const float*) numarray: (int) size
|
||||
{
|
||||
}
|
||||
|
||||
- (void) DPSxyshow: (const char*) s: (const float*) numarray: (int) size
|
||||
{
|
||||
}
|
||||
|
||||
- (void) DPSyshow: (const char*) s: (const float*) numarray: (int) size
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
- (void) GSSetCharacterSpacing: (float) extra
|
||||
{
|
||||
[self notImplemented: _cmd];
|
||||
}
|
||||
|
||||
- (void) GSSetFont: (NSFont*) font
|
||||
{
|
||||
[self notImplemented: _cmd];
|
||||
}
|
||||
|
||||
- (void) GSSetFontSize: (float) size
|
||||
{
|
||||
[self notImplemented: _cmd];
|
||||
}
|
||||
|
||||
- (NSAffineTransform *) GSGetTextCTM
|
||||
{
|
||||
NSLog(@"DPSinvalidcontext: getting values from stream context");
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (NSPoint) GSGetTextPosition
|
||||
{
|
||||
NSLog(@"DPSinvalidcontext: getting values from stream context");
|
||||
return NSMakePoint(0,0);
|
||||
}
|
||||
|
||||
- (void) GSSetTextCTM: (NSAffineTransform *) ctm
|
||||
{
|
||||
[self notImplemented: _cmd];
|
||||
}
|
||||
|
||||
- (void) GSSetTextDrawingMode: (GSTextDrawingMode) mode
|
||||
{
|
||||
[self notImplemented: _cmd];
|
||||
}
|
||||
|
||||
- (void) GSSetTextPosition: (NSPoint) loc
|
||||
{
|
||||
[self notImplemented: _cmd];
|
||||
}
|
||||
|
||||
- (void) GSShowText: (const char *) string: (size_t) length
|
||||
{
|
||||
[self notImplemented: _cmd];
|
||||
}
|
||||
|
||||
- (void) GSShowGlyphs: (const NSGlyph *) glyphs: (size_t) length
|
||||
{
|
||||
[self notImplemented: _cmd];
|
||||
}
|
||||
|
||||
|
||||
/* ----------------------------------------------------------------------- */
|
||||
/* Gstate Handling */
|
||||
/* ----------------------------------------------------------------------- */
|
||||
- (void) DPScurrentgstate: (int) gst
|
||||
{
|
||||
NSLog(@"DPSinvalidcontext: getting values from stream context");
|
||||
}
|
||||
|
||||
- (void) DPSgrestore
|
||||
{
|
||||
fprintf(gstream, "grestore\n");
|
||||
}
|
||||
|
||||
- (void) DPSgsave
|
||||
{
|
||||
fprintf(gstream, "gsave\n");
|
||||
}
|
||||
|
||||
- (void) DPSgstate
|
||||
{
|
||||
}
|
||||
|
||||
- (void) DPSinitgraphics
|
||||
{
|
||||
fprintf(gstream, "initgraphics\n");
|
||||
}
|
||||
|
||||
- (void) DPSsetgstate: (int) gst
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
- (int) GSDefineGState
|
||||
{
|
||||
NSLog(@"DPSinvalidcontext: getting values from stream context");
|
||||
return 0;
|
||||
}
|
||||
|
||||
- (void) GSUndefineGState: (int) gst
|
||||
{
|
||||
[self notImplemented: _cmd];
|
||||
}
|
||||
|
||||
- (void) GSReplaceGState: (int) gst
|
||||
{
|
||||
[self notImplemented: _cmd];
|
||||
}
|
||||
|
||||
- (void) GSCreateGState: (int) gst
|
||||
{
|
||||
[self notImplemented: _cmd];
|
||||
}
|
||||
|
||||
- (void) GSSetGState: (int) gst
|
||||
{
|
||||
[self notImplemented: _cmd];
|
||||
}
|
||||
|
||||
|
||||
/* ----------------------------------------------------------------------- */
|
||||
/* Gstate operations */
|
||||
/* ----------------------------------------------------------------------- */
|
||||
- (void) DPScurrentflat: (float*) flatness
|
||||
{
|
||||
NSLog(@"DPSinvalidcontext: getting values from stream context");
|
||||
}
|
||||
|
||||
- (void) DPScurrentlinecap: (int*) linecap
|
||||
{
|
||||
NSLog(@"DPSinvalidcontext: getting values from stream context");
|
||||
}
|
||||
|
||||
- (void) DPScurrentlinejoin: (int*) linejoin
|
||||
{
|
||||
NSLog(@"DPSinvalidcontext: getting values from stream context");
|
||||
}
|
||||
|
||||
- (void) DPScurrentlinewidth: (float*) width
|
||||
{
|
||||
NSLog(@"DPSinvalidcontext: getting values from stream context");
|
||||
}
|
||||
|
||||
- (void) DPScurrentmiterlimit: (float*) limit
|
||||
{
|
||||
NSLog(@"DPSinvalidcontext: getting values from stream context");
|
||||
}
|
||||
|
||||
- (void) DPScurrentpoint: (float*) x: (float*) y
|
||||
{
|
||||
NSLog(@"DPSinvalidcontext: getting values from stream context");
|
||||
}
|
||||
|
||||
- (void) DPScurrentstrokeadjust: (int*) b
|
||||
{
|
||||
NSLog(@"DPSinvalidcontext: getting values from stream context");
|
||||
}
|
||||
|
||||
- (void) DPSsetdash: (const float*) pat: (int) size: (float) offset
|
||||
{
|
||||
int i;
|
||||
fprintf(gstream, "[");
|
||||
for (i = 0; i < size; i++)
|
||||
fprintf(gstream, "%f ", pat[i]);
|
||||
fprintf(gstream, "] %g setdash\n", offset);
|
||||
}
|
||||
|
||||
- (void) DPSsetflat: (float) flatness
|
||||
{
|
||||
fprintf(gstream, "%g setflat\n", flatness);
|
||||
}
|
||||
|
||||
- (void) DPSsethalftonephase: (float) x: (float) y
|
||||
{
|
||||
fprintf(gstream, "%g %g sethalftonephase\n", x, y);
|
||||
}
|
||||
|
||||
- (void) DPSsetlinecap: (int) linecap
|
||||
{
|
||||
fprintf(gstream, "%d setlinecap\n", linecap);
|
||||
}
|
||||
|
||||
- (void) DPSsetlinejoin: (int) linejoin
|
||||
{
|
||||
fprintf(gstream, "%d setlinejoin\n", linejoin);
|
||||
}
|
||||
|
||||
- (void) DPSsetlinewidth: (float) width
|
||||
{
|
||||
fprintf(gstream, "%g setlinewidth\n", width);
|
||||
}
|
||||
|
||||
- (void) DPSsetmiterlimit: (float) limit
|
||||
{
|
||||
fprintf(gstream, "%g setmiterlimit\n", limit);
|
||||
}
|
||||
|
||||
- (void) DPSsetstrokeadjust: (int) b
|
||||
{
|
||||
fprintf(gstream, "%d setstrokeadjust\n", b);
|
||||
}
|
||||
|
||||
|
||||
/* ----------------------------------------------------------------------- */
|
||||
/* Matrix operations */
|
||||
/* ----------------------------------------------------------------------- */
|
||||
- (void) DPSconcat: (const float*) m
|
||||
{
|
||||
fprintf(gstream, "[%g %g %g %g %g %g] concat\n",
|
||||
m[0], m[1], m[2], m[3], m[4], m[5]);
|
||||
}
|
||||
|
||||
- (void) DPSinitmatrix
|
||||
{
|
||||
fprintf(gstream, "initmatrix\n");
|
||||
}
|
||||
|
||||
- (void) DPSrotate: (float) angle
|
||||
{
|
||||
fprintf(gstream, "%g rotate\n", angle);
|
||||
}
|
||||
|
||||
- (void) DPSscale: (float) x: (float) y
|
||||
{
|
||||
fprintf(gstream, "%g %g scale\n", x, y);
|
||||
}
|
||||
|
||||
- (void) DPStranslate: (float) x: (float) y
|
||||
{
|
||||
fprintf(gstream, "%g %g translate\n", x, y);
|
||||
}
|
||||
|
||||
|
||||
- (NSAffineTransform *) GSCurrentCTM
|
||||
{
|
||||
NSLog(@"DPSinvalidcontext: getting values from stream context");
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (void) GSSetCTM: (NSAffineTransform *) ctm
|
||||
{
|
||||
[self notImplemented: _cmd];
|
||||
}
|
||||
|
||||
- (void) GSConcatCTM: (NSAffineTransform *) ctm
|
||||
{
|
||||
[self notImplemented: _cmd];
|
||||
}
|
||||
|
||||
|
||||
/* ----------------------------------------------------------------------- */
|
||||
/* Paint operations */
|
||||
/* ----------------------------------------------------------------------- */
|
||||
- (void) DPSarc: (float) x: (float) y: (float) r: (float) angle1: (float) angle2
|
||||
{
|
||||
fprintf(gstream, "%g %g %g %g %g arc\n", x, y, r, angle1, angle2);
|
||||
}
|
||||
|
||||
- (void) DPSarcn: (float) x: (float) y: (float) r: (float) angle1: (float) angle2
|
||||
{
|
||||
fprintf(gstream, "%g %g %g %g %g arcn\n", x, y, r, angle1, angle2);
|
||||
}
|
||||
|
||||
- (void) DPSarct: (float) x1: (float) y1: (float) x2: (float) y2: (float) r
|
||||
{
|
||||
fprintf(gstream, "%g %g %g %g %g arct\n", x1, y1, x2, y2, r);
|
||||
}
|
||||
|
||||
- (void) DPSclip
|
||||
{
|
||||
fprintf(gstream, "clip\n");
|
||||
}
|
||||
|
||||
- (void) DPSclosepath
|
||||
{
|
||||
fprintf(gstream, "closepath\n");
|
||||
}
|
||||
|
||||
- (void) DPScurveto: (float) x1: (float) y1: (float) x2: (float) y2: (float) x3: (float) y3
|
||||
{
|
||||
fprintf(gstream, "%g %g %g %g %g %g curveto\n", x1, y1, x2, y2, x3, y3);
|
||||
}
|
||||
|
||||
- (void) DPSeoclip
|
||||
{
|
||||
fprintf(gstream, "eoclip\n");
|
||||
}
|
||||
|
||||
- (void) DPSeofill
|
||||
{
|
||||
fprintf(gstream, "eofill\n");
|
||||
}
|
||||
|
||||
- (void) DPSfill
|
||||
{
|
||||
fprintf(gstream, "fill\n");
|
||||
}
|
||||
|
||||
- (void) DPSflattenpath
|
||||
{
|
||||
fprintf(gstream, "flattenpath\n");
|
||||
}
|
||||
|
||||
- (void) DPSinitclip
|
||||
{
|
||||
fprintf(gstream, "initclip\n");
|
||||
}
|
||||
|
||||
- (void) DPSlineto: (float) x: (float) y
|
||||
{
|
||||
fprintf(gstream, "%g %g lineto\n", x, y);
|
||||
}
|
||||
|
||||
- (void) DPSmoveto: (float) x: (float) y
|
||||
{
|
||||
fprintf(gstream, "%g %g moveto\n", x, y);
|
||||
}
|
||||
|
||||
- (void) DPSnewpath
|
||||
{
|
||||
fprintf(gstream, "newpath\n");
|
||||
}
|
||||
|
||||
- (void) DPSpathbbox: (float*) llx: (float*) lly: (float*) urx: (float*) ury
|
||||
{
|
||||
}
|
||||
|
||||
- (void) DPSrcurveto: (float) x1: (float) y1: (float) x2: (float) y2: (float) x3: (float) y3
|
||||
{
|
||||
fprintf(gstream, "%g %g %g %g %g %g rcurveto\n", x1, y1, x2, y2, x3, y3);
|
||||
}
|
||||
|
||||
- (void) DPSrectclip: (float) x: (float) y: (float) w: (float) h
|
||||
{
|
||||
fprintf(gstream, "%g %g %g %g rectclip\n", x, y, w, h);
|
||||
}
|
||||
|
||||
- (void) DPSrectfill: (float) x: (float) y: (float) w: (float) h
|
||||
{
|
||||
fprintf(gstream, "%g %g %g %g rectfill\n", x, y, w, h);
|
||||
}
|
||||
|
||||
- (void) DPSrectstroke: (float) x: (float) y: (float) w: (float) h
|
||||
{
|
||||
fprintf(gstream, "%g %g %g %g rectstroke\n", x, y, w, h);
|
||||
}
|
||||
|
||||
- (void) DPSreversepath
|
||||
{
|
||||
fprintf(gstream, "reversepath\n");
|
||||
}
|
||||
|
||||
- (void) DPSrlineto: (float) x: (float) y
|
||||
{
|
||||
fprintf(gstream, "%g %g rlineto\n", x, y);
|
||||
}
|
||||
|
||||
- (void) DPSrmoveto: (float) x: (float) y
|
||||
{
|
||||
fprintf(gstream, "%g %g rmoveto\n", x, y);
|
||||
}
|
||||
|
||||
- (void) DPSstroke
|
||||
{
|
||||
fprintf(gstream, "stroke\n");
|
||||
}
|
||||
|
||||
|
||||
- (void) GSSendBezierPath: (NSBezierPath *) path
|
||||
{
|
||||
[self notImplemented: _cmd];
|
||||
}
|
||||
|
||||
- (void) GSRectClipList: (const NSRect *) rects: (int) count
|
||||
{
|
||||
[self notImplemented: _cmd];
|
||||
}
|
||||
|
||||
- (void) GSRectFillList: (const NSRect *) rects: (int) count
|
||||
{
|
||||
[self notImplemented: _cmd];
|
||||
}
|
||||
|
||||
|
||||
/* ----------------------------------------------------------------------- */
|
||||
/* Window system ops */
|
||||
/* ----------------------------------------------------------------------- */
|
||||
- (void) DPScurrentgcdrawable: (void**) gc: (void**) draw: (int*) x: (int*) y
|
||||
{
|
||||
NSLog(@"DPSinvalidcontext: getting values from stream context");
|
||||
}
|
||||
|
||||
- (void) DPScurrentoffset: (int*) x: (int*) y
|
||||
{
|
||||
NSLog(@"DPSinvalidcontext: getting values from stream context");
|
||||
}
|
||||
|
||||
- (void) DPSsetgcdrawable: (void*) gc: (void*) draw: (int) x: (int) y
|
||||
{
|
||||
}
|
||||
|
||||
- (void) DPSsetoffset: (short int) x: (short int) y
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/*-------------------------------------------------------------------------*/
|
||||
/* Graphics Extensions Ops */
|
||||
/*-------------------------------------------------------------------------*/
|
||||
- (void) DPScomposite: (float) x: (float) y: (float) w: (float) h: (int) gstateNum: (float) dx: (float) dy: (int) op
|
||||
{
|
||||
fprintf(gstream, "%g %g %g %g %d %g %g %d composite\n", x, y, w, h, gstateNum, dx, dy, op);
|
||||
}
|
||||
|
||||
- (void) DPScompositerect: (float) x: (float) y: (float) w: (float) h: (int) op
|
||||
{
|
||||
fprintf(gstream, "%g %g %g %g %d compositerect\n", x, y, w, h, op);
|
||||
}
|
||||
|
||||
- (void) DPSdissolve: (float) x: (float) y: (float) w: (float) h: (int) gstateNum: (float) dx: (float) dy: (float) delta
|
||||
{
|
||||
fprintf(gstream, "%g %g %g %g %d %g %g %g dissolve\n", x, y, w, h, gstateNum, dx, dy, delta);
|
||||
}
|
||||
|
||||
|
||||
- (void) GSDrawImage: (NSRect) rect: (void *) imageref
|
||||
{
|
||||
[self notImplemented: _cmd];
|
||||
}
|
||||
|
||||
|
||||
/* ----------------------------------------------------------------------- */
|
||||
/* Client functions */
|
||||
/* ----------------------------------------------------------------------- */
|
||||
- (void) DPSPrintf: (char *)fmt : (va_list)args
|
||||
{
|
||||
vfprintf(gstream, fmt, args);
|
||||
}
|
||||
|
||||
- (void) DPSWriteData: (char *)buf : (unsigned int)count
|
||||
{
|
||||
/* Not sure here. Should we translate to ASCII if it's not
|
||||
already? */
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
static char *hexdigits = "0123456789abcdef";
|
||||
|
||||
void
|
||||
writeHex(FILE *gstream, const unsigned char *data, int count)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
fprintf(gstream, "%c%c", hexdigits[(int)(data[0]/16)],
|
||||
hexdigits[(data[0] % 16)]);
|
||||
if (i && i % 40 == 0)
|
||||
fprintf(gstream, "\n");
|
||||
}
|
||||
}
|
||||
|
||||
@implementation GSStreamContext (Graphics)
|
||||
|
||||
- (void) NSDrawBitmap: (NSRect) rect : (int) pixelsWide : (int) pixelsHigh
|
||||
: (int) bitsPerSample : (int) samplesPerPixel
|
||||
: (int) bitsPerPixel : (int) bytesPerRow : (BOOL) isPlanar
|
||||
: (BOOL) hasAlpha : (NSString *) colorSpaceName
|
||||
: (const unsigned char *const [5]) data
|
||||
{
|
||||
int bytes;
|
||||
NSSize scale;
|
||||
|
||||
scale = NSMakeSize(NSWidth(rect) / pixelsWide,
|
||||
NSHeight(rect) / pixelsHigh);
|
||||
/* Save scaling */
|
||||
fprintf(gstream, "matrix\ncurrentmatrix\n");
|
||||
fprintf(gstream, "%f %f translate %f %f scale\n",
|
||||
NSMinX(rect), NSMinY(rect), scale.width, scale.height);
|
||||
|
||||
if (bitsPerSample == 0)
|
||||
bitsPerSample = 8;
|
||||
bytes =
|
||||
(bitsPerSample * pixelsWide * pixelsHigh + 7) / 8;
|
||||
if (bytes * samplesPerPixel != bytesPerRow * pixelsHigh)
|
||||
{
|
||||
NSLog(@"Image Rendering Error: Dodgy bytesPerRow value %d", bytesPerRow);
|
||||
NSLog(@" pixelsHigh=%d, bytes=%d, samplesPerPixel=%d",
|
||||
bytesPerRow, pixelsHigh, bytes);
|
||||
return;
|
||||
}
|
||||
|
||||
if(samplesPerPixel > 1)
|
||||
{
|
||||
if(isPlanar || hasAlpha)
|
||||
{
|
||||
if(bitsPerSample != 8)
|
||||
{
|
||||
NSLog(@"Image format conversion not supported for bps!=8");
|
||||
return;
|
||||
}
|
||||
}
|
||||
fprintf(gstream, "%d %d %d [%d 0 0 -%d 0 %d]\n",
|
||||
pixelsWide, pixelsHigh, bitsPerSample, pixelsWide,
|
||||
pixelsHigh, pixelsHigh);
|
||||
fprintf(gstream, "{currentfile %d string readhexstring pop}\n",
|
||||
bytesPerRow);
|
||||
fprintf(gstream, "false %d colorimage\n",
|
||||
hasAlpha?(samplesPerPixel-1):samplesPerPixel);
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(gstream, "%d %d %d [%d 0 0 -%d 0 %d]\n",
|
||||
pixelsWide, pixelsHigh, bitsPerSample, pixelsWide,
|
||||
pixelsHigh, pixelsHigh);
|
||||
fprintf(gstream, "currentfile image\n");
|
||||
}
|
||||
|
||||
// The context is now waiting for data on its standard input
|
||||
if(isPlanar || hasAlpha)
|
||||
{
|
||||
// We need to do a format conversion.
|
||||
// We do this on the fly, sending data to the context as soon as
|
||||
// it is computed.
|
||||
int i, j, spp, alpha;
|
||||
unsigned char val;
|
||||
if(hasAlpha)
|
||||
spp = samplesPerPixel - 1;
|
||||
else
|
||||
spp = samplesPerPixel;
|
||||
|
||||
for(j=0; j<bytes; j++)
|
||||
{
|
||||
if(hasAlpha)
|
||||
{
|
||||
if(isPlanar)
|
||||
alpha = data[spp][j];
|
||||
else
|
||||
alpha = data[0][spp+j*samplesPerPixel];
|
||||
}
|
||||
for (i = 0; i < spp; i++)
|
||||
{
|
||||
if(isPlanar)
|
||||
val = data[i][j];
|
||||
else
|
||||
val = data[0][i+j*samplesPerPixel];
|
||||
if(hasAlpha)
|
||||
val = 255 - ((255-val)*(long)alpha)/255;
|
||||
writeHex(gstream, &val, 1);
|
||||
}
|
||||
if (j && j % 40 == 0)
|
||||
fprintf(gstream, "\n");
|
||||
}
|
||||
fprintf(gstream, "\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
// The data is already in the format the context expects it in
|
||||
writeHex(gstream, data[0], bytes*samplesPerPixel);
|
||||
}
|
||||
|
||||
/* Restore original scaling */
|
||||
fprintf(gstream, "setmatrix\n");
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation GSStreamContext (Private)
|
||||
|
||||
- (void) output: (const char*)s
|
||||
{
|
||||
const char *t = s;
|
||||
|
||||
while (*t)
|
||||
{
|
||||
switch (*t)
|
||||
{
|
||||
case '(':
|
||||
fputs("\\(", gstream);
|
||||
break;
|
||||
case ')':
|
||||
fputs("\\)", gstream);
|
||||
break;
|
||||
default:
|
||||
fputc(*t, gstream);
|
||||
break;
|
||||
}
|
||||
t++;
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
54
Source/gsc/externs.m
Normal file
54
Source/gsc/externs.m
Normal file
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
externs.m
|
||||
|
||||
External data
|
||||
|
||||
Copyright (C) 1997 Free Software Foundation, Inc.
|
||||
|
||||
Author: Adam Fedor <fedor@gnu.org>
|
||||
Date: Dec 1998
|
||||
|
||||
This file is part of the GNUstep GUI Library.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; see the file COPYING.LIB.
|
||||
If not, write to the Free Software Foundation,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <Foundation/NSString.h>
|
||||
|
||||
NSString *DPSconfigurationerror = @"DPSconfigurationerror: %@";
|
||||
NSString *DPSinvalidaccess = @"DPSinvalidaccess: %@";
|
||||
NSString *DPSinvalidcontext = @"DPSinvalidcontext: %@";
|
||||
NSString *DPSinvalidexit = @"DPSinvalidexit: %@";
|
||||
NSString *DPSinvalidfileaccess = @"DPSinvalidfileaccess: %@";
|
||||
NSString *DPSinvalidfont = @"DPSinvalidfont: %@";
|
||||
NSString *DPSinvalidid = @"DPSinvalidid: %@";
|
||||
NSString *DPSinvalidrestore = @"DPSinvalidrestore: %@";
|
||||
NSString *DPSinvalidparam = @"DPSinvalidparam: %@";
|
||||
NSString *DPSioerror = @"DPSioerror: %@";
|
||||
NSString *DPSlimitcheck = @"DPSlimitcheck: %@";
|
||||
NSString *DPSnocurrentpoint = @"DPSnocurrentpoint: %@";
|
||||
NSString *DPSnulloutput = @"DPSnulloutput: %@";
|
||||
NSString *DPSrangecheck = @"DPSrangecheck: %@";
|
||||
NSString *DPSstackoverflow = @"DPSstackoverflow: %@";
|
||||
NSString *DPSstackunderflow = @"DPSstackunderflow: %@";
|
||||
NSString *DPStypecheck = @"DPStypecheck: %@";
|
||||
NSString *DPSundefined = @"DPSundefined: %@";
|
||||
NSString *DPSundefinedfilename = @"DPSundefinedfilename: %@";
|
||||
NSString *DPSundefinedresource = @"DPSundefinedresource: %@";
|
||||
NSString *DPSundefinedresult = @"DPSundefinedresult: %@";
|
||||
NSString *DPSunmatchedmark = @"DPSunmatchedmark: %@";
|
||||
NSString *DPSunregistered = @"DPSunregistered: %@";
|
||||
NSString *DPSVMerror = @"DPSVMerror: %@";
|
80
Source/x11/GNUmakefile
Normal file
80
Source/x11/GNUmakefile
Normal file
|
@ -0,0 +1,80 @@
|
|||
#
|
||||
# Main makefile for GNUstep Backend x11
|
||||
#
|
||||
# Copyright (C) 2002 Free Software Foundation, Inc.
|
||||
#
|
||||
# Author: Adam Fedor <fedor@gnu.org>
|
||||
#
|
||||
# This file is part of the GNUstep Backend.
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Library General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This library is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# Library General Public License for more details.
|
||||
#
|
||||
# If you are interested in a warranty or support for this source code,
|
||||
# contact Scott Christley at scottc@net-community.com
|
||||
#
|
||||
# You should have received a copy of the GNU Library General Public
|
||||
# License along with this library; see the file COPYING.LIB.
|
||||
# If not, write to the Free Software Foundation,
|
||||
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
GNUSTEP_INSTALLATION_DIR = $(GNUSTEP_SYSTEM_ROOT)
|
||||
|
||||
GNUSTEP_MAKEFILES = $(GNUSTEP_SYSTEM_ROOT)/Makefiles
|
||||
|
||||
GNUSTEP_LOCAL_ADDITIONAL_MAKEFILES=../../back.make
|
||||
|
||||
include $(GNUSTEP_MAKEFILES)/common.make
|
||||
|
||||
include ../../config.make
|
||||
|
||||
# The library to be compiled, as a library or as a bundle
|
||||
SUBPROJECT_NAME=x11
|
||||
|
||||
# The C source files to be compiled
|
||||
ifeq ($(WITH_WRASTER),yes)
|
||||
x11_C_FILES = \
|
||||
xdnd.c
|
||||
else
|
||||
x11_C_FILES = \
|
||||
StdCmap.c \
|
||||
context.c \
|
||||
convert.c \
|
||||
draw.c \
|
||||
gradient.c \
|
||||
misc.c \
|
||||
raster.c \
|
||||
scale.c \
|
||||
xdnd.c \
|
||||
xutil.c
|
||||
endif
|
||||
|
||||
# The Objective-C source files to be compiled
|
||||
x11_OBJC_FILES = \
|
||||
XGServer.m \
|
||||
XGServerEvent.m \
|
||||
XGServerWindow.m \
|
||||
XGDragView.m \
|
||||
XGSlideView.m \
|
||||
XIMInputServer.m
|
||||
|
||||
x11_HEADER_FILES_DIR = ../Headers/x11
|
||||
x11_HEADER_FILES_INSTALL_DIR = gnustep/x11
|
||||
|
||||
x11_HEADER_FILES = \
|
||||
XGServer.h \
|
||||
XGServerWindow.h
|
||||
|
||||
-include GNUmakefile.preamble
|
||||
|
||||
include $(GNUSTEP_MAKEFILES)/subproject.make
|
||||
|
||||
-include GNUmakefile.postamble
|
||||
|
55
Source/x11/GNUmakefile.preamble
Normal file
55
Source/x11/GNUmakefile.preamble
Normal file
|
@ -0,0 +1,55 @@
|
|||
#
|
||||
# GNUmakefile.preamble
|
||||
#
|
||||
# Copyright (C) 2002 Free Software Foundation, Inc.
|
||||
#
|
||||
# Author: Adam Fedor <fedor@gnu.org>
|
||||
#
|
||||
# This file is part of the GNUstep Backend.
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Library General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This library is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# Library General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Library General Public
|
||||
# License along with this library; see the file COPYING.LIB.
|
||||
# If not, write to the Free Software Foundation,
|
||||
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
#
|
||||
# Flags dealing with compiling and linking
|
||||
#
|
||||
|
||||
# Additional flags to pass to the preprocessor
|
||||
GNUSTEP_INSTALL_LIBDIR=$(GNUSTEP_LIBRARIES_ROOT)
|
||||
ADDITIONAL_CPPFLAGS = -DGNUSTEP_INSTALL_LIBDIR=\"$(GNUSTEP_INSTALL_LIBDIR)\" \
|
||||
-DGNUSTEP_INSTALL_PREFIX=$(GNUSTEP_INSTALL_PREFIX) \
|
||||
$(CONFIG_SYSTEM_DEFS)
|
||||
|
||||
# Additional flags to pass to the Objective-C compiler
|
||||
ADDITIONAL_OBJCFLAGS =
|
||||
|
||||
# Additional flags to pass to the C compiler
|
||||
ADDITIONAL_CFLAGS =
|
||||
|
||||
# Additional include directories the compiler should search
|
||||
ADDITIONAL_INCLUDE_DIRS = -I../../Headers \
|
||||
-I../$(GNUSTEP_TARGET_DIR)
|
||||
|
||||
# Additional LDFLAGS to pass to the linker
|
||||
ADDITIONAL_LDFLAGS =
|
||||
|
||||
# Additional library directories the linker should search
|
||||
ADDITIONAL_LIB_DIRS =
|
||||
|
||||
#
|
||||
# Flags dealing with installing and uninstalling
|
||||
#
|
||||
|
||||
|
219
Source/x11/StdCmap.c
Normal file
219
Source/x11/StdCmap.c
Normal file
|
@ -0,0 +1,219 @@
|
|||
/* $XConsortium: StdCmap.c,v 1.14 94/04/17 20:16:14 rws Exp $ */
|
||||
|
||||
/*
|
||||
|
||||
Copyright (c) 1989 X Consortium
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
||||
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
Except as contained in this notice, the name of the X Consortium shall not be
|
||||
used in advertising or otherwise to promote the sale, use or other dealings
|
||||
in this Software without prior written authorization from the X Consortium.
|
||||
|
||||
*/
|
||||
|
||||
/*
|
||||
* Author: Donna Converse, MIT X Consortium
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xatom.h>
|
||||
#include <X11/Xutil.h>
|
||||
#include <X11/Xmu/StdCmap.h>
|
||||
|
||||
#define lowbit(x) ((x) & (~(x) + 1))
|
||||
|
||||
static Status valid_args(); /* argument restrictions */
|
||||
|
||||
/*
|
||||
* To create any one standard colormap, use XmuStandardColormap().
|
||||
*
|
||||
* Create a standard colormap for the given screen, visualid, and visual
|
||||
* depth, with the given red, green, and blue maximum values, with the
|
||||
* given standard property name. Return a pointer to an XStandardColormap
|
||||
* structure which describes the newly created colormap, upon success.
|
||||
* Upon failure, return NULL.
|
||||
*
|
||||
* XmuStandardColormap() calls XmuCreateColormap() to create the map.
|
||||
*
|
||||
* Resources created by this function are not made permanent; that is the
|
||||
* caller's responsibility.
|
||||
*/
|
||||
|
||||
XStandardColormap *XmuStandardColormap(dpy, screen, visualid, depth, property,
|
||||
cmap, red_max, green_max, blue_max)
|
||||
Display *dpy; /* specifies X server connection */
|
||||
int screen; /* specifies display screen */
|
||||
VisualID visualid; /* identifies the visual type */
|
||||
unsigned int depth; /* identifies the visual type */
|
||||
Atom property; /* a standard colormap property */
|
||||
Colormap cmap; /* specifies colormap ID or None */
|
||||
unsigned long red_max, green_max, blue_max; /* allocations */
|
||||
{
|
||||
XStandardColormap *stdcmap;
|
||||
Status status;
|
||||
XVisualInfo vinfo_template, *vinfo;
|
||||
long vinfo_mask;
|
||||
int n;
|
||||
|
||||
/* Match the required visual information to an actual visual */
|
||||
vinfo_template.visualid = visualid;
|
||||
vinfo_template.screen = screen;
|
||||
vinfo_template.depth = depth;
|
||||
vinfo_mask = VisualIDMask | VisualScreenMask | VisualDepthMask;
|
||||
if ((vinfo = XGetVisualInfo(dpy, vinfo_mask, &vinfo_template, &n)) == NULL)
|
||||
return 0;
|
||||
|
||||
/* Check the validity of the combination of visual characteristics,
|
||||
* allocation, and colormap property. Create an XStandardColormap
|
||||
* structure.
|
||||
*/
|
||||
|
||||
if (! valid_args(vinfo, red_max, green_max, blue_max, property)
|
||||
|| ((stdcmap = XAllocStandardColormap()) == NULL)) {
|
||||
XFree((char *) vinfo);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Fill in the XStandardColormap structure */
|
||||
|
||||
if (cmap == DefaultColormap(dpy, screen)) {
|
||||
/* Allocating out of the default map, cannot use XFreeColormap() */
|
||||
Window win = XCreateWindow(dpy, RootWindow(dpy, screen), 1, 1, 1, 1,
|
||||
0, 0, InputOnly, vinfo->visual,
|
||||
(unsigned long) 0,
|
||||
(XSetWindowAttributes *)NULL);
|
||||
stdcmap->killid = (XID) XCreatePixmap(dpy, win, 1, 1, depth);
|
||||
XDestroyWindow(dpy, win);
|
||||
stdcmap->colormap = cmap;
|
||||
} else {
|
||||
stdcmap->killid = ReleaseByFreeingColormap;
|
||||
stdcmap->colormap = XCreateColormap(dpy, RootWindow(dpy, screen),
|
||||
vinfo->visual, AllocNone);
|
||||
}
|
||||
stdcmap->red_max = red_max;
|
||||
stdcmap->green_max = green_max;
|
||||
stdcmap->blue_max = blue_max;
|
||||
if (property == XA_RGB_GRAY_MAP)
|
||||
stdcmap->red_mult = stdcmap->green_mult = stdcmap->blue_mult = 1;
|
||||
else if (vinfo->class == TrueColor || vinfo->class == DirectColor) {
|
||||
stdcmap->red_mult = lowbit(vinfo->red_mask);
|
||||
stdcmap->green_mult = lowbit(vinfo->green_mask);
|
||||
stdcmap->blue_mult = lowbit(vinfo->blue_mask);
|
||||
} else {
|
||||
stdcmap->red_mult = (red_max > 0)
|
||||
? (green_max + 1) * (blue_max + 1) : 0;
|
||||
stdcmap->green_mult = (green_max > 0) ? blue_max + 1 : 0;
|
||||
stdcmap->blue_mult = (blue_max > 0) ? 1 : 0;
|
||||
}
|
||||
stdcmap->base_pixel = 0; /* base pixel may change */
|
||||
stdcmap->visualid = vinfo->visualid;
|
||||
|
||||
/* Make the colormap */
|
||||
|
||||
status = XmuCreateColormap(dpy, stdcmap);
|
||||
|
||||
/* Clean up */
|
||||
|
||||
XFree((char *) vinfo);
|
||||
if (!status) {
|
||||
|
||||
/* Free the colormap or the pixmap, if we created one */
|
||||
if (stdcmap->killid == ReleaseByFreeingColormap)
|
||||
XFreeColormap(dpy, stdcmap->colormap);
|
||||
else if (stdcmap->killid != None)
|
||||
XFreePixmap(dpy, stdcmap->killid);
|
||||
|
||||
XFree((char *) stdcmap);
|
||||
return (XStandardColormap *) NULL;
|
||||
}
|
||||
return stdcmap;
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
static Status valid_args(vinfo, red_max, green_max, blue_max, property)
|
||||
XVisualInfo *vinfo; /* specifies visual */
|
||||
unsigned long red_max, green_max, blue_max; /* specifies alloc */
|
||||
Atom property; /* specifies property name */
|
||||
{
|
||||
unsigned long ncolors; /* number of colors requested */
|
||||
|
||||
/* Determine that the number of colors requested is <= map size */
|
||||
|
||||
if ((vinfo->class == DirectColor) || (vinfo->class == TrueColor)) {
|
||||
unsigned long mask;
|
||||
|
||||
mask = vinfo->red_mask;
|
||||
while (!(mask & 1))
|
||||
mask >>= 1;
|
||||
if (red_max > mask)
|
||||
return 0;
|
||||
mask = vinfo->green_mask;
|
||||
while (!(mask & 1))
|
||||
mask >>= 1;
|
||||
if (green_max > mask)
|
||||
return 0;
|
||||
mask = vinfo->blue_mask;
|
||||
while (!(mask & 1))
|
||||
mask >>= 1;
|
||||
if (blue_max > mask)
|
||||
return 0;
|
||||
} else if (property == XA_RGB_GRAY_MAP) {
|
||||
ncolors = red_max + green_max + blue_max + 1;
|
||||
if (ncolors > vinfo->colormap_size)
|
||||
return 0;
|
||||
} else {
|
||||
ncolors = (red_max + 1) * (green_max + 1) * (blue_max + 1);
|
||||
if (ncolors > vinfo->colormap_size)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Determine that the allocation and visual make sense for the property */
|
||||
|
||||
switch (property)
|
||||
{
|
||||
case XA_RGB_DEFAULT_MAP:
|
||||
if (red_max == 0 || green_max == 0 || blue_max == 0)
|
||||
return 0;
|
||||
break;
|
||||
case XA_RGB_RED_MAP:
|
||||
if (red_max == 0)
|
||||
return 0;
|
||||
break;
|
||||
case XA_RGB_GREEN_MAP:
|
||||
if (green_max == 0)
|
||||
return 0;
|
||||
break;
|
||||
case XA_RGB_BLUE_MAP:
|
||||
if (blue_max == 0)
|
||||
return 0;
|
||||
break;
|
||||
case XA_RGB_BEST_MAP:
|
||||
if (red_max == 0 || green_max == 0 || blue_max == 0)
|
||||
return 0;
|
||||
break;
|
||||
case XA_RGB_GRAY_MAP:
|
||||
if (red_max == 0 || blue_max == 0 || green_max == 0)
|
||||
return 0;
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
1293
Source/x11/XGDragView.m
Normal file
1293
Source/x11/XGDragView.m
Normal file
File diff suppressed because it is too large
Load diff
424
Source/x11/XGServer.m
Normal file
424
Source/x11/XGServer.m
Normal file
|
@ -0,0 +1,424 @@
|
|||
/* -*- mode:ObjC -*-
|
||||
XGServer - X11 Server Class
|
||||
|
||||
Copyright (C) 1998,2002 Free Software Foundation, Inc.
|
||||
|
||||
Written by: Adam Fedor <fedor@gnu.org>
|
||||
Date: Mar 2002
|
||||
|
||||
This file is part of the GNU Objective C User Interface Library.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include <AppKit/AppKitExceptions.h>
|
||||
#include <AppKit/NSApplication.h>
|
||||
#include <AppKit/NSView.h>
|
||||
#include <AppKit/NSWindow.h>
|
||||
#include <Foundation/NSException.h>
|
||||
#include <Foundation/NSArray.h>
|
||||
#include <Foundation/NSConnection.h>
|
||||
#include <Foundation/NSDictionary.h>
|
||||
#include <Foundation/NSData.h>
|
||||
#include <Foundation/NSRunLoop.h>
|
||||
#include <Foundation/NSValue.h>
|
||||
#include <Foundation/NSString.h>
|
||||
#include <Foundation/NSUserDefaults.h>
|
||||
#include <Foundation/NSDebug.h>
|
||||
|
||||
#ifdef HAVE_WRASTER_H
|
||||
#include "wraster.h"
|
||||
#else
|
||||
#include "x11/wraster.h"
|
||||
#endif
|
||||
|
||||
#include "x11/XGServer.h"
|
||||
#include "x11/XGInputServer.h"
|
||||
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xutil.h>
|
||||
#include <X11/keysym.h>
|
||||
|
||||
extern int XGErrorHandler(Display *display, XErrorEvent *err);
|
||||
|
||||
@interface XGServer (Window)
|
||||
- (void) _setupRootWindow;
|
||||
@end
|
||||
|
||||
@interface XGServer (Private)
|
||||
- (void) setupRunLoopInputSourcesForMode: (NSString*)mode;
|
||||
@end
|
||||
|
||||
#define XDPY (((RContext *)context)->dpy)
|
||||
#define XSCR (((RContext *)context)->screen_number)
|
||||
|
||||
/**
|
||||
<unit>
|
||||
<heading>XGServer</heading>
|
||||
</unit>
|
||||
*/
|
||||
@implementation XGServer
|
||||
|
||||
/* Initialize AppKit backend */
|
||||
+ (void)initializeBackend
|
||||
{
|
||||
NSDebugLog(@"Initializing GNUstep x11 backend.\n");
|
||||
[GSDisplayServer setDefaultServerClass: [XGServer class]];
|
||||
}
|
||||
|
||||
/**
|
||||
Returns a pointer to the current X-Windows display variable for
|
||||
the current context.
|
||||
*/
|
||||
+ (Display*) currentXDisplay
|
||||
{
|
||||
return [(XGServer*)GSCurrentServer() xDisplay];
|
||||
}
|
||||
|
||||
- (RContextAttributes *) _getXDefaults
|
||||
{
|
||||
int dummy;
|
||||
RContextAttributes *attribs;
|
||||
|
||||
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
||||
attribs = (RContextAttributes *)malloc(sizeof(RContextAttributes));
|
||||
|
||||
attribs->flags = 0;
|
||||
if ([defaults boolForKey: @"NSDefaultVisual"])
|
||||
attribs->flags |= RC_DefaultVisual;
|
||||
if ((dummy = [defaults integerForKey: @"NSDefaultVisual"]))
|
||||
{
|
||||
attribs->flags |= RC_VisualID;
|
||||
attribs->visualid = dummy;
|
||||
}
|
||||
if ((dummy = [defaults integerForKey: @"NSColorsPerChannel"]))
|
||||
{
|
||||
attribs->flags |= RC_ColorsPerChannel;
|
||||
attribs->colors_per_channel = dummy;
|
||||
}
|
||||
|
||||
return attribs;
|
||||
}
|
||||
|
||||
- _initXContext
|
||||
{
|
||||
Display *dpy;
|
||||
int screen_number;
|
||||
NSString *display_name;
|
||||
RContext *rcontext;
|
||||
RContextAttributes *attribs;
|
||||
XColor testColor;
|
||||
unsigned char r, g, b;
|
||||
|
||||
display_name = [server_info objectForKey: @"DisplayName"];
|
||||
if (display_name == nil)
|
||||
{
|
||||
NSString *host;
|
||||
NSString *dnum = @"0.0";
|
||||
|
||||
host = [[NSUserDefaults standardUserDefaults] stringForKey: @"NSHost"];
|
||||
if (host == nil)
|
||||
{
|
||||
NSString *d = [[[NSProcessInfo processInfo] environment]
|
||||
objectForKey: @"DISPLAY"];
|
||||
|
||||
if (d == nil)
|
||||
{
|
||||
host = @"";
|
||||
}
|
||||
else
|
||||
{
|
||||
if ([d hasPrefix: @":"] == YES)
|
||||
{
|
||||
host = @""; // local host
|
||||
}
|
||||
else
|
||||
{
|
||||
NSArray *a = [d componentsSeparatedByString: @":"];
|
||||
|
||||
if ([a count] != 2)
|
||||
{
|
||||
NSLog(@"X DISPLAY environment variable has bad format"
|
||||
@" assuming local X server (DISPLAY=:0.0)");
|
||||
host = @"";
|
||||
}
|
||||
else
|
||||
{
|
||||
host = [a objectAtIndex: 0];
|
||||
dnum = [a lastObject];
|
||||
if ([dnum isEqual: @"0"] == NO
|
||||
&& [dnum hasPrefix: @"0."] == NO)
|
||||
{
|
||||
NSLog(@"Only one display per host fully supported.");
|
||||
}
|
||||
}
|
||||
}
|
||||
if ([host isEqual: @""] == NO)
|
||||
{
|
||||
/**
|
||||
* If we are using the DISPLAY environment variable to
|
||||
* determine where to display, set the NSHost default
|
||||
* so that other parts of the system know where we are
|
||||
* displaying.
|
||||
*/
|
||||
[[NSUserDefaults standardUserDefaults] registerDefaults:
|
||||
[NSDictionary dictionaryWithObject: host
|
||||
forKey: @"NSHost"]];
|
||||
}
|
||||
}
|
||||
}
|
||||
if ([host isEqual: @""] == NO)
|
||||
{
|
||||
/**
|
||||
* If the NSHost default told us to display somewhere, we need
|
||||
* to generate a display name for X from the host name and the
|
||||
* default display and screen numbers (zero).
|
||||
*/
|
||||
display_name = [NSString stringWithFormat: @"%@:%@", host, dnum];
|
||||
}
|
||||
}
|
||||
|
||||
if (display_name)
|
||||
{
|
||||
dpy = XOpenDisplay([display_name cString]);
|
||||
}
|
||||
else
|
||||
{
|
||||
dpy = XOpenDisplay(NULL);
|
||||
display_name = [NSString stringWithCString: XDisplayName(NULL)];
|
||||
}
|
||||
|
||||
/* Use the fact that the screen number is specified like an extension
|
||||
e.g. hostname:0.1 */
|
||||
screen_number = [[display_name pathExtension] intValue];
|
||||
|
||||
if (dpy == NULL)
|
||||
{
|
||||
char *dname = XDisplayName([display_name cString]);
|
||||
[NSException raise: @"DPSconfigurationerror"
|
||||
format: @"Unable to connect to X Server `%s'", dname];
|
||||
}
|
||||
else
|
||||
NSDebugLog(@"Opened display %@", display_name);
|
||||
|
||||
/* Get the visual information */
|
||||
attribs = NULL;
|
||||
//attribs = [self _getXDefaults];
|
||||
rcontext = RCreateContext(dpy, screen_number, attribs);
|
||||
context = (void *)rcontext;
|
||||
|
||||
/*
|
||||
* If we have shared memory available, only use it when the XGPS-Shm
|
||||
* default is set to YES
|
||||
*/
|
||||
if (rcontext->attribs->use_shared_memory == True
|
||||
&& [[NSUserDefaults standardUserDefaults] boolForKey: @"XGPS-Shm"] != YES)
|
||||
rcontext->attribs->use_shared_memory = False;
|
||||
|
||||
/*
|
||||
* Crude tests to see if we can accelerate creation of pixels from
|
||||
* 8-bit red, green and blue color values.
|
||||
*/
|
||||
if (rcontext->depth == 12 || rcontext->depth == 16)
|
||||
{
|
||||
drawMechanism = XGDM_FAST16;
|
||||
r = 8;
|
||||
g = 9;
|
||||
b = 7;
|
||||
testColor.pixel = (((r << 5) + g) << 6) + b;
|
||||
XQueryColor(rcontext->dpy, rcontext->cmap, &testColor);
|
||||
if (((testColor.red >> 11) != r)
|
||||
|| ((testColor.green >> 11) != g)
|
||||
|| ((testColor.blue >> 11) != b))
|
||||
{
|
||||
NSLog(@"WARNING - XGServer is unable to use the "
|
||||
@"fast algorithm for writing to a 16-bit display on "
|
||||
@"this host - perhaps you'd like to adjust the code "
|
||||
@"to work ... and submit a patch.");
|
||||
drawMechanism = XGDM_PORTABLE;
|
||||
}
|
||||
}
|
||||
else if (rcontext->depth == 15)
|
||||
{
|
||||
drawMechanism = XGDM_FAST15;
|
||||
r = 8;
|
||||
g = 9;
|
||||
b = 7;
|
||||
testColor.pixel = (((r << 5) + g) << 5) + b;
|
||||
XQueryColor(rcontext->dpy, rcontext->cmap, &testColor);
|
||||
if (((testColor.red >> 11) != r)
|
||||
|| ((testColor.green >> 11) != g)
|
||||
|| ((testColor.blue >> 11) != b))
|
||||
{
|
||||
NSLog(@"WARNING - XGServer is unable to use the "
|
||||
@"fast algorithm for writing to a 15-bit display on "
|
||||
@"this host - perhaps you'd like to adjust the code "
|
||||
@"to work ... and submit a patch.");
|
||||
drawMechanism = XGDM_PORTABLE;
|
||||
}
|
||||
}
|
||||
else if (rcontext->depth == 24 || rcontext->depth == 32)
|
||||
{
|
||||
drawMechanism = XGDM_FAST32;
|
||||
r = 32;
|
||||
g = 33;
|
||||
b = 31;
|
||||
testColor.pixel = (((r << 8) + g) << 8) + b;
|
||||
XQueryColor(rcontext->dpy, rcontext->cmap, &testColor);
|
||||
if (((testColor.red >> 8) == r)
|
||||
&& ((testColor.green >> 8) == g)
|
||||
&& ((testColor.blue >> 8) == b))
|
||||
{
|
||||
drawMechanism = XGDM_FAST32;
|
||||
}
|
||||
else if (((testColor.red >> 8) == b)
|
||||
&& ((testColor.green >> 8) == g)
|
||||
&& ((testColor.blue >> 8) == r))
|
||||
{
|
||||
drawMechanism = XGDM_FAST32_BGR;
|
||||
}
|
||||
else
|
||||
{
|
||||
NSLog(@"WARNING - XGServer is unable to use the "
|
||||
@"fast algorithm for writing to a 32-bit display on "
|
||||
@"this host - perhaps you'd like to adjust the code "
|
||||
@"to work ... and submit a patch.");
|
||||
drawMechanism = XGDM_PORTABLE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
NSLog(@"WARNING - XGServer is unable to use a "
|
||||
@"fast algorithm for writing to the display on "
|
||||
@"this host - perhaps you'd like to adjust the code "
|
||||
@"to work ... and submit a patch.");
|
||||
drawMechanism = XGDM_PORTABLE;
|
||||
}
|
||||
|
||||
XSetErrorHandler(XGErrorHandler);
|
||||
|
||||
if (GSDebugSet(@"XSynchronize") == YES)
|
||||
XSynchronize(dpy, True);
|
||||
|
||||
[self _setupRootWindow];
|
||||
inputServer = [[XIMInputServer allocWithZone: [self zone]]
|
||||
initWithDelegate: nil display: dpy name: @"XIM"];
|
||||
return self;
|
||||
}
|
||||
|
||||
/**
|
||||
Opens the X display (using a helper method) and sets up basic
|
||||
display mechanisms, such as visuals and colormaps.
|
||||
*/
|
||||
- (id) initWithAttributes: (NSDictionary *)info
|
||||
{
|
||||
[self _initXContext];
|
||||
[super initWithAttributes: info];
|
||||
|
||||
[self setupRunLoopInputSourcesForMode: NSDefaultRunLoopMode];
|
||||
[self setupRunLoopInputSourcesForMode: NSConnectionReplyMode];
|
||||
[self setupRunLoopInputSourcesForMode: NSModalPanelRunLoopMode];
|
||||
[self setupRunLoopInputSourcesForMode: NSEventTrackingRunLoopMode];
|
||||
return self;
|
||||
}
|
||||
|
||||
/**
|
||||
Closes all X resources, the X display and dealloc other ivars.
|
||||
*/
|
||||
- (void) dealloc
|
||||
{
|
||||
NSDebugLog(@"Destroying X11 Server");
|
||||
DESTROY(inputServer);
|
||||
[self _destroyServerWindows];
|
||||
XCloseDisplay(XDPY);
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
/**
|
||||
Returns the XGDrawMechanism, which roughly describes the depth of
|
||||
the screen and how pixels should be drawn to the screen for maximum
|
||||
speed.
|
||||
*/
|
||||
- (XGDrawMechanism) drawMechanism
|
||||
{
|
||||
return drawMechanism;
|
||||
}
|
||||
|
||||
/**
|
||||
Returns a pointer to a structure which describes aspects of the
|
||||
X windows display
|
||||
*/
|
||||
- (void *) xrContext
|
||||
{
|
||||
return context;
|
||||
}
|
||||
|
||||
/*
|
||||
Returns a pointer to the X windows display variable
|
||||
*/
|
||||
- (Display *) xDisplay
|
||||
{
|
||||
return XDPY;
|
||||
}
|
||||
|
||||
/**
|
||||
Returns the root window of the display
|
||||
*/
|
||||
- (Window) xDisplayRootWindow
|
||||
{
|
||||
return RootWindow(XDPY, XSCR);
|
||||
}
|
||||
|
||||
/**
|
||||
Returns the application root window, which is used for many things
|
||||
such as window hints
|
||||
*/
|
||||
- (Window) xAppRootWindow
|
||||
{
|
||||
return generic.appRootWindow;
|
||||
}
|
||||
|
||||
/**
|
||||
Returns the closest color in the current colormap to the indicated
|
||||
X color
|
||||
*/
|
||||
- (XColor)xColorFromColor: (XColor)color
|
||||
{
|
||||
Status ret;
|
||||
RColor rcolor;
|
||||
Colormap colormap = XDefaultColormap(XDPY, XSCR);
|
||||
XAllocColor(XDPY, colormap, &color);
|
||||
rcolor.red = color.red / 256;
|
||||
rcolor.green = color.green / 256;
|
||||
rcolor.blue = color.blue / 256;
|
||||
ret = RGetClosestXColor((RContext *)context, &rcolor, &color);
|
||||
if (ret == False)
|
||||
NSLog(@"Failed to alloc color (%d,%d,%d)\n",
|
||||
(int)rcolor.red, (int)rcolor.green, (int)rcolor.blue);
|
||||
return color;
|
||||
}
|
||||
|
||||
/**
|
||||
Wait for all contexts to finish processing. Only used with XDPS graphics.
|
||||
*/
|
||||
+ (void) waitAllContexts
|
||||
{
|
||||
if ([[GSCurrentContext() class]
|
||||
respondsToSelector: @selector(waitAllContexts)])
|
||||
[[GSCurrentContext() class] waitAllContexts];
|
||||
}
|
||||
|
||||
@end
|
1828
Source/x11/XGServerEvent.m
Normal file
1828
Source/x11/XGServerEvent.m
Normal file
File diff suppressed because it is too large
Load diff
2612
Source/x11/XGServerWindow.m
Normal file
2612
Source/x11/XGServerWindow.m
Normal file
File diff suppressed because it is too large
Load diff
238
Source/x11/XGSlideView.m
Normal file
238
Source/x11/XGSlideView.m
Normal file
|
@ -0,0 +1,238 @@
|
|||
/*
|
||||
XGSlideView
|
||||
|
||||
Copyright (C) 2002 Free Software Foundation, Inc.
|
||||
|
||||
Created by: Enrico Sersale <enrico@imago.ro>
|
||||
Date: Jan 2002
|
||||
|
||||
This file is part of the GNU Objective C User Interface Library.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include <AppKit/NSApplication.h>
|
||||
#include <AppKit/NSCell.h>
|
||||
#include <AppKit/NSColor.h>
|
||||
#include <AppKit/NSCursor.h>
|
||||
#include <AppKit/NSImage.h>
|
||||
#include <AppKit/NSScreen.h>
|
||||
#include <AppKit/NSView.h>
|
||||
#include <AppKit/NSWindow.h>
|
||||
|
||||
#include "x11/XGServer.h"
|
||||
#include "x11/XGServerWindow.h"
|
||||
#include "x11/XGSlideView.h"
|
||||
#include <math.h>
|
||||
#include <X11/extensions/shape.h>
|
||||
|
||||
#define DWZ 48
|
||||
#define ALPHA_THRESHOLD 158
|
||||
|
||||
#define XDPY [XGServer currentXDisplay]
|
||||
|
||||
#ifndef max
|
||||
#define max(a,b) ((a) > (b) ? (a): (b))
|
||||
#endif
|
||||
|
||||
#ifndef min
|
||||
#define min(a,b) ((a) < (b) ? (a): (b))
|
||||
#endif
|
||||
|
||||
#define DMAX 1800
|
||||
#define MAXSTEPS 100
|
||||
|
||||
@interface XGSlideRawWindow : NSWindow
|
||||
@end
|
||||
|
||||
@interface NSImage (BackEnd)
|
||||
- (Pixmap) xPixmapMask;
|
||||
@end
|
||||
|
||||
@interface XGSlideView (Private)
|
||||
- (void) _setupWindow: (NSPoint)slideStart;
|
||||
- (BOOL) _slideFrom: (NSPoint)fromPoint to: (NSPoint)toPoint;
|
||||
@end
|
||||
|
||||
@implementation XGSlideView (Private)
|
||||
|
||||
- (void) _setupWindow: (NSPoint)slideStart
|
||||
{
|
||||
NSSize imageSize = [[slideCell image] size];
|
||||
Pixmap pixmap = 0;
|
||||
|
||||
[_window setFrame: NSMakeRect (slideStart.x, slideStart.y,
|
||||
imageSize.width, imageSize.height) display: NO];
|
||||
|
||||
if ([[[slideCell image] backgroundColor] alphaComponent] * 256
|
||||
<= ALPHA_THRESHOLD)
|
||||
{
|
||||
[self lockFocus];
|
||||
pixmap = [[slideCell image] xPixmapMask];
|
||||
[self unlockFocus];
|
||||
}
|
||||
|
||||
if (pixmap)
|
||||
{
|
||||
XShapeCombineMask(XDPY, slideWindev->ident, ShapeBounding, 0, 0,
|
||||
pixmap, ShapeSet);
|
||||
XFreePixmap(XDPY, pixmap);
|
||||
}
|
||||
else
|
||||
{
|
||||
XShapeCombineMask(XDPY, slideWindev->ident, ShapeBounding,
|
||||
0, 0, 0, ShapeSet);
|
||||
}
|
||||
|
||||
[_window orderFrontRegardless];
|
||||
}
|
||||
|
||||
- (BOOL) _slideFrom: (NSPoint)fromPoint to: (NSPoint)toPoint
|
||||
{
|
||||
float sheight = [[NSScreen mainScreen] frame].size.height;
|
||||
float iheight = [[slideCell image] size].height;
|
||||
NSPoint fPoint = NSMakePoint(fromPoint.x, sheight - fromPoint.y - iheight);
|
||||
NSPoint tPoint = NSMakePoint(toPoint.x, sheight - toPoint.y - iheight);
|
||||
float distx = max(fPoint.x, tPoint.x) - min(fPoint.x, tPoint.x);
|
||||
float disty = max(fPoint.y, tPoint.y) - min(fPoint.y, tPoint.y);
|
||||
float dist = sqrt((distx * distx) + (disty * disty));
|
||||
float r = DMAX / dist;
|
||||
int steps = (int)(MAXSTEPS / r);
|
||||
float unitx = distx / steps;
|
||||
float unity = disty / steps;
|
||||
float xp = fPoint.x;
|
||||
float yp = fPoint.y;
|
||||
float *xpositions
|
||||
= NSZoneMalloc (NSDefaultMallocZone(), sizeof(float) * steps);
|
||||
float *ypositions
|
||||
= NSZoneMalloc (NSDefaultMallocZone(), sizeof(float) * steps);
|
||||
NSEvent *theEvent;
|
||||
int i;
|
||||
|
||||
unitx = (tPoint.x > fPoint.x) ? unitx : -unitx;
|
||||
unity = (tPoint.y > fPoint.y) ? unity : -unity;
|
||||
|
||||
for (i = 0; i < steps; i++)
|
||||
{
|
||||
xp += unitx;
|
||||
yp += unity;
|
||||
xpositions[i] = xp;
|
||||
ypositions[i] = yp;
|
||||
}
|
||||
|
||||
XFlush(XDPY);
|
||||
[NSEvent startPeriodicEventsAfterDelay: 0.02 withPeriod: 0.02];
|
||||
for (i = 0; i < steps; i++)
|
||||
{
|
||||
theEvent = [NSApp nextEventMatchingMask: NSPeriodicMask
|
||||
untilDate: [NSDate distantFuture]
|
||||
inMode: NSEventTrackingRunLoopMode
|
||||
dequeue: YES];
|
||||
XMoveWindow (XDPY, slideWindev->ident, xpositions[i], ypositions[i]);
|
||||
}
|
||||
[NSEvent stopPeriodicEvents];
|
||||
|
||||
NSZoneFree (NSDefaultMallocZone(), xpositions);
|
||||
NSZoneFree (NSDefaultMallocZone(), ypositions);
|
||||
|
||||
[[self window] orderOut: nil];
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation XGSlideView
|
||||
|
||||
+ (BOOL) _slideImage: (NSImage *)image
|
||||
from: (NSPoint)fromPoint
|
||||
to: (NSPoint)toPoint
|
||||
{
|
||||
static XGSlideView *v = nil;
|
||||
BOOL result = NO;
|
||||
|
||||
if (image != nil)
|
||||
{
|
||||
if (v == nil)
|
||||
{
|
||||
v = [[self alloc] init];
|
||||
}
|
||||
[NSApp preventWindowOrdering];
|
||||
[v->slideCell setImage: image];
|
||||
[v _setupWindow: fromPoint];
|
||||
result = [v _slideFrom: fromPoint to: toPoint];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
- (id) init
|
||||
{
|
||||
self = [super init];
|
||||
if (self != nil)
|
||||
{
|
||||
NSRect winRect = {{0, 0}, {DWZ, DWZ}};
|
||||
XGSlideRawWindow *slideWindow = [XGSlideRawWindow alloc];
|
||||
|
||||
slideCell = [[NSCell alloc] initImageCell: nil];
|
||||
[slideCell setBordered: NO];
|
||||
|
||||
slideWindow = [slideWindow initWithContentRect: winRect
|
||||
styleMask: NSBorderlessWindowMask
|
||||
backing: NSBackingStoreNonretained
|
||||
defer: NO];
|
||||
[slideWindow setContentView: self];
|
||||
RELEASE (self);
|
||||
|
||||
slideWindev
|
||||
= [XGServer _windowWithTag: [slideWindow windowNumber]];
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
RELEASE (slideCell);
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (void) drawRect: (NSRect)rect
|
||||
{
|
||||
[slideCell drawWithFrame: rect inView: self];
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
|
||||
@implementation XGSlideRawWindow
|
||||
|
||||
- (BOOL) canBecomeMainWindow
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (BOOL) canBecomeKeyWindow
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (void) _initDefaults
|
||||
{
|
||||
[super _initDefaults];
|
||||
[self setReleasedWhenClosed: YES];
|
||||
[self setExcludedFromWindowsMenu: YES];
|
||||
}
|
||||
|
||||
@end
|
336
Source/x11/XIMInputServer.m
Normal file
336
Source/x11/XIMInputServer.m
Normal file
|
@ -0,0 +1,336 @@
|
|||
/* XIMInputServer - XIM Keyboard input handling
|
||||
|
||||
Copyright (C) 2002 Free Software Foundation, Inc.
|
||||
|
||||
Author: Christian Gillot <cgillot@neo-rousseaux.org>
|
||||
Date: Nov 2001
|
||||
Author: Adam Fedor <fedor@gnu.org>
|
||||
Date: Jan 2002
|
||||
|
||||
This file is part of the GNUstep GUI Library.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; see the file COPYING.LIB.
|
||||
If not, write to the Free Software Foundation,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <Foundation/NSData.h>
|
||||
#include <Foundation/NSDebug.h>
|
||||
#include <Foundation/NSException.h>
|
||||
#include <AppKit/NSWindow.h>
|
||||
|
||||
#include "x11/XGInputServer.h"
|
||||
#include <X11/Xlocale.h>
|
||||
|
||||
@interface XIMInputServer (XIMPrivate)
|
||||
- (BOOL) ximInit: (Display *)dpy;
|
||||
- (void) ximClose;
|
||||
- (int) ximStyleInit;
|
||||
- (XIC) ximCreateIC: (Window)w;
|
||||
- (unsigned long) ximXicGetMask: (XIC)xic;
|
||||
@end
|
||||
|
||||
#define BUF_LEN 255
|
||||
|
||||
@implementation XIMInputServer
|
||||
|
||||
- (id) initWithDelegate: (id)aDelegate
|
||||
name: (NSString *)name
|
||||
{
|
||||
Display *dpy = [XGServer currentXDisplay];
|
||||
return [self initWithDelegate: aDelegate display: dpy name: name];
|
||||
}
|
||||
|
||||
- (id) initWithDelegate: (id)aDelegate
|
||||
display: (Display *)dpy
|
||||
name: (NSString *)name
|
||||
{
|
||||
char *locale;
|
||||
NSString *localeEncoding;
|
||||
delegate = aDelegate;
|
||||
ASSIGN(server_name, name);
|
||||
dbuf = RETAIN([NSMutableData dataWithCapacity: BUF_LEN]);
|
||||
|
||||
/* Use X11 version of setlocale since many people just set the locale
|
||||
for X. Also just get CTYPE locale (which is typically the one that
|
||||
deals with character handling */
|
||||
locale = setlocale(LC_CTYPE, "");
|
||||
localeEncoding = [NSString stringWithCString: locale];
|
||||
if (XSupportsLocale() != True)
|
||||
{
|
||||
NSLog(@"Xlib does not support locale setting %@", localeEncoding);
|
||||
/* FIXME: Should we reset the locale or just hope that X
|
||||
can deal with it? */
|
||||
}
|
||||
localeEncoding = [[[localeEncoding componentsSeparatedByString: @"."]
|
||||
lastObject] lowercaseString];
|
||||
NSDebugLLog(@"XIM", @"XIM locale encoding is %@", localeEncoding);
|
||||
// FIXME: Use [GSFontInfo +encodingForRegistry:encoding:]?
|
||||
if ([localeEncoding isEqualToString:@"big5"])
|
||||
{
|
||||
encoding = NSBIG5StringEncoding;
|
||||
}
|
||||
#ifdef X_HAVE_UTF8_STRING
|
||||
else if ([localeEncoding isEqualToString:@"utf8"]
|
||||
|| [localeEncoding isEqualToString:@"utf-8"] )
|
||||
{
|
||||
encoding = NSUTF8StringEncoding;
|
||||
}
|
||||
#endif
|
||||
else
|
||||
{
|
||||
encoding = NSISOLatin1StringEncoding;
|
||||
}
|
||||
|
||||
#if USE_XIM
|
||||
if ([self ximInit: dpy] == NO)
|
||||
{
|
||||
NSLog(@"Unable to initialize XIM, using standard keyboard events");
|
||||
}
|
||||
#endif
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
DESTROY(server_name);
|
||||
DESTROY(dbuf);
|
||||
[self ximClose];
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
XInputFiltering protocol methods
|
||||
*/
|
||||
- (BOOL) filterEvent: (XEvent *)event
|
||||
{
|
||||
if (XFilterEvent(event, None))
|
||||
{
|
||||
NSDebugLLog(@"NSKeyEvent", @"Event filtered by XIM\n");
|
||||
return YES;
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (NSString *) lookupStringForEvent: (XKeyEvent *)event
|
||||
window: (gswindow_device_t *)windev
|
||||
keysym: (KeySym *)keysymptr
|
||||
{
|
||||
int count;
|
||||
Status status;
|
||||
NSString *keys;
|
||||
KeySym keysym;
|
||||
XComposeStatus compose;
|
||||
char *buf = [dbuf mutableBytes];
|
||||
|
||||
/* Process characters */
|
||||
keys = nil;
|
||||
if (windev->ic && event->type == KeyPress)
|
||||
{
|
||||
[dbuf setLength: BUF_LEN];
|
||||
#ifdef X_HAVE_UTF8_STRING
|
||||
if (encoding == NSUTF8StringEncoding)
|
||||
count = Xutf8LookupString(windev->ic, event, buf, BUF_LEN,
|
||||
&keysym, &status);
|
||||
else
|
||||
#endif
|
||||
count = XmbLookupString(windev->ic, event, buf, BUF_LEN,
|
||||
&keysym, &status);
|
||||
|
||||
if (status==XBufferOverflow)
|
||||
NSDebugLLog(@"NSKeyEvent",@"XmbLookupString buffer overflow\n");
|
||||
if (count)
|
||||
{
|
||||
[dbuf setLength: count];
|
||||
keys = [[NSString alloc] initWithData: dbuf encoding: encoding];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
count = XLookupString (event, buf, BUF_LEN, &keysym, &compose);
|
||||
/* Make sure that the string is properly terminated */
|
||||
if (count > BUF_LEN)
|
||||
buf[BUF_LEN] = '\0';
|
||||
else
|
||||
{
|
||||
if (count < 1)
|
||||
buf[0] = '\0';
|
||||
else
|
||||
buf[count] = '\0';
|
||||
}
|
||||
if (count)
|
||||
keys = [NSString stringWithCString: buf];
|
||||
}
|
||||
|
||||
if (keysymptr)
|
||||
*keysymptr = keysym;
|
||||
|
||||
return keys;
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
NSInputServiceProvider protocol methods
|
||||
*/
|
||||
- (void) activeConversationChanged: (id)sender
|
||||
toNewConversation: (long)newConversation
|
||||
{
|
||||
NSWindow *window;
|
||||
gswindow_device_t *windev;
|
||||
|
||||
[super activeConversationChanged: sender
|
||||
toNewConversation: newConversation];
|
||||
|
||||
if ([sender respondsToSelector: @selector(window)] == NO)
|
||||
{
|
||||
[NSException raise: NSInvalidArgumentException
|
||||
format: @"NSTextInput sender does not respond to window"];
|
||||
}
|
||||
window = [sender window];
|
||||
windev = [XGServer _windowWithTag: [window windowNumber]];
|
||||
if (windev == NULL)
|
||||
{
|
||||
[NSException raise: NSInvalidArgumentException
|
||||
format: @"NSTextInput sender has invalid window"];
|
||||
}
|
||||
|
||||
[self ximFocusICWindow: windev];
|
||||
}
|
||||
|
||||
- (void) activeConversationWillChange: (id)sender
|
||||
fromOldConversation: (long)oldConversation
|
||||
{
|
||||
[super activeConversationWillChange: sender
|
||||
fromOldConversation: oldConversation];
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
XIM private methods
|
||||
*/
|
||||
- (BOOL) ximInit: (Display *)dpy
|
||||
{
|
||||
XClassHint class_hints;
|
||||
|
||||
if (!XSetLocaleModifiers (""))
|
||||
NSDebugLLog(@"XIM", @"can not set locale modifiers\n");
|
||||
|
||||
/* FIXME: Get these */
|
||||
class_hints.res_name = class_hints.res_class = NULL;
|
||||
xim = XOpenIM(dpy, NULL, class_hints.res_name, class_hints.res_class);
|
||||
if (xim == NULL)
|
||||
{
|
||||
NSDebugLLog(@"XIM", @"Can't open XIM.\n");
|
||||
return NO;
|
||||
}
|
||||
|
||||
if (![self ximStyleInit])
|
||||
{
|
||||
[self ximClose];
|
||||
return NO;
|
||||
}
|
||||
|
||||
NSDebugLLog(@"XIM", @"Initialized XIM\n");
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (int) ximStyleInit
|
||||
{
|
||||
/* FIXME: Right now we only support this style *but*
|
||||
this is only temporary */
|
||||
XIMStyle xim_supported_style=XIMPreeditNothing|XIMStatusNothing;
|
||||
XIMStyles *styles;
|
||||
char *failed_arg;
|
||||
int i;
|
||||
|
||||
failed_arg = XGetIMValues(xim,XNQueryInputStyle,&styles,NULL);
|
||||
if (failed_arg!=NULL)
|
||||
{
|
||||
NSDebugLLog(@"XIM", @"Can't getting the following IM value :%s",
|
||||
failed_arg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (i=0;i<styles->count_styles;i++)
|
||||
{
|
||||
if (styles->supported_styles[i]==xim_supported_style)
|
||||
{
|
||||
xim_style=xim_supported_style;
|
||||
XFree(styles);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
XFree(styles);
|
||||
return 0;
|
||||
}
|
||||
|
||||
- (void) ximClose
|
||||
{
|
||||
NSDebugLLog(@"XIM", @"Closed XIM\n");
|
||||
if (xim)
|
||||
XCloseIM(xim);
|
||||
xim=NULL;
|
||||
}
|
||||
|
||||
- (void) ximFocusICWindow: (gswindow_device_t *)windev
|
||||
{
|
||||
if (xim == NULL)
|
||||
return;
|
||||
|
||||
/* Make sure we have an ic for this window */
|
||||
#if USE_XIM
|
||||
if (windev->ic == NULL)
|
||||
{
|
||||
windev->ic = [self ximCreateIC: windev->ident];
|
||||
if (windev->ic == NULL)
|
||||
{
|
||||
[self ximClose];
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Now set focus to this window */
|
||||
if (windev->ic)
|
||||
{
|
||||
NSDebugLLog(@"XIM", @"XSetICFocus to window %p",
|
||||
windev->ident);
|
||||
XSetICFocus(windev->ic);
|
||||
}
|
||||
}
|
||||
|
||||
- (XIC) ximCreateIC: (Window)w
|
||||
{
|
||||
XIC xic;
|
||||
xic = XCreateIC(xim, XNClientWindow, w, XNInputStyle,
|
||||
xim_style, XNFocusWindow, w, NULL);
|
||||
if (xic==NULL)
|
||||
NSDebugLLog(@"XIM", @"Can't create the input context.\n");
|
||||
return xic;
|
||||
}
|
||||
|
||||
- (unsigned long) ximXicGetMask: (XIC)xic
|
||||
{
|
||||
unsigned long xic_xmask = 0;
|
||||
if (XGetICValues(xic,XNFilterEvents,&xic_xmask,NULL)!=NULL)
|
||||
NSDebugLLog(@"XIM", @"Can't get the event mask for that input context");
|
||||
|
||||
return xic_xmask;
|
||||
}
|
||||
|
||||
- (void) ximCloseIC: (XIC)xic
|
||||
{
|
||||
XDestroyIC(xic);
|
||||
}
|
||||
|
||||
@end
|
800
Source/x11/context.c
Normal file
800
Source/x11/context.c
Normal file
|
@ -0,0 +1,800 @@
|
|||
/* context.c - X context management
|
||||
*
|
||||
* Raster graphics library
|
||||
*
|
||||
* Copyright (c) 1997, 1998, 1999 Alfredo K. Kojima
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free
|
||||
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xutil.h>
|
||||
#include <X11/Xatom.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "StdCmap.h"
|
||||
|
||||
#include "xrtools.h"
|
||||
|
||||
|
||||
extern void _wraster_change_filter(int type);
|
||||
|
||||
|
||||
static Bool bestContext(Display *dpy, int screen_number, RContext *context);
|
||||
|
||||
static RContextAttributes DEFAULT_CONTEXT_ATTRIBS = {
|
||||
RC_UseSharedMemory|RC_RenderMode|RC_ColorsPerChannel, /* flags */
|
||||
RDitheredRendering, /* render_mode */
|
||||
4, /* colors_per_channel */
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
True, /* use_shared_memory */
|
||||
RMitchellFilter,
|
||||
RUseStdColormap
|
||||
};
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
* Colormap allocation for PseudoColor visuals:
|
||||
*
|
||||
*
|
||||
* switch standardColormap:
|
||||
* none:
|
||||
* allocate colors according to colors_per_channel
|
||||
*
|
||||
* best/default:
|
||||
* if there's a std colormap defined then use it
|
||||
*
|
||||
* else
|
||||
* create a std colormap and set it
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*----------------------------------------------------------------------
|
||||
* allocateStandardPseudoColor
|
||||
* Creates the internal colormap for PseudoColor, setting the
|
||||
* color values according to the supplied standard colormap.
|
||||
*
|
||||
* Returns: -
|
||||
*
|
||||
* Side effects: -
|
||||
*
|
||||
* Notes: -
|
||||
*----------------------------------------------------------------------
|
||||
*/
|
||||
static Bool
|
||||
allocateStandardPseudoColor(RContext *ctx, XStandardColormap *stdcmap)
|
||||
{
|
||||
int i;
|
||||
|
||||
ctx->ncolors = stdcmap->red_max * stdcmap->red_mult
|
||||
+ stdcmap->green_max * stdcmap->green_mult
|
||||
+ stdcmap->blue_max * stdcmap->blue_mult + 1;
|
||||
|
||||
if (ctx->ncolors <= 1) {
|
||||
RErrorCode = RERR_INTERNAL;
|
||||
puts("wraster: bad standard colormap");
|
||||
|
||||
return False;
|
||||
}
|
||||
|
||||
ctx->colors = malloc(sizeof(XColor)*ctx->ncolors);
|
||||
if (!ctx->colors) {
|
||||
RErrorCode = RERR_NOMEMORY;
|
||||
|
||||
return False;
|
||||
}
|
||||
|
||||
ctx->pixels = malloc(sizeof(unsigned long)*ctx->ncolors);
|
||||
if (!ctx->pixels) {
|
||||
|
||||
free(ctx->colors);
|
||||
ctx->colors = NULL;
|
||||
|
||||
RErrorCode = RERR_NOMEMORY;
|
||||
|
||||
return False;
|
||||
}
|
||||
|
||||
|
||||
#define calc(max,mult) (((i / stdcmap->mult) % \
|
||||
(stdcmap->max + 1)) * 65535) / stdcmap->max
|
||||
|
||||
for (i = 0; i < ctx->ncolors; i++) {
|
||||
ctx->colors[i].pixel = i + stdcmap->base_pixel;
|
||||
ctx->colors[i].red = calc(red_max, red_mult);
|
||||
ctx->colors[i].green = calc(green_max, green_mult);
|
||||
ctx->colors[i].blue = calc(blue_max, blue_mult);
|
||||
|
||||
ctx->pixels[i] = ctx->colors[i].pixel;
|
||||
}
|
||||
|
||||
#undef calc
|
||||
|
||||
return True;
|
||||
}
|
||||
|
||||
|
||||
static Bool
|
||||
setupStandardColormap(RContext *ctx, Atom property)
|
||||
{
|
||||
if (!XmuLookupStandardColormap(ctx->dpy, ctx->screen_number,
|
||||
ctx->visual->visualid,
|
||||
ctx->depth, property,
|
||||
True, True)) {
|
||||
RErrorCode = RERR_STDCMAPFAIL;
|
||||
|
||||
return False;
|
||||
}
|
||||
return True;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static Bool
|
||||
allocatePseudoColor(RContext *ctx)
|
||||
{
|
||||
XColor *colors;
|
||||
XColor avcolors[256];
|
||||
int avncolors;
|
||||
int i, ncolors, r, g, b;
|
||||
int retries;
|
||||
int cpc = ctx->attribs->colors_per_channel;
|
||||
|
||||
ncolors = cpc * cpc * cpc;
|
||||
|
||||
if (ncolors > (1<<ctx->depth)) {
|
||||
/* reduce colormap size */
|
||||
cpc = ctx->attribs->colors_per_channel = 1<<((int)ctx->depth/3);
|
||||
ncolors = cpc * cpc * cpc;
|
||||
}
|
||||
|
||||
assert(cpc >= 2 && ncolors <= (1<<ctx->depth));
|
||||
|
||||
colors = malloc(sizeof(XColor)*ncolors);
|
||||
if (!colors) {
|
||||
RErrorCode = RERR_NOMEMORY;
|
||||
return False;
|
||||
}
|
||||
|
||||
ctx->pixels = malloc(sizeof(unsigned long)*ncolors);
|
||||
if (!ctx->pixels) {
|
||||
free(colors);
|
||||
RErrorCode = RERR_NOMEMORY;
|
||||
return False;
|
||||
}
|
||||
|
||||
i=0;
|
||||
|
||||
if ((ctx->attribs->flags & RC_GammaCorrection) && ctx->attribs->rgamma > 0
|
||||
&& ctx->attribs->ggamma > 0 && ctx->attribs->bgamma > 0) {
|
||||
double rg, gg, bg;
|
||||
double tmp;
|
||||
|
||||
/* do gamma correction */
|
||||
rg = 1.0/ctx->attribs->rgamma;
|
||||
gg = 1.0/ctx->attribs->ggamma;
|
||||
bg = 1.0/ctx->attribs->bgamma;
|
||||
for (r=0; r<cpc; r++) {
|
||||
for (g=0; g<cpc; g++) {
|
||||
for (b=0; b<cpc; b++) {
|
||||
colors[i].red=(r*0xffff) / (cpc-1);
|
||||
colors[i].green=(g*0xffff) / (cpc-1);
|
||||
colors[i].blue=(b*0xffff) / (cpc-1);
|
||||
colors[i].flags = DoRed|DoGreen|DoBlue;
|
||||
|
||||
tmp = (double)colors[i].red / 65536.0;
|
||||
colors[i].red = (unsigned short)(65536.0*pow(tmp, rg));
|
||||
|
||||
tmp = (double)colors[i].green / 65536.0;
|
||||
colors[i].green = (unsigned short)(65536.0*pow(tmp, gg));
|
||||
|
||||
tmp = (double)colors[i].blue / 65536.0;
|
||||
colors[i].blue = (unsigned short)(65536.0*pow(tmp, bg));
|
||||
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
for (r=0; r<cpc; r++) {
|
||||
for (g=0; g<cpc; g++) {
|
||||
for (b=0; b<cpc; b++) {
|
||||
colors[i].red=(r*0xffff) / (cpc-1);
|
||||
colors[i].green=(g*0xffff) / (cpc-1);
|
||||
colors[i].blue=(b*0xffff) / (cpc-1);
|
||||
colors[i].flags = DoRed|DoGreen|DoBlue;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/* try to allocate the colors */
|
||||
for (i=0; i<ncolors; i++) {
|
||||
if (!XAllocColor(ctx->dpy, ctx->cmap, &(colors[i]))) {
|
||||
colors[i].flags = 0; /* failed */
|
||||
} else {
|
||||
colors[i].flags = DoRed|DoGreen|DoBlue;
|
||||
}
|
||||
}
|
||||
/* try to allocate close values for the colors that couldn't
|
||||
* be allocated before */
|
||||
avncolors = (1<<ctx->depth>256 ? 256 : 1<<ctx->depth);
|
||||
for (i=0; i<avncolors; i++) avcolors[i].pixel = i;
|
||||
|
||||
XQueryColors(ctx->dpy, ctx->cmap, avcolors, avncolors);
|
||||
|
||||
for (i=0; i<ncolors; i++) {
|
||||
if (colors[i].flags==0) {
|
||||
int j;
|
||||
unsigned long cdiff=0xffffffff, diff;
|
||||
unsigned long closest=0;
|
||||
|
||||
retries = 2;
|
||||
|
||||
while (retries--) {
|
||||
/* find closest color */
|
||||
for (j=0; j<avncolors; j++) {
|
||||
r = (colors[i].red - avcolors[i].red)>>8;
|
||||
g = (colors[i].green - avcolors[i].green)>>8;
|
||||
b = (colors[i].blue - avcolors[i].blue)>>8;
|
||||
diff = r*r + g*g + b*b;
|
||||
if (diff<cdiff) {
|
||||
cdiff = diff;
|
||||
closest = j;
|
||||
}
|
||||
}
|
||||
/* allocate closest color found */
|
||||
colors[i].red = avcolors[closest].red;
|
||||
colors[i].green = avcolors[closest].green;
|
||||
colors[i].blue = avcolors[closest].blue;
|
||||
if (XAllocColor(ctx->dpy, ctx->cmap, &colors[i])) {
|
||||
colors[i].flags = DoRed|DoGreen|DoBlue;
|
||||
break; /* succeeded, don't need to retry */
|
||||
}
|
||||
#ifdef DEBUG
|
||||
printf("close color allocation failed. Retrying...\n");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ctx->colors = colors;
|
||||
ctx->ncolors = ncolors;
|
||||
|
||||
/* fill the pixels shortcut array */
|
||||
for (i = 0; i < ncolors; i++) {
|
||||
ctx->pixels[i] = ctx->colors[i].pixel;
|
||||
}
|
||||
|
||||
return True;
|
||||
}
|
||||
|
||||
|
||||
static XColor*
|
||||
allocateGrayScale(RContext *ctx)
|
||||
{
|
||||
XColor *colors;
|
||||
XColor avcolors[256];
|
||||
int avncolors;
|
||||
int i, ncolors, r, g, b;
|
||||
int retries;
|
||||
int cpc = ctx->attribs->colors_per_channel;
|
||||
|
||||
ncolors = cpc * cpc * cpc;
|
||||
|
||||
if (ctx->vclass == StaticGray) {
|
||||
/* we might as well use all grays */
|
||||
ncolors = 1<<ctx->depth;
|
||||
} else {
|
||||
if ( ncolors > (1<<ctx->depth) ) {
|
||||
/* reduce colormap size */
|
||||
cpc = ctx->attribs->colors_per_channel = 1<<((int)ctx->depth/3);
|
||||
ncolors = cpc * cpc * cpc;
|
||||
}
|
||||
|
||||
assert(cpc >= 2 && ncolors <= (1<<ctx->depth));
|
||||
}
|
||||
|
||||
if (ncolors>=256 && ctx->vclass==StaticGray) {
|
||||
/* don't need dithering for 256 levels of gray in StaticGray visual */
|
||||
ctx->attribs->render_mode = RBestMatchRendering;
|
||||
}
|
||||
|
||||
colors = malloc(sizeof(XColor)*ncolors);
|
||||
if (!colors) {
|
||||
RErrorCode = RERR_NOMEMORY;
|
||||
return False;
|
||||
}
|
||||
for (i=0; i<ncolors; i++) {
|
||||
colors[i].red=(i*0xffff) / (ncolors-1);
|
||||
colors[i].green=(i*0xffff) / (ncolors-1);
|
||||
colors[i].blue=(i*0xffff) / (ncolors-1);
|
||||
colors[i].flags = DoRed|DoGreen|DoBlue;
|
||||
}
|
||||
/* try to allocate the colors */
|
||||
for (i=0; i<ncolors; i++) {
|
||||
#ifdef DEBUG
|
||||
printf("trying:%x,%x,%x\n",colors[i].red,colors[i].green,colors[i].blue);
|
||||
#endif
|
||||
if (!XAllocColor(ctx->dpy, ctx->cmap, &(colors[i]))) {
|
||||
colors[i].flags = 0; /* failed */
|
||||
#ifdef DEBUG
|
||||
printf("failed:%x,%x,%x\n",colors[i].red,colors[i].green,colors[i].blue);
|
||||
#endif
|
||||
} else {
|
||||
colors[i].flags = DoRed|DoGreen|DoBlue;
|
||||
#ifdef DEBUG
|
||||
printf("success:%x,%x,%x\n",colors[i].red,colors[i].green,colors[i].blue);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
/* try to allocate close values for the colors that couldn't
|
||||
* be allocated before */
|
||||
avncolors = (1<<ctx->depth>256 ? 256 : 1<<ctx->depth);
|
||||
for (i=0; i<avncolors; i++) avcolors[i].pixel = i;
|
||||
|
||||
XQueryColors(ctx->dpy, ctx->cmap, avcolors, avncolors);
|
||||
|
||||
for (i=0; i<ncolors; i++) {
|
||||
if (colors[i].flags==0) {
|
||||
int j;
|
||||
unsigned long cdiff=0xffffffff, diff;
|
||||
unsigned long closest=0;
|
||||
|
||||
retries = 2;
|
||||
|
||||
while (retries--) {
|
||||
/* find closest color */
|
||||
for (j=0; j<avncolors; j++) {
|
||||
r = (colors[i].red - avcolors[i].red)>>8;
|
||||
g = (colors[i].green - avcolors[i].green)>>8;
|
||||
b = (colors[i].blue - avcolors[i].blue)>>8;
|
||||
diff = r*r + g*g + b*b;
|
||||
if (diff<cdiff) {
|
||||
cdiff = diff;
|
||||
closest = j;
|
||||
}
|
||||
}
|
||||
/* allocate closest color found */
|
||||
#ifdef DEBUG
|
||||
printf("best match:%x,%x,%x => %x,%x,%x\n",colors[i].red,colors[i].green,colors[i].blue,avcolors[closest].red,avcolors[closest].green,avcolors[closest].blue);
|
||||
#endif
|
||||
colors[i].red = avcolors[closest].red;
|
||||
colors[i].green = avcolors[closest].green;
|
||||
colors[i].blue = avcolors[closest].blue;
|
||||
if (XAllocColor(ctx->dpy, ctx->cmap, &colors[i])) {
|
||||
colors[i].flags = DoRed|DoGreen|DoBlue;
|
||||
break; /* succeeded, don't need to retry */
|
||||
}
|
||||
#ifdef DEBUG
|
||||
printf("close color allocation failed. Retrying...\n");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
return colors;
|
||||
}
|
||||
|
||||
|
||||
static Bool
|
||||
setupPseudoColorColormap(RContext *context)
|
||||
{
|
||||
Atom property = 0;
|
||||
|
||||
if (context->attribs->standard_colormap_mode == RCreateStdColormap) {
|
||||
property = XInternAtom(context->dpy, "RGB_DEFAULT_MAP", False);
|
||||
|
||||
if (!setupStandardColormap(context, property)) {
|
||||
return False;
|
||||
}
|
||||
}
|
||||
|
||||
if (context->attribs->standard_colormap_mode != RIgnoreStdColormap) {
|
||||
XStandardColormap *maps;
|
||||
int count, i;
|
||||
|
||||
if (!property) {
|
||||
property = XInternAtom(context->dpy, "RGB_BEST_MAP", False);
|
||||
if (!XGetRGBColormaps(context->dpy,
|
||||
DefaultRootWindow(context->dpy),
|
||||
&maps, &count, property)) {
|
||||
maps = NULL;
|
||||
}
|
||||
|
||||
if (!maps) {
|
||||
property = XInternAtom(context->dpy, "RGB_DEFAULT_MAP", False);
|
||||
if (!XGetRGBColormaps(context->dpy,
|
||||
DefaultRootWindow(context->dpy),
|
||||
&maps, &count, property)) {
|
||||
maps = NULL;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!XGetRGBColormaps(context->dpy,
|
||||
DefaultRootWindow(context->dpy),
|
||||
&maps, &count, property)) {
|
||||
maps = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (maps) {
|
||||
int theMap = -1;
|
||||
|
||||
for (i = 0; i < count; i++) {
|
||||
if (maps[i].visualid == context->visual->visualid) {
|
||||
theMap = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (theMap < 0) {
|
||||
puts("wrlib: no std cmap found");
|
||||
}
|
||||
|
||||
if (theMap >= 0
|
||||
&& allocateStandardPseudoColor(context, &maps[theMap])) {
|
||||
|
||||
context->std_rgb_map = XAllocStandardColormap();
|
||||
|
||||
*context->std_rgb_map = maps[theMap];
|
||||
|
||||
context->cmap = context->std_rgb_map->colormap;
|
||||
|
||||
XFree(maps);
|
||||
|
||||
return True;
|
||||
}
|
||||
|
||||
XFree(maps);
|
||||
}
|
||||
}
|
||||
|
||||
context->attribs->standard_colormap_mode = RIgnoreStdColormap;
|
||||
|
||||
/* RIgnoreStdColormap and fallback */
|
||||
return allocatePseudoColor(context);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
static char*
|
||||
mygetenv(char *var, int scr)
|
||||
{
|
||||
char *p;
|
||||
char varname[64];
|
||||
|
||||
sprintf(varname, "%s%i", var, scr);
|
||||
p = getenv(varname);
|
||||
if (!p) {
|
||||
p = getenv(var);
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
gatherconfig(RContext *context, int screen_n)
|
||||
{
|
||||
char *ptr;
|
||||
|
||||
ptr = mygetenv("WRASTER_GAMMA", screen_n);
|
||||
if (ptr) {
|
||||
float g1,g2,g3;
|
||||
if (sscanf(ptr, "%f/%f/%f", &g1, &g2, &g3)!=3
|
||||
|| g1<=0.0 || g2<=0.0 || g3<=0.0) {
|
||||
printf("wrlib: invalid value(s) for gamma correction \"%s\"\n",
|
||||
ptr);
|
||||
} else {
|
||||
context->attribs->flags |= RC_GammaCorrection;
|
||||
context->attribs->rgamma = g1;
|
||||
context->attribs->ggamma = g2;
|
||||
context->attribs->bgamma = g3;
|
||||
}
|
||||
}
|
||||
ptr = mygetenv("WRASTER_COLOR_RESOLUTION", screen_n);
|
||||
if (ptr) {
|
||||
int i;
|
||||
if (sscanf(ptr, "%d", &i)!=1 || i<2 || i>6) {
|
||||
printf("wrlib: invalid value for color resolution \"%s\"\n",ptr);
|
||||
} else {
|
||||
context->attribs->flags |= RC_ColorsPerChannel;
|
||||
context->attribs->colors_per_channel = i;
|
||||
}
|
||||
}
|
||||
|
||||
ptr = mygetenv("WRASTER_OPTIMIZE_FOR_SPEED", screen_n);
|
||||
if (ptr) {
|
||||
context->flags.optimize_for_speed = 1;
|
||||
} else {
|
||||
context->flags.optimize_for_speed = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
getColormap(RContext *context, int screen_number)
|
||||
{
|
||||
Colormap cmap = None;
|
||||
XStandardColormap *cmaps;
|
||||
int ncmaps, i;
|
||||
|
||||
if (XGetRGBColormaps(context->dpy,
|
||||
RootWindow(context->dpy, screen_number),
|
||||
&cmaps, &ncmaps, XA_RGB_DEFAULT_MAP)) {
|
||||
for (i=0; i<ncmaps; ++i) {
|
||||
if (cmaps[i].visualid == context->visual->visualid) {
|
||||
puts("ACHOU");
|
||||
cmap = cmaps[i].colormap;
|
||||
break;
|
||||
}
|
||||
}
|
||||
XFree(cmaps);
|
||||
}
|
||||
if (cmap == None) {
|
||||
XColor color;
|
||||
|
||||
cmap = XCreateColormap(context->dpy,
|
||||
RootWindow(context->dpy, screen_number),
|
||||
context->visual, AllocNone);
|
||||
|
||||
color.red = color.green = color.blue = 0;
|
||||
XAllocColor(context->dpy, cmap, &color);
|
||||
context->black = color.pixel;
|
||||
|
||||
color.red = color.green = color.blue = 0xffff;
|
||||
XAllocColor(context->dpy, cmap, &color);
|
||||
context->white = color.pixel;
|
||||
|
||||
}
|
||||
context->cmap = cmap;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
count_offset(unsigned long mask)
|
||||
{
|
||||
int i;
|
||||
|
||||
i=0;
|
||||
while ((mask & 1)==0) {
|
||||
i++;
|
||||
mask = mask >> 1;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
|
||||
RContext*
|
||||
RCreateContext(Display *dpy, int screen_number, RContextAttributes *attribs)
|
||||
{
|
||||
RContext *context;
|
||||
XGCValues gcv;
|
||||
|
||||
|
||||
context = malloc(sizeof(RContext));
|
||||
if (!context) {
|
||||
RErrorCode = RERR_NOMEMORY;
|
||||
return NULL;
|
||||
}
|
||||
memset(context, 0, sizeof(RContext));
|
||||
|
||||
context->dpy = dpy;
|
||||
|
||||
context->screen_number = screen_number;
|
||||
|
||||
context->attribs = malloc(sizeof(RContextAttributes));
|
||||
if (!context->attribs) {
|
||||
free(context);
|
||||
RErrorCode = RERR_NOMEMORY;
|
||||
return NULL;
|
||||
}
|
||||
if (!attribs)
|
||||
*context->attribs = DEFAULT_CONTEXT_ATTRIBS;
|
||||
else
|
||||
*context->attribs = *attribs;
|
||||
|
||||
if (!(context->attribs->flags & RC_StandardColormap)) {
|
||||
context->attribs->standard_colormap_mode = RUseStdColormap;
|
||||
}
|
||||
|
||||
/* get configuration from environment variables */
|
||||
gatherconfig(context, screen_number);
|
||||
#ifndef BENCH
|
||||
_wraster_change_filter(context->attribs->scaling_filter);
|
||||
#endif
|
||||
if ((context->attribs->flags & RC_VisualID)) {
|
||||
XVisualInfo *vinfo, templ;
|
||||
int nret;
|
||||
|
||||
templ.screen = screen_number;
|
||||
templ.visualid = context->attribs->visualid;
|
||||
vinfo = XGetVisualInfo(context->dpy, VisualIDMask|VisualScreenMask,
|
||||
&templ, &nret);
|
||||
if (!vinfo || nret==0) {
|
||||
free(context);
|
||||
RErrorCode = RERR_BADVISUALID;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (vinfo[0].visual == DefaultVisual(dpy, screen_number)) {
|
||||
context->attribs->flags |= RC_DefaultVisual;
|
||||
} else {
|
||||
XSetWindowAttributes attr;
|
||||
unsigned long mask;
|
||||
|
||||
context->visual = vinfo[0].visual;
|
||||
context->depth = vinfo[0].depth;
|
||||
context->vclass = vinfo[0].class;
|
||||
getColormap(context, screen_number);
|
||||
attr.colormap = context->cmap;
|
||||
attr.override_redirect = True;
|
||||
attr.border_pixel = 0;
|
||||
attr.background_pixel = 0;
|
||||
mask = CWBorderPixel|CWColormap|CWOverrideRedirect|CWBackPixel;
|
||||
context->drawable =
|
||||
XCreateWindow(dpy, RootWindow(dpy, screen_number), 1, 1,
|
||||
1, 1, 0, context->depth, CopyFromParent,
|
||||
context->visual, mask, &attr);
|
||||
/* XSetWindowColormap(dpy, context->drawable, attr.colormap);*/
|
||||
}
|
||||
XFree(vinfo);
|
||||
}
|
||||
|
||||
/* use default */
|
||||
if (!context->visual) {
|
||||
if ((context->attribs->flags & RC_DefaultVisual)
|
||||
|| !bestContext(dpy, screen_number, context)) {
|
||||
context->visual = DefaultVisual(dpy, screen_number);
|
||||
context->depth = DefaultDepth(dpy, screen_number);
|
||||
context->cmap = DefaultColormap(dpy, screen_number);
|
||||
context->drawable = RootWindow(dpy, screen_number);
|
||||
context->black = BlackPixel(dpy, screen_number);
|
||||
context->white = WhitePixel(dpy, screen_number);
|
||||
context->vclass = context->visual->class;
|
||||
}
|
||||
}
|
||||
|
||||
gcv.function = GXcopy;
|
||||
gcv.graphics_exposures = False;
|
||||
context->copy_gc = XCreateGC(dpy, context->drawable, GCFunction
|
||||
|GCGraphicsExposures, &gcv);
|
||||
|
||||
if (context->vclass == PseudoColor || context->vclass == StaticColor) {
|
||||
|
||||
if (!setupPseudoColorColormap(context)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
} else if (context->vclass == GrayScale || context->vclass == StaticGray) {
|
||||
context->colors = allocateGrayScale(context);
|
||||
if (!context->colors) {
|
||||
return NULL;
|
||||
}
|
||||
} else if (context->vclass == TrueColor) {
|
||||
/* calc offsets to create a TrueColor pixel */
|
||||
context->red_offset = count_offset(context->visual->red_mask);
|
||||
context->green_offset = count_offset(context->visual->green_mask);
|
||||
context->blue_offset = count_offset(context->visual->blue_mask);
|
||||
/* disable dithering on 24 bits visuals */
|
||||
if (context->depth >= 24)
|
||||
context->attribs->render_mode = RBestMatchRendering;
|
||||
}
|
||||
|
||||
/* check avaiability of MIT-SHM */
|
||||
#ifdef XSHM
|
||||
if (!(context->attribs->flags & RC_UseSharedMemory)) {
|
||||
context->attribs->flags |= RC_UseSharedMemory;
|
||||
context->attribs->use_shared_memory = True;
|
||||
}
|
||||
|
||||
if (context->attribs->use_shared_memory) {
|
||||
int major, minor;
|
||||
Bool sharedPixmaps;
|
||||
|
||||
context->flags.use_shared_pixmap = 0;
|
||||
|
||||
if (!XShmQueryVersion(context->dpy, &major, &minor, &sharedPixmaps)) {
|
||||
context->attribs->use_shared_memory = False;
|
||||
} else {
|
||||
if (XShmPixmapFormat(context->dpy)==ZPixmap)
|
||||
context->flags.use_shared_pixmap = sharedPixmaps;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return context;
|
||||
}
|
||||
|
||||
|
||||
static Bool
|
||||
bestContext(Display *dpy, int screen_number, RContext *context)
|
||||
{
|
||||
XVisualInfo *vinfo=NULL, rvinfo;
|
||||
int best = -1, numvis, i;
|
||||
long flags;
|
||||
XSetWindowAttributes attr;
|
||||
|
||||
rvinfo.class = TrueColor;
|
||||
rvinfo.screen = screen_number;
|
||||
flags = VisualClassMask | VisualScreenMask;
|
||||
|
||||
vinfo = XGetVisualInfo(dpy, flags, &rvinfo, &numvis);
|
||||
if (vinfo) { /* look for a TrueColor, 24-bit or more (pref 24) */
|
||||
for (i=numvis-1, best = -1; i>=0; i--) {
|
||||
if (vinfo[i].depth == 24) best = i;
|
||||
else if (vinfo[i].depth>24 && best<0) best = i;
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
if (best == -1) { /* look for a DirectColor, 24-bit or more (pref 24) */
|
||||
rvinfo.class = DirectColor;
|
||||
if (vinfo) XFree((char *) vinfo);
|
||||
vinfo = XGetVisualInfo(dpy, flags, &rvinfo, &numvis);
|
||||
if (vinfo) {
|
||||
for (i=0, best = -1; i<numvis; i++) {
|
||||
if (vinfo[i].depth == 24) best = i;
|
||||
else if (vinfo[i].depth>24 && best<0) best = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if (best > -1) {
|
||||
context->visual = vinfo[best].visual;
|
||||
context->depth = vinfo[best].depth;
|
||||
context->vclass = vinfo[best].class;
|
||||
getColormap(context, screen_number);
|
||||
attr.colormap = context->cmap;
|
||||
attr.override_redirect = True;
|
||||
attr.border_pixel = 0;
|
||||
context->drawable =
|
||||
XCreateWindow(dpy, RootWindow(dpy, screen_number),
|
||||
1, 1, 1, 1, 0, context->depth,
|
||||
CopyFromParent, context->visual,
|
||||
CWBorderPixel|CWColormap|CWOverrideRedirect, &attr);
|
||||
/* XSetWindowColormap(dpy, context->drawable, context->cmap);*/
|
||||
}
|
||||
if (vinfo) XFree((char *) vinfo);
|
||||
|
||||
if (best < 0)
|
||||
return False;
|
||||
else
|
||||
return True;
|
||||
}
|
1065
Source/x11/convert.c
Normal file
1065
Source/x11/convert.c
Normal file
File diff suppressed because it is too large
Load diff
605
Source/x11/draw.c
Normal file
605
Source/x11/draw.c
Normal file
|
@ -0,0 +1,605 @@
|
|||
/* draw.c - pixel plotting, line drawing
|
||||
*
|
||||
* Raster graphics library
|
||||
*
|
||||
* Copyright (c) 1998 Dan Pascu
|
||||
* Copyright (c) 2000 Alfredo K. Kojima
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free
|
||||
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "xrtools.h"
|
||||
|
||||
|
||||
#define MIN(a,b) ((a) < (b) ? (a) : (b))
|
||||
#define MAX(a,b) ((a) > (b) ? (a) : (b))
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Returns the color of the pixel at coordinates (x, y) in "color".
|
||||
*/
|
||||
Bool
|
||||
RGetPixel(RImage *image, int x, int y, RColor *color)
|
||||
{
|
||||
int ofs;
|
||||
|
||||
assert(image!=NULL);
|
||||
if (x < 0 || x >= image->width
|
||||
|| y < 0 || y >= image->height)
|
||||
return False;
|
||||
|
||||
if (image->format == RRGBAFormat) {
|
||||
ofs = (y*image->width + x) * 4;
|
||||
color->red = image->data[ofs];
|
||||
color->green = image->data[ofs++];
|
||||
color->blue = image->data[ofs++];
|
||||
color->alpha = image->data[ofs];
|
||||
} else {
|
||||
ofs = (y*image->width + x) * 3;
|
||||
color->red = image->data[ofs++];
|
||||
color->green = image->data[ofs++];
|
||||
color->blue = image->data[ofs++];
|
||||
/* If the image does not have alpha channel, we consider alpha 255 */
|
||||
color->alpha = 255;
|
||||
}
|
||||
|
||||
return True;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
RPutPixel(RImage *image, int x, int y, RColor *color)
|
||||
{
|
||||
unsigned char *ptr;
|
||||
|
||||
assert(image!=NULL);
|
||||
assert(color!=NULL);
|
||||
if (x < 0 || x >= image->width || y < 0 || y >= image->height)
|
||||
return;
|
||||
|
||||
if (image->format == RRGBAFormat) {
|
||||
ptr = image->data + (y*image->width + x) * 4;
|
||||
} else {
|
||||
ptr = image->data + (y*image->width + x) * 3;
|
||||
}
|
||||
|
||||
if (color->alpha==255) {
|
||||
*ptr++ = color->red;
|
||||
*ptr++ = color->green;
|
||||
*ptr++ = color->blue;
|
||||
if (image->format == RRGBAFormat) {
|
||||
*ptr = 255;
|
||||
}
|
||||
} else {
|
||||
register int alpha, nalpha, r, g, b;
|
||||
|
||||
r = color->red;
|
||||
g = color->green;
|
||||
b = color->blue;
|
||||
alpha = color->alpha;
|
||||
nalpha = 255 - alpha;
|
||||
|
||||
*ptr++ = (((int)*ptr * nalpha) + (r * alpha))/256;
|
||||
*ptr++ = (((int)*ptr * nalpha) + (g * alpha))/256;
|
||||
*ptr++ = (((int)*ptr * nalpha) + (b * alpha))/256;
|
||||
if (image->format == RRGBAFormat) {
|
||||
*ptr = alpha + ((int)*ptr * nalpha)/256;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
operatePixel(RImage *image, int ofs, int operation, RColor *color)
|
||||
{
|
||||
unsigned char *sr, *sg, *sb, *sa;
|
||||
register int alpha, nalpha, tmp;
|
||||
int hasAlpha = image->format == RRGBAFormat;
|
||||
|
||||
alpha = color->alpha;
|
||||
nalpha = 255 - alpha;
|
||||
|
||||
sr = image->data + ofs*(hasAlpha ? 4 : 3);
|
||||
sg = image->data + ofs*(hasAlpha ? 4 : 3) + 1;
|
||||
sb = image->data + ofs*(hasAlpha ? 4 : 3) + 2;
|
||||
sa = image->data + ofs*(hasAlpha ? 4 : 3) + 3;
|
||||
|
||||
switch (operation) {
|
||||
case RClearOperation:
|
||||
*sr = 0;
|
||||
*sg = 0;
|
||||
*sb = 0;
|
||||
if (hasAlpha)
|
||||
*sa = 0;
|
||||
break;
|
||||
case RCopyOperation:
|
||||
*sr = color->red;
|
||||
*sg = color->green;
|
||||
*sb = color->blue;
|
||||
if (hasAlpha)
|
||||
*sa = color->alpha;
|
||||
break;
|
||||
case RNormalOperation:
|
||||
if (color->alpha==255) {
|
||||
*sr = color->red;
|
||||
*sg = color->green;
|
||||
*sb = color->blue;
|
||||
if (hasAlpha)
|
||||
*sa = 255;
|
||||
} else {
|
||||
*sr = (((int)*sr * nalpha) + ((int)color->red * alpha))/256;
|
||||
*sg = (((int)*sg * nalpha) + ((int)color->green * alpha))/256;
|
||||
*sb = (((int)*sb * nalpha) + ((int)color->blue * alpha))/256;
|
||||
}
|
||||
break;
|
||||
case RAddOperation:
|
||||
tmp = color->red + *sr;
|
||||
*sr = MIN(255, tmp);
|
||||
tmp = color->green + *sg;
|
||||
*sg = MIN(255, tmp);
|
||||
tmp = color->blue + *sb;
|
||||
*sb = MIN(255, tmp);
|
||||
if (hasAlpha)
|
||||
*sa = MIN(*sa, color->alpha);
|
||||
break;
|
||||
case RSubtractOperation:
|
||||
tmp = *sr - color->red;
|
||||
*sr = MAX(0, tmp);
|
||||
tmp = *sg - color->green;
|
||||
*sg = MAX(0, tmp);
|
||||
tmp = *sb - color->blue;
|
||||
*sb = MAX(0, tmp);
|
||||
if (hasAlpha)
|
||||
*sa = MIN(*sa, color->alpha);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void
|
||||
ROperatePixel(RImage *image, int operation, int x, int y, RColor *color)
|
||||
{
|
||||
int ofs;
|
||||
|
||||
assert(image!=NULL);
|
||||
assert(color!=NULL);
|
||||
assert(x >= 0 && x < image->width);
|
||||
assert(y >= 0 && y < image->height);
|
||||
|
||||
ofs = y*image->width + x;
|
||||
|
||||
operatePixel(image, ofs, operation, color);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
RPutPixels(RImage *image, RPoint *points, int npoints, int mode, RColor *color)
|
||||
{
|
||||
register int x, y, i;
|
||||
|
||||
assert(image!=NULL);
|
||||
assert(points!=NULL);
|
||||
|
||||
x = y = 0;
|
||||
|
||||
for (i=0; i<npoints; i++) {
|
||||
if (mode == RAbsoluteCoordinates) {
|
||||
x = points[i].x;
|
||||
y = points[i].y;
|
||||
} else {
|
||||
x += points[i].x;
|
||||
y += points[i].y;
|
||||
}
|
||||
RPutPixel(image, x, y, color);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ROperatePixels(RImage *image, int operation, RPoint *points, int npoints,
|
||||
int mode, RColor *color)
|
||||
{
|
||||
register int x, y, i;
|
||||
|
||||
assert(image!=NULL);
|
||||
assert(points!=NULL);
|
||||
|
||||
x = y = 0;
|
||||
|
||||
for (i=0; i<npoints; i++) {
|
||||
if (mode == RAbsoluteCoordinates) {
|
||||
x = points[i].x;
|
||||
y = points[i].y;
|
||||
} else {
|
||||
x += points[i].x;
|
||||
y += points[i].y;
|
||||
}
|
||||
ROperatePixel(image, operation, x, y, color);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static Bool
|
||||
clipLineInRectangle(int xmin, int ymin, int xmax, int ymax,
|
||||
int *x1, int *y1, int *x2, int *y2)
|
||||
{
|
||||
#define TOP (1<<0)
|
||||
#define BOT (1<<1)
|
||||
#define LEF (1<<2)
|
||||
#define RIG (1<<3)
|
||||
#define CHECK_OUT(X,Y) (((Y) > ymax ? TOP : ((Y) < ymin ? BOT : 0))\
|
||||
| ((X) > xmax ? RIG : ((X) < xmin ? LEF : 0)))
|
||||
|
||||
int ocode1, ocode2, ocode;
|
||||
int accept = 0;
|
||||
int x, y;
|
||||
|
||||
ocode1 = CHECK_OUT(*x1, *y1);
|
||||
ocode2 = CHECK_OUT(*x2, *y2);
|
||||
|
||||
for(;;) {
|
||||
if (!ocode1 && !ocode2) { /* completely inside */
|
||||
accept = 1;
|
||||
break;
|
||||
} else if (ocode1 & ocode2) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (ocode1)
|
||||
ocode = ocode1;
|
||||
else
|
||||
ocode = ocode2;
|
||||
|
||||
if (ocode & TOP) {
|
||||
x = *x1 + (*x2 - *x1) * (ymax - *y1) / (*y2 - *y1);
|
||||
y = ymax;
|
||||
} else if (ocode & BOT) {
|
||||
x = *x1 + (*x2 - *x1) * (ymin - *y1) / (*y2 - *y1);
|
||||
y = ymin;
|
||||
} else if (ocode & RIG) {
|
||||
y = *y1 + (*y2 - *y1) * (xmax - *x1) / (*x2 - *x1);
|
||||
x = xmax;
|
||||
} else if (ocode & LEF) {
|
||||
y = *y1 + (*y2 - *y1) * (xmax - *x1) / (*x2 - *x1);
|
||||
x = xmin;
|
||||
}
|
||||
|
||||
if (ocode == ocode1) {
|
||||
*x1 = x;
|
||||
*y1 = y;
|
||||
ocode1 = CHECK_OUT(x, y);
|
||||
} else {
|
||||
*x2 = x;
|
||||
*y2 = y;
|
||||
ocode2 = CHECK_OUT(x, y);
|
||||
}
|
||||
}
|
||||
|
||||
return accept;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* This routine is a generic drawing routine, based on Bresenham's line
|
||||
* drawing algorithm.
|
||||
*/
|
||||
static int
|
||||
genericLine(RImage *image, int x0, int y0, int x1, int y1, RColor *color,
|
||||
int operation, int polyline)
|
||||
{
|
||||
int i, err, du, dv, du2, dv2, uofs, vofs, last;
|
||||
|
||||
assert(image!=NULL);
|
||||
|
||||
if (!clipLineInRectangle(0, 0, image->width-1, image->height-1,
|
||||
&x0, &y0, &x1, &y1))
|
||||
return True;
|
||||
|
||||
if (x0 < x1) {
|
||||
du = x1 - x0;
|
||||
uofs = 1;
|
||||
} else {
|
||||
du = x0 - x1;
|
||||
uofs = -1;
|
||||
}
|
||||
if (y0 < y1) {
|
||||
dv = y1 -y0;
|
||||
vofs = image->width;
|
||||
} else {
|
||||
dv = y0 - y1;
|
||||
vofs = -image->width;
|
||||
}
|
||||
|
||||
if (du < dv) {
|
||||
/* Swap coordinates between them, so that always du>dv */
|
||||
i = du; du = dv; dv = i;
|
||||
i = uofs; uofs = vofs; vofs = i;
|
||||
}
|
||||
|
||||
err = 0;
|
||||
du2 = du<<1;
|
||||
dv2 = dv<<1;
|
||||
last = (polyline) ? du-1 : du;
|
||||
|
||||
if (color->alpha==255 || operation==RCopyOperation) {
|
||||
unsigned char *ptr;
|
||||
|
||||
if (image->format == RRGBAFormat)
|
||||
i = (y0*image->width + x0) * 4;
|
||||
else
|
||||
i = (y0*image->width + x0) * 3;
|
||||
ptr = image->data + i;
|
||||
|
||||
for (i=0; i<=last; i++) {
|
||||
/* Draw the pixel */
|
||||
*ptr = color->red;
|
||||
*(ptr+1) = color->green;
|
||||
*(ptr+2) = color->blue;
|
||||
if (image->format == RRGBAFormat)
|
||||
*(ptr+3) = 255;
|
||||
|
||||
/* Compute error for NeXT Step */
|
||||
err += dv2;
|
||||
if (err >= du) {
|
||||
if (image->format == RRGBAFormat)
|
||||
ptr += vofs*4;
|
||||
else
|
||||
ptr += vofs*3;
|
||||
err -= du2;
|
||||
}
|
||||
if (image->format == RRGBAFormat)
|
||||
ptr += uofs*4;
|
||||
else
|
||||
ptr += uofs*3;
|
||||
}
|
||||
} else {
|
||||
register int ofs = y0*image->width + x0;
|
||||
|
||||
for (i=0; i<=last; i++) {
|
||||
/* Draw the pixel */
|
||||
operatePixel(image, ofs, operation, color);
|
||||
|
||||
/* Compute error for NeXT Step */
|
||||
err += dv2;
|
||||
if (err >= du) {
|
||||
ofs += vofs;
|
||||
err -= du2;
|
||||
}
|
||||
ofs += uofs;
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
if (mode == RALTER_PIXELS) {
|
||||
RColorOffset *cdelta = (RColorOffset*)cdata;
|
||||
register short r, g, b, a;
|
||||
|
||||
for (i=0; i<=last; i++) {
|
||||
/* Change the pixel with offset */
|
||||
r = (short)*sr + cdelta->red;
|
||||
g = (short)*sg + cdelta->green;
|
||||
b = (short)*sb + cdelta->blue;
|
||||
if (r>255) r = 255; else if (r<0) r = 0;
|
||||
if (g>255) g = 255; else if (g<0) g = 0;
|
||||
if (b>255) b = 255; else if (b<0) b = 0;
|
||||
*sr = (unsigned char) r;
|
||||
*sg = (unsigned char) g;
|
||||
*sb = (unsigned char) b;
|
||||
if (image->data[3]) {
|
||||
a = (short)*sa + cdelta->alpha;
|
||||
if (a>255) a = 255; else if (a<0) a = 0;
|
||||
*sa = (unsigned char) a;
|
||||
}
|
||||
|
||||
/* Compute error for NeXT Step */
|
||||
err += dv2;
|
||||
if (err >= du) {
|
||||
sr += vofs; sg += vofs;
|
||||
sb += vofs; sa += vofs;
|
||||
err -= du2;
|
||||
}
|
||||
sr += uofs; sg += uofs;
|
||||
sb += uofs; sa += uofs;
|
||||
}
|
||||
} else {
|
||||
RColor *color = (RColor*)cdata;
|
||||
|
||||
if (color->alpha==255) {
|
||||
for (i=0; i<=last; i++) {
|
||||
/* Draw the pixel */
|
||||
*sr = color->red;
|
||||
*sg = color->green;
|
||||
*sb = color->blue;
|
||||
if (image->data[3])
|
||||
*sa = 255;
|
||||
|
||||
/* Compute error for NeXT Step */
|
||||
err += dv2;
|
||||
if (err >= du) {
|
||||
sr += vofs; sg += vofs;
|
||||
sb += vofs; sa += vofs;
|
||||
err -= du2;
|
||||
}
|
||||
sr += uofs; sg += uofs;
|
||||
sb += uofs; sa += uofs;
|
||||
}
|
||||
} else {
|
||||
register short alpha, nalpha, r, g ,b;
|
||||
|
||||
alpha = color->alpha;
|
||||
nalpha = 255 - alpha;
|
||||
r = color->red;
|
||||
g = color->green;
|
||||
b = color->blue;
|
||||
|
||||
for (i=0; i<=last; i++) {
|
||||
/* Draw the pixel */
|
||||
*sr = (((int)*sr * nalpha) + (r * alpha))/256;
|
||||
*sg = (((int)*sg * nalpha) + (g * alpha))/256;
|
||||
*sb = (((int)*sb * nalpha) + (b * alpha))/256;
|
||||
if (image->data[3])
|
||||
*sa = alpha + ((int)*sa * nalpha)/256;
|
||||
|
||||
/* Compute error for NeXT Step */
|
||||
err += dv2;
|
||||
if (err >= du) {
|
||||
sr += vofs; sg += vofs;
|
||||
sb += vofs; sa += vofs;
|
||||
err -= du2;
|
||||
}
|
||||
sr += uofs; sg += uofs;
|
||||
sb += uofs; sa += uofs;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return True;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
RDrawLine(RImage *image, int x0, int y0, int x1, int y1, RColor *color)
|
||||
{
|
||||
return genericLine(image, x0, y0, x1, y1, color, RNormalOperation, False);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
ROperateLine(RImage *image, int operation, int x0, int y0, int x1,
|
||||
int y1, RColor *color)
|
||||
{
|
||||
return genericLine(image, x0, y0, x1, y1, color, operation, False);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
RDrawLines(RImage *image, RPoint *points, int npoints, int mode, RColor *color)
|
||||
{
|
||||
register int x1, y1, x2, y2, i;
|
||||
|
||||
assert(points!=NULL);
|
||||
|
||||
if (npoints==0)
|
||||
return;
|
||||
|
||||
x1 = points[0].x;
|
||||
y1 = points[0].y;
|
||||
x2 = y2 = 0;
|
||||
|
||||
for (i=1; i<npoints-1; i++) {
|
||||
if (mode == RAbsoluteCoordinates) {
|
||||
x2 = points[i].x;
|
||||
y2 = points[i].y;
|
||||
} else {
|
||||
x2 += points[i-1].x;
|
||||
y2 += points[i-1].y;
|
||||
}
|
||||
/* Don't draw pixels at junction points twice */
|
||||
genericLine(image, x1, y1, x2, y2, color, RNormalOperation, True);
|
||||
x1 = x2;
|
||||
y1 = y2;
|
||||
}
|
||||
i = npoints-1; /* last point */
|
||||
if (mode == RAbsoluteCoordinates) {
|
||||
x2 = points[i].x;
|
||||
y2 = points[i].y;
|
||||
} else {
|
||||
x2 += points[i-1].x;
|
||||
y2 += points[i-1].y;
|
||||
}
|
||||
i = (points[0].x==x2 && points[0].y==y2 && npoints>1);
|
||||
genericLine(image, x1, y1, x2, y2, color, RNormalOperation, i);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ROperateLines(RImage *image, int operation, RPoint *points,
|
||||
int npoints, int mode, RColor *color)
|
||||
{
|
||||
register int x1, y1, x2, y2, i;
|
||||
|
||||
assert(points!=NULL);
|
||||
|
||||
if (npoints==0)
|
||||
return;
|
||||
|
||||
x1 = points[0].x;
|
||||
y1 = points[0].y;
|
||||
x2 = y2 = 0;
|
||||
|
||||
for (i=1; i<npoints-1; i++) {
|
||||
if (mode == RAbsoluteCoordinates) {
|
||||
x2 = points[i].x;
|
||||
y2 = points[i].y;
|
||||
} else {
|
||||
x2 += points[i-1].x;
|
||||
y2 += points[i-1].y;
|
||||
}
|
||||
/* Don't draw pixels at junction points twice */
|
||||
genericLine(image, x1, y1, x2, y2, color, operation, True);
|
||||
x1 = x2;
|
||||
y1 = y2;
|
||||
}
|
||||
i = npoints-1; /* last point */
|
||||
if (mode == RAbsoluteCoordinates) {
|
||||
x2 = points[i].x;
|
||||
y2 = points[i].y;
|
||||
} else {
|
||||
x2 += points[i-1].x;
|
||||
y2 += points[i-1].y;
|
||||
}
|
||||
i = (points[0].x==x2 && points[0].y==y2 && npoints>1);
|
||||
genericLine(image, x1, y1, x2, y2, color, operation, i);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
RDrawSegments(RImage *image, RSegment *segs, int nsegs, RColor *color)
|
||||
{
|
||||
register int i;
|
||||
|
||||
assert(segs!=NULL);
|
||||
|
||||
for (i=0; i<nsegs; i++) {
|
||||
genericLine(image, segs->x1, segs->y1, segs->x2, segs->y2, color,
|
||||
RNormalOperation, False);
|
||||
segs++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ROperateSegments(RImage *image, int operation, RSegment *segs,
|
||||
int nsegs, RColor *color)
|
||||
{
|
||||
register int i;
|
||||
|
||||
assert(segs!=NULL);
|
||||
|
||||
for (i=0; i<nsegs; i++) {
|
||||
genericLine(image, segs->x1, segs->y1, segs->x2, segs->y2, color,
|
||||
operation, False);
|
||||
segs++;
|
||||
}
|
||||
}
|
||||
|
488
Source/x11/gradient.c
Normal file
488
Source/x11/gradient.c
Normal file
|
@ -0,0 +1,488 @@
|
|||
/* gradient.c - renders gradients
|
||||
*
|
||||
* Raster graphics library
|
||||
*
|
||||
* Copyright (c) 1997-2000 Alfredo K. Kojima
|
||||
* Copyright (c) 1998-2000 Dan Pascu
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free
|
||||
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include "xrtools.h"
|
||||
|
||||
|
||||
static RImage *renderHGradient(unsigned width, unsigned height,
|
||||
int r0, int g0, int b0,
|
||||
int rf, int gf, int bf);
|
||||
static RImage *renderVGradient(unsigned width, unsigned height,
|
||||
int r0, int g0, int b0,
|
||||
int rf, int gf, int bf);
|
||||
static RImage *renderDGradient(unsigned width, unsigned height,
|
||||
int r0, int g0, int b0,
|
||||
int rf, int gf, int bf);
|
||||
|
||||
static RImage *renderMHGradient(unsigned width, unsigned height,
|
||||
RColor **colors, int count);
|
||||
static RImage *renderMVGradient(unsigned width, unsigned height,
|
||||
RColor **colors, int count);
|
||||
static RImage *renderMDGradient(unsigned width, unsigned height,
|
||||
RColor **colors, int count);
|
||||
|
||||
RImage*
|
||||
RRenderMultiGradient(unsigned width, unsigned height, RColor **colors, int style)
|
||||
{
|
||||
int count;
|
||||
|
||||
count = 0;
|
||||
while (colors[count]!=NULL) count++;
|
||||
|
||||
if (count > 2) {
|
||||
switch (style) {
|
||||
case RHorizontalGradient:
|
||||
return renderMHGradient(width, height, colors, count);
|
||||
case RVerticalGradient:
|
||||
return renderMVGradient(width, height, colors, count);
|
||||
case RDiagonalGradient:
|
||||
return renderMDGradient(width, height, colors, count);
|
||||
}
|
||||
} else if (count > 1) {
|
||||
return RRenderGradient(width, height, colors[0], colors[1], style);
|
||||
} else if (count > 0) {
|
||||
return RRenderGradient(width, height, colors[0], colors[0], style);
|
||||
}
|
||||
assert(0);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
RImage*
|
||||
RRenderGradient(unsigned width, unsigned height, RColor *from, RColor *to,
|
||||
int style)
|
||||
{
|
||||
switch (style) {
|
||||
case RHorizontalGradient:
|
||||
return renderHGradient(width, height, from->red, from->green,
|
||||
from->blue, to->red, to->green, to->blue);
|
||||
case RVerticalGradient:
|
||||
return renderVGradient(width, height, from->red, from->green,
|
||||
from->blue, to->red, to->green, to->blue);
|
||||
|
||||
case RDiagonalGradient:
|
||||
return renderDGradient(width, height, from->red, from->green,
|
||||
from->blue, to->red, to->green, to->blue);
|
||||
}
|
||||
assert(0);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*----------------------------------------------------------------------
|
||||
* renderHGradient--
|
||||
* Renders a horizontal linear gradient of the specified size in the
|
||||
* RImage format with a border of the specified type.
|
||||
*
|
||||
* Returns:
|
||||
* A 24bit RImage with the gradient (no alpha channel).
|
||||
*
|
||||
* Side effects:
|
||||
* None
|
||||
*----------------------------------------------------------------------
|
||||
*/
|
||||
static RImage*
|
||||
renderHGradient(unsigned width, unsigned height, int r0, int g0, int b0,
|
||||
int rf, int gf, int bf)
|
||||
{
|
||||
int i;
|
||||
unsigned long r, g, b, dr, dg, db;
|
||||
RImage *image;
|
||||
unsigned char *ptr;
|
||||
|
||||
image = RCreateImage(width, height, False);
|
||||
if (!image) {
|
||||
return NULL;
|
||||
}
|
||||
ptr = image->data;
|
||||
|
||||
r = r0 << 16;
|
||||
g = g0 << 16;
|
||||
b = b0 << 16;
|
||||
|
||||
dr = ((rf-r0)<<16)/(int)width;
|
||||
dg = ((gf-g0)<<16)/(int)width;
|
||||
db = ((bf-b0)<<16)/(int)width;
|
||||
/* render the first line */
|
||||
for (i=0; i<width; i++) {
|
||||
*(ptr++) = (unsigned char)(r>>16);
|
||||
*(ptr++) = (unsigned char)(g>>16);
|
||||
*(ptr++) = (unsigned char)(b>>16);
|
||||
r += dr;
|
||||
g += dg;
|
||||
b += db;
|
||||
}
|
||||
|
||||
/* copy the first line to the other lines */
|
||||
for (i=1; i<height; i++) {
|
||||
memcpy(&(image->data[i*width*3]), image->data, width*3);
|
||||
}
|
||||
return image;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*----------------------------------------------------------------------
|
||||
* renderVGradient--
|
||||
* Renders a vertical linear gradient of the specified size in the
|
||||
* RImage format with a border of the specified type.
|
||||
*
|
||||
* Returns:
|
||||
* A 24bit RImage with the gradient (no alpha channel).
|
||||
*
|
||||
* Side effects:
|
||||
* None
|
||||
*----------------------------------------------------------------------
|
||||
*/
|
||||
static RImage*
|
||||
renderVGradient(unsigned width, unsigned height, int r0, int g0, int b0,
|
||||
int rf, int gf, int bf)
|
||||
{
|
||||
int i, j;
|
||||
unsigned long r, g, b, dr, dg, db;
|
||||
RImage *image;
|
||||
unsigned char *ptr;
|
||||
unsigned int *iptr;
|
||||
unsigned char rr, gg, bb;
|
||||
|
||||
image = RCreateImage(width, height, False);
|
||||
if (!image) {
|
||||
return NULL;
|
||||
}
|
||||
iptr = (unsigned int*)ptr = image->data;
|
||||
|
||||
r = r0<<16;
|
||||
g = g0<<16;
|
||||
b = b0<<16;
|
||||
|
||||
dr = ((rf-r0)<<16)/(int)height;
|
||||
dg = ((gf-g0)<<16)/(int)height;
|
||||
db = ((bf-b0)<<16)/(int)height;
|
||||
|
||||
for (i=0; i<height; i++) {
|
||||
rr = r>>16;
|
||||
gg = g>>16;
|
||||
bb = b>>16;
|
||||
for (j=0; j<width/8; j++) {
|
||||
*(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
|
||||
*(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
|
||||
*(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
|
||||
*(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
|
||||
*(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
|
||||
*(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
|
||||
*(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
|
||||
*(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
|
||||
}
|
||||
switch (width%8) {
|
||||
case 7: *(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
|
||||
case 6: *(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
|
||||
case 5: *(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
|
||||
case 4: *(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
|
||||
case 3: *(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
|
||||
case 2: *(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
|
||||
case 1: *(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
|
||||
}
|
||||
r+=dr;
|
||||
g+=dg;
|
||||
b+=db;
|
||||
}
|
||||
return image;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*----------------------------------------------------------------------
|
||||
* renderDGradient--
|
||||
* Renders a diagonal linear gradient of the specified size in the
|
||||
* RImage format with a border of the specified type.
|
||||
*
|
||||
* Returns:
|
||||
* A 24bit RImage with the gradient (no alpha channel).
|
||||
*
|
||||
* Side effects:
|
||||
* None
|
||||
*----------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
static RImage*
|
||||
renderDGradient(unsigned width, unsigned height, int r0, int g0, int b0,
|
||||
int rf, int gf, int bf)
|
||||
{
|
||||
RImage *image, *tmp;
|
||||
int j;
|
||||
float a, offset;
|
||||
char *ptr;
|
||||
|
||||
if (width == 1)
|
||||
return renderVGradient(width, height, r0, g0, b0, rf, gf, bf);
|
||||
else if (height == 1)
|
||||
return renderHGradient(width, height, r0, g0, b0, rf, gf, bf);
|
||||
|
||||
image = RCreateImage(width, height, False);
|
||||
if (!image) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
tmp = renderHGradient(2*width-1, 1, r0, g0, b0, rf, gf, bf);
|
||||
if (!tmp) {
|
||||
RDestroyImage(image);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ptr = tmp->data;
|
||||
|
||||
a = ((float)(width - 1))/((float)(height - 1));
|
||||
width = width * 3;
|
||||
|
||||
/* copy the first line to the other lines with corresponding offset */
|
||||
for (j=0, offset=0.0; j<width*height; j += width) {
|
||||
memcpy(&(image->data[j]), &ptr[3*(int)offset], width);
|
||||
offset += a;
|
||||
}
|
||||
|
||||
RDestroyImage(tmp);
|
||||
return image;
|
||||
}
|
||||
|
||||
|
||||
static RImage*
|
||||
renderMHGradient(unsigned width, unsigned height, RColor **colors, int count)
|
||||
{
|
||||
int i, j, k;
|
||||
unsigned long r, g, b, dr, dg, db;
|
||||
RImage *image;
|
||||
unsigned char *ptr;
|
||||
unsigned width2;
|
||||
|
||||
|
||||
assert(count > 2);
|
||||
|
||||
image = RCreateImage(width, height, False);
|
||||
if (!image) {
|
||||
return NULL;
|
||||
}
|
||||
ptr = image->data;
|
||||
|
||||
if (count > width)
|
||||
count = width;
|
||||
|
||||
if (count > 1)
|
||||
width2 = width/(count-1);
|
||||
else
|
||||
width2 = width;
|
||||
|
||||
k = 0;
|
||||
|
||||
r = colors[0]->red << 16;
|
||||
g = colors[0]->green << 16;
|
||||
b = colors[0]->blue << 16;
|
||||
|
||||
/* render the first line */
|
||||
for (i=1; i<count; i++) {
|
||||
dr = ((int)(colors[i]->red - colors[i-1]->red) <<16)/(int)width2;
|
||||
dg = ((int)(colors[i]->green - colors[i-1]->green)<<16)/(int)width2;
|
||||
db = ((int)(colors[i]->blue - colors[i-1]->blue) <<16)/(int)width2;
|
||||
for (j=0; j<width2; j++) {
|
||||
*ptr++ = (unsigned char)(r>>16);
|
||||
*ptr++ = (unsigned char)(g>>16);
|
||||
*ptr++ = (unsigned char)(b>>16);
|
||||
r += dr;
|
||||
g += dg;
|
||||
b += db;
|
||||
k++;
|
||||
}
|
||||
r = colors[i]->red << 16;
|
||||
g = colors[i]->green << 16;
|
||||
b = colors[i]->blue << 16;
|
||||
}
|
||||
for (j=k; j<width; j++) {
|
||||
*ptr++ = (unsigned char)(r>>16);
|
||||
*ptr++ = (unsigned char)(g>>16);
|
||||
*ptr++ = (unsigned char)(b>>16);
|
||||
}
|
||||
|
||||
/* copy the first line to the other lines */
|
||||
for (i=1; i<height; i++) {
|
||||
memcpy(&(image->data[i*width*3]), image->data, width*3);
|
||||
}
|
||||
return image;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
static RImage*
|
||||
renderMVGradient(unsigned width, unsigned height, RColor **colors, int count)
|
||||
{
|
||||
int i, j, k;
|
||||
unsigned long r, g, b, dr, dg, db;
|
||||
RImage *image;
|
||||
unsigned char *ptr, *tmp;
|
||||
unsigned height2;
|
||||
int x;
|
||||
unsigned char rr, gg, bb;
|
||||
|
||||
|
||||
assert(count > 2);
|
||||
|
||||
image = RCreateImage(width, height, False);
|
||||
if (!image) {
|
||||
return NULL;
|
||||
}
|
||||
ptr = image->data;
|
||||
|
||||
if (count > height)
|
||||
count = height;
|
||||
|
||||
if (count > 1)
|
||||
height2 = height/(count-1);
|
||||
else
|
||||
height2 = height;
|
||||
|
||||
k = 0;
|
||||
|
||||
r = colors[0]->red << 16;
|
||||
g = colors[0]->green << 16;
|
||||
b = colors[0]->blue << 16;
|
||||
|
||||
for (i=1; i<count; i++) {
|
||||
dr = ((int)(colors[i]->red - colors[i-1]->red) <<16)/(int)height2;
|
||||
dg = ((int)(colors[i]->green - colors[i-1]->green)<<16)/(int)height2;
|
||||
db = ((int)(colors[i]->blue - colors[i-1]->blue) <<16)/(int)height2;
|
||||
|
||||
for (j=0; j<height2; j++) {
|
||||
rr = r>>16;
|
||||
gg = g>>16;
|
||||
bb = b>>16;
|
||||
|
||||
for (x=0; x<width/4; x++) {
|
||||
*ptr++ = rr; *ptr++ = gg; *ptr++ = bb;
|
||||
*ptr++ = rr; *ptr++ = gg; *ptr++ = bb;
|
||||
*ptr++ = rr; *ptr++ = gg; *ptr++ = bb;
|
||||
*ptr++ = rr; *ptr++ = gg; *ptr++ = bb;
|
||||
}
|
||||
switch (width%4) {
|
||||
case 3: *ptr++ = rr; *ptr++ = gg; *ptr++ = bb;
|
||||
case 2: *ptr++ = rr; *ptr++ = gg; *ptr++ = bb;
|
||||
case 1: *ptr++ = rr; *ptr++ = gg; *ptr++ = bb;
|
||||
}
|
||||
r += dr;
|
||||
g += dg;
|
||||
b += db;
|
||||
k++;
|
||||
}
|
||||
r = colors[i]->red << 16;
|
||||
g = colors[i]->green << 16;
|
||||
b = colors[i]->blue << 16;
|
||||
}
|
||||
|
||||
rr = r>>16;
|
||||
gg = g>>16;
|
||||
bb = b>>16;
|
||||
|
||||
if (k<height) {
|
||||
tmp = ptr;
|
||||
for (x=0; x<width/4; x++) {
|
||||
*ptr++ = rr; *ptr++ = gg; *ptr++ = bb;
|
||||
*ptr++ = rr; *ptr++ = gg; *ptr++ = bb;
|
||||
*ptr++ = rr; *ptr++ = gg; *ptr++ = bb;
|
||||
*ptr++ = rr; *ptr++ = gg; *ptr++ = bb;
|
||||
}
|
||||
switch (width%4) {
|
||||
case 3: *ptr++ = rr; *ptr++ = gg; *ptr++ = bb;
|
||||
case 2: *ptr++ = rr; *ptr++ = gg; *ptr++ = bb;
|
||||
case 1: *ptr++ = rr; *ptr++ = gg; *ptr++ = bb;
|
||||
default: break;
|
||||
}
|
||||
|
||||
for (j=k+1; j<height; j++) {
|
||||
memcpy(ptr, tmp, width*3);
|
||||
ptr += width*3;
|
||||
}
|
||||
}
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
|
||||
static RImage*
|
||||
renderMDGradient(unsigned width, unsigned height, RColor **colors, int count)
|
||||
{
|
||||
RImage *image, *tmp;
|
||||
float a, offset;
|
||||
int j;
|
||||
unsigned char *ptr;
|
||||
|
||||
assert(count > 2);
|
||||
|
||||
if (width == 1)
|
||||
return renderMVGradient(width, height, colors, count);
|
||||
else if (height == 1)
|
||||
return renderMHGradient(width, height, colors, count);
|
||||
|
||||
image = RCreateImage(width, height, False);
|
||||
if (!image) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (count > width)
|
||||
count = width;
|
||||
if (count > height)
|
||||
count = height;
|
||||
|
||||
if (count > 2)
|
||||
tmp = renderMHGradient(2*width-1, 1, colors, count);
|
||||
else
|
||||
tmp = renderHGradient(2*width-1, 1, colors[0]->red<<8,
|
||||
colors[0]->green<<8, colors[0]->blue<<8,
|
||||
colors[1]->red<<8, colors[1]->green<<8,
|
||||
colors[1]->blue<<8);
|
||||
|
||||
if (!tmp) {
|
||||
RDestroyImage(image);
|
||||
return NULL;
|
||||
}
|
||||
ptr = tmp->data;
|
||||
|
||||
a = ((float)(width - 1))/((float)(height - 1));
|
||||
width = width * 3;
|
||||
|
||||
/* copy the first line to the other lines with corresponding offset */
|
||||
for (j=0, offset=0; j<width*height; j += width) {
|
||||
memcpy(&(image->data[j]), &ptr[3*(int)offset], width);
|
||||
offset += a;
|
||||
}
|
||||
RDestroyImage(tmp);
|
||||
return image;
|
||||
}
|
221
Source/x11/misc.c
Normal file
221
Source/x11/misc.c
Normal file
|
@ -0,0 +1,221 @@
|
|||
/*
|
||||
* Raster graphics library
|
||||
*
|
||||
* Copyright (c) 1997-2000 Alfredo K. Kojima
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free
|
||||
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
#include <config.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <X11/Xlib.h>
|
||||
|
||||
#include "xrtools.h"
|
||||
|
||||
|
||||
void
|
||||
RBevelImage(RImage *image, int bevel_type)
|
||||
{
|
||||
RColor color;
|
||||
RColor cdelta;
|
||||
int w, h;
|
||||
|
||||
if (image->width<3 || image->height<3)
|
||||
return;
|
||||
|
||||
w = image->width;
|
||||
h = image->height;
|
||||
if (bevel_type>0) { /* raised */
|
||||
/* top */
|
||||
cdelta.alpha = 0;
|
||||
cdelta.red = cdelta.green = cdelta.blue = 80;
|
||||
ROperateLine(image, RAddOperation, 0, 0, w-1, 0, &cdelta);
|
||||
if (bevel_type==RBEV_RAISED3 && w>3)
|
||||
ROperateLine(image, RAddOperation, 1, 1, w-3, 1,&cdelta);
|
||||
|
||||
/* left */
|
||||
ROperateLine(image, RAddOperation, 0, 1, 0, h-1, &cdelta);
|
||||
if (bevel_type==RBEV_RAISED3 && h>3)
|
||||
ROperateLine(image, RAddOperation, 1, 2, 1, h-3, &cdelta);
|
||||
|
||||
/* bottom */
|
||||
color.alpha = 255;
|
||||
color.red = color.green = color.blue = 0;
|
||||
cdelta.red = cdelta.green = cdelta.blue = 40;
|
||||
if (bevel_type==RBEV_RAISED2 || bevel_type==RBEV_RAISED3) {
|
||||
ROperateLine(image, RSubtractOperation, 0, h-2, w-3,
|
||||
h-2, &cdelta);
|
||||
RDrawLine(image, 0, h-1, w-1, h-1, &color);
|
||||
} else {
|
||||
ROperateLine(image, RSubtractOperation, 0, h-1, w-1, h-1,
|
||||
&cdelta);
|
||||
}
|
||||
|
||||
/* right */
|
||||
if (bevel_type==RBEV_RAISED2 || bevel_type==RBEV_RAISED3) {
|
||||
ROperateLine(image, RSubtractOperation, w-2, 0, w-2, h-2,
|
||||
&cdelta);
|
||||
RDrawLine(image, w-1, 0, w-1, h-2, &color);
|
||||
} else {
|
||||
ROperateLine(image, RSubtractOperation, w-1, 0, w-1, h-2,
|
||||
&cdelta);
|
||||
}
|
||||
} else { /* sunken */
|
||||
cdelta.alpha = 0;
|
||||
cdelta.red = cdelta.green = cdelta.blue = 40;
|
||||
ROperateLine(image, RSubtractOperation, 0, 0, w-1, 0,
|
||||
&cdelta); /* top */
|
||||
ROperateLine(image, RSubtractOperation, 0, 1, 0, h-1,
|
||||
&cdelta); /* left */
|
||||
cdelta.red = cdelta.green = cdelta.blue = 80;
|
||||
ROperateLine(image, RAddOperation, 0, h-1, w-1, h-1, &cdelta); /* bottom */
|
||||
ROperateLine(image, RAddOperation, w-1, 0, w-1, h-2, &cdelta); /* right */
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
RClearImage(RImage *image, RColor *color)
|
||||
{
|
||||
if (image->format == RRGBAFormat) {
|
||||
unsigned char *d = image->data;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < image->width; i++) {
|
||||
*d++ = color->red;
|
||||
*d++ = color->green;
|
||||
*d++ = color->blue;
|
||||
*d++ = color->alpha;
|
||||
}
|
||||
for (i = 1; i < image->height; i++, d += image->width*4) {
|
||||
memcpy(d, image->data, image->width*4);
|
||||
}
|
||||
} else {
|
||||
unsigned char *d = image->data;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < image->width; i++) {
|
||||
*d++ = color->red;
|
||||
*d++ = color->green;
|
||||
*d++ = color->blue;
|
||||
}
|
||||
for (i = 1; i < image->height; i++, d += image->width*3) {
|
||||
memcpy(d, image->data, image->width*3);
|
||||
}
|
||||
}
|
||||
#if 0
|
||||
if (color->alpha==255) {
|
||||
if (image->format == RRGBAFormat) {
|
||||
unsigned char *d = image->data;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < image->width; i++) {
|
||||
*d++ = color->red;
|
||||
*d++ = color->green;
|
||||
*d++ = color->blue;
|
||||
*d++ = 0xff;
|
||||
}
|
||||
for (i = 1; i < image->height; i++, d += image->width*4) {
|
||||
memcpy(d, image->data, image->width*4);
|
||||
}
|
||||
} else {
|
||||
unsigned char *d = image->data;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < image->width; i++) {
|
||||
*d++ = color->red;
|
||||
*d++ = color->green;
|
||||
*d++ = color->blue;
|
||||
}
|
||||
for (i = 1; i < image->height; i++, d += image->width*3) {
|
||||
memcpy(d, image->data, image->width*3);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
int bytes = image->width*image->height;
|
||||
int i;
|
||||
unsigned char *d;
|
||||
int alpha, nalpha, r, g, b;
|
||||
|
||||
d = image->data;
|
||||
|
||||
alpha = color->alpha;
|
||||
r = color->red * alpha;
|
||||
g = color->green * alpha;
|
||||
b = color->blue * alpha;
|
||||
nalpha = 255 - alpha;
|
||||
|
||||
for (i=0; i<bytes; i++) {
|
||||
*d = (((int)*d * nalpha) + r)/256;
|
||||
d++;
|
||||
*d = (((int)*d * nalpha) + g)/256;
|
||||
d++;
|
||||
*d = (((int)*d * nalpha) + b)/256;
|
||||
d++;
|
||||
if (image->format == RRGBAFormat) {
|
||||
d++;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
const char*
|
||||
RMessageForError(int errorCode)
|
||||
{
|
||||
switch (errorCode) {
|
||||
case RERR_NONE:
|
||||
return "no error";
|
||||
|
||||
case RERR_OPEN:
|
||||
return "could not open file";
|
||||
|
||||
case RERR_READ:
|
||||
return "error reading from file";
|
||||
|
||||
case RERR_WRITE:
|
||||
return "error writing to file";
|
||||
|
||||
case RERR_NOMEMORY:
|
||||
return "out of memory";
|
||||
|
||||
case RERR_NOCOLOR:
|
||||
return "out of color cells";
|
||||
|
||||
case RERR_BADIMAGEFILE:
|
||||
return "invalid or corrupted image file";
|
||||
|
||||
case RERR_BADFORMAT:
|
||||
return "the image format in the file is not supported and can't be loaded";
|
||||
|
||||
case RERR_BADINDEX:
|
||||
return "image file does not contain requested image index";
|
||||
|
||||
case RERR_BADVISUALID:
|
||||
return "request for an invalid visual ID";
|
||||
|
||||
case RERR_STDCMAPFAIL:
|
||||
return "failed to create standard colormap";
|
||||
|
||||
case RERR_XERROR:
|
||||
return "internal X error";
|
||||
|
||||
default:
|
||||
case RERR_INTERNAL:
|
||||
return "internal error";
|
||||
}
|
||||
}
|
554
Source/x11/raster.c
Normal file
554
Source/x11/raster.c
Normal file
|
@ -0,0 +1,554 @@
|
|||
/* raster.c - main and other misc stuff
|
||||
*
|
||||
* Raster graphics library
|
||||
*
|
||||
* Copyright (c) 1997-2000 Alfredo K. Kojima
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free
|
||||
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <X11/Xlib.h>
|
||||
#include "xrtools.h"
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
|
||||
char *WRasterLibVersion="0.9";
|
||||
|
||||
int RErrorCode=RERR_NONE;
|
||||
|
||||
|
||||
#define HAS_ALPHA(I) ((I)->format == RRGBAFormat)
|
||||
|
||||
|
||||
RImage*
|
||||
RCreateImage(unsigned width, unsigned height, int alpha)
|
||||
{
|
||||
RImage *image=NULL;
|
||||
|
||||
assert(width>0 && height>0);
|
||||
|
||||
image = malloc(sizeof(RImage));
|
||||
if (!image) {
|
||||
RErrorCode = RERR_NOMEMORY;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memset(image, 0, sizeof(RImage));
|
||||
image->width = width;
|
||||
image->height = height;
|
||||
if (alpha) {
|
||||
image->format = RRGBAFormat;
|
||||
} else {
|
||||
image->format = RRGBFormat;
|
||||
}
|
||||
/* the +4 is to give extra bytes at the end of the buffer,
|
||||
* so that we can optimize image conversion for MMX(tm).. see convert.c
|
||||
*/
|
||||
image->data = malloc(width * height * (alpha ? 4 : 3) + 4);
|
||||
if (!image->data) {
|
||||
RErrorCode = RERR_NOMEMORY;
|
||||
free(image);
|
||||
image = NULL;
|
||||
}
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
|
||||
|
||||
RImage*
|
||||
RCloneImage(RImage *image)
|
||||
{
|
||||
RImage *new_image;
|
||||
|
||||
assert(image!=NULL);
|
||||
|
||||
new_image = RCreateImage(image->width, image->height, HAS_ALPHA(image));
|
||||
if (!new_image)
|
||||
return NULL;
|
||||
|
||||
new_image->background = image->background;
|
||||
memcpy(new_image->data, image->data,
|
||||
image->width*image->height*(HAS_ALPHA(image) ? 4 : 3));
|
||||
|
||||
return new_image;
|
||||
}
|
||||
|
||||
|
||||
RImage*
|
||||
RGetSubImage(RImage *image, int x, int y, unsigned width, unsigned height)
|
||||
{
|
||||
int i, ofs;
|
||||
RImage *new_image;
|
||||
unsigned total_line_size, line_size;
|
||||
|
||||
assert(image!=NULL);
|
||||
assert(x>=0 && y>=0);
|
||||
assert(x<image->width && y<image->height);
|
||||
assert(width>0 && height>0);
|
||||
|
||||
if (x+width > image->width)
|
||||
width = image->width-x;
|
||||
if (y+height > image->height)
|
||||
height = image->height-y;
|
||||
|
||||
new_image = RCreateImage(width, height, HAS_ALPHA(image));
|
||||
|
||||
if (!new_image)
|
||||
return NULL;
|
||||
new_image->background = image->background;
|
||||
|
||||
total_line_size = image->width * (HAS_ALPHA(image) ? 4 : 3);
|
||||
line_size = width * (HAS_ALPHA(image) ? 4 : 3);
|
||||
|
||||
ofs = x*(HAS_ALPHA(image) ? 4 : 3) + y*total_line_size;;
|
||||
|
||||
for (i=0; i<height; i++) {
|
||||
memcpy(&new_image->data[i*line_size],
|
||||
&image->data[i*total_line_size+ofs], line_size);
|
||||
}
|
||||
return new_image;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
RDestroyImage(RImage *image)
|
||||
{
|
||||
assert(image!=NULL);
|
||||
|
||||
free(image->data);
|
||||
free(image);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*----------------------------------------------------------------------
|
||||
* RCombineImages-
|
||||
* Combines two equal sized images with alpha image. The second
|
||||
* image will be placed on top of the first one.
|
||||
*----------------------------------------------------------------------
|
||||
*/
|
||||
void
|
||||
RCombineImages(RImage *image, RImage *src)
|
||||
{
|
||||
assert(image->width == src->width);
|
||||
assert(image->height == src->height);
|
||||
|
||||
if (!HAS_ALPHA(src)) {
|
||||
if (!HAS_ALPHA(image)) {
|
||||
memcpy(image->data, src->data, image->height*image->width*3);
|
||||
} else {
|
||||
int x, y;
|
||||
unsigned char *d, *s;
|
||||
|
||||
d = image->data;
|
||||
s = src->data;
|
||||
for (y = 0; y < image->height; y++) {
|
||||
for (x = 0; x < image->width; x++) {
|
||||
*d++ = *s++;
|
||||
*d++ = *s++;
|
||||
*d++ = *s++;
|
||||
d++;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
register int i;
|
||||
unsigned char *d;
|
||||
unsigned char *s;
|
||||
int alpha, calpha;
|
||||
|
||||
d = image->data;
|
||||
s = src->data;
|
||||
|
||||
if (!HAS_ALPHA(image)) {
|
||||
for (i=0; i<image->height*image->width; i++) {
|
||||
alpha = *(s+3);
|
||||
calpha = 255 - alpha;
|
||||
*d = (((int)*d * calpha) + ((int)*s * alpha))/256;
|
||||
d++; s++;
|
||||
*d = (((int)*d * calpha) + ((int)*s * alpha))/256;
|
||||
d++; s++;
|
||||
*d = (((int)*d * calpha) + ((int)*s * alpha))/256;
|
||||
d++; s++;
|
||||
s++;
|
||||
}
|
||||
} else {
|
||||
for (i=0; i<image->height*image->width; i++) {
|
||||
alpha = *(s+3);
|
||||
calpha = 255 - alpha;
|
||||
*d = (((int)*d * calpha) + ((int)*s * alpha))/256;
|
||||
d++; s++;
|
||||
*d = (((int)*d * calpha) + ((int)*s * alpha))/256;
|
||||
d++; s++;
|
||||
*d = (((int)*d * calpha) + ((int)*s * alpha))/256;
|
||||
d++; s++;
|
||||
*d++ |= *s++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void
|
||||
RCombineImagesWithOpaqueness(RImage *image, RImage *src, int opaqueness)
|
||||
{
|
||||
register int i;
|
||||
unsigned char *d;
|
||||
unsigned char *s;
|
||||
int c_opaqueness;
|
||||
|
||||
assert(image->width == src->width);
|
||||
assert(image->height == src->height);
|
||||
|
||||
d = image->data;
|
||||
s = src->data;
|
||||
|
||||
c_opaqueness = 255 - opaqueness;
|
||||
#define OP opaqueness
|
||||
if (!HAS_ALPHA(src)) {
|
||||
int dalpha = HAS_ALPHA(image);
|
||||
#define COP c_opaqueness
|
||||
for (i=0; i < image->width*image->height; i++) {
|
||||
*d = (((int)*d *(int)COP) + ((int)*s *(int)OP))/256;
|
||||
d++; s++;
|
||||
*d = (((int)*d *(int)COP) + ((int)*s *(int)OP))/256;
|
||||
d++; s++;
|
||||
*d = (((int)*d *(int)COP) + ((int)*s *(int)OP))/256;
|
||||
d++; s++;
|
||||
if (dalpha) {
|
||||
d++;
|
||||
}
|
||||
}
|
||||
#undef COP
|
||||
} else {
|
||||
int tmp;
|
||||
|
||||
if (!HAS_ALPHA(image)) {
|
||||
for (i=0; i<image->width*image->height; i++) {
|
||||
tmp = (*(s+3) * opaqueness)/256;
|
||||
*d = (((int)*d * (255-tmp)) + ((int)*s * tmp))/256;
|
||||
d++; s++;
|
||||
*d = (((int)*d * (255-tmp)) + ((int)*s * tmp))/256;
|
||||
d++; s++;
|
||||
*d = (((int)*d * (255-tmp)) + ((int)*s * tmp))/256;
|
||||
d++; s++;
|
||||
s++;
|
||||
}
|
||||
} else {
|
||||
for (i=0; i<image->width*image->height; i++) {
|
||||
tmp = (*(s+3) * opaqueness)/256;
|
||||
*d = (((int)*d * (255-tmp)) + ((int)*s * tmp))/256;
|
||||
d++; s++;
|
||||
*d = (((int)*d * (255-tmp)) + ((int)*s * tmp))/256;
|
||||
d++; s++;
|
||||
*d = (((int)*d * (255-tmp)) + ((int)*s * tmp))/256;
|
||||
d++; s++;
|
||||
*d |= tmp;
|
||||
d++; s++;
|
||||
}
|
||||
}
|
||||
}
|
||||
#undef OP
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
RCombineArea(RImage *image, RImage *src, int sx, int sy, unsigned width,
|
||||
unsigned height, int dx, int dy)
|
||||
{
|
||||
int x, y, dwi, swi;
|
||||
unsigned char *d;
|
||||
unsigned char *s;
|
||||
int alpha, calpha;
|
||||
|
||||
|
||||
assert(dy < image->height);
|
||||
assert(dx < image->width);
|
||||
|
||||
assert(sy + height <= src->height);
|
||||
assert(sx + width <= src->width);
|
||||
|
||||
if (width > image->width - dx)
|
||||
width = image->width - dx;
|
||||
|
||||
if (height > image->height - dy)
|
||||
height = image->height - dy;
|
||||
|
||||
if (!HAS_ALPHA(src)) {
|
||||
if (!HAS_ALPHA(image)) {
|
||||
swi = src->width * 3;
|
||||
dwi = image->width * 3;
|
||||
|
||||
s = src->data + (sy*(int)src->width + sx) * 3;
|
||||
d = image->data + (dy*(int)image->width + dx) * 3;
|
||||
|
||||
for (y=0; y < height; y++) {
|
||||
memcpy(d, s, width*3);
|
||||
d += dwi;
|
||||
s += swi;
|
||||
}
|
||||
} else {
|
||||
swi = (src->width - width) * 3;
|
||||
dwi = (image->width - width) * 4;
|
||||
|
||||
s = src->data + (sy*(int)src->width + sx) * 3;
|
||||
d = image->data + (dy*(int)image->width + dx) * 4;
|
||||
|
||||
for (y=0; y < height; y++) {
|
||||
for (x=0; x < width; x++) {
|
||||
*d++ = *s++;
|
||||
*d++ = *s++;
|
||||
*d++ = *s++;
|
||||
d++;
|
||||
}
|
||||
d += dwi;
|
||||
s += swi;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
int dalpha = HAS_ALPHA(image);
|
||||
|
||||
swi = (src->width - width) * 4;
|
||||
s = src->data + (sy*(int)src->width + sx) * 4;
|
||||
if (dalpha) {
|
||||
dwi = (image->width - width) * 4;
|
||||
d = image->data + (dy*(int)image->width + dx) * 4;
|
||||
} else {
|
||||
dwi = (image->width - width) * 3;
|
||||
d = image->data + (dy*(int)image->width + dx) * 3;
|
||||
}
|
||||
|
||||
for (y=0; y < height; y++) {
|
||||
for (x=0; x < width; x++) {
|
||||
alpha = *(s+3);
|
||||
calpha = 255 - alpha;
|
||||
*d = (((int)*d * calpha) + ((int)*s * alpha))/256;
|
||||
s++; d++;
|
||||
*d = (((int)*d * calpha) + ((int)*s * alpha))/256;
|
||||
s++; d++;
|
||||
*d = (((int)*d * calpha) + ((int)*s * alpha))/256;
|
||||
s++; d++;
|
||||
s++;
|
||||
if (dalpha)
|
||||
d++;
|
||||
}
|
||||
d += dwi;
|
||||
s += swi;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
RCombineAreaWithOpaqueness(RImage *image, RImage *src, int sx, int sy,
|
||||
unsigned width, unsigned height, int dx, int dy,
|
||||
int opaqueness)
|
||||
{
|
||||
int x, y, dwi, swi;
|
||||
int c_opaqueness;
|
||||
unsigned char *d;
|
||||
unsigned char *s;
|
||||
int dalpha = HAS_ALPHA(image);
|
||||
int dch = (dalpha ? 4 : 3);
|
||||
|
||||
assert(dy <= image->height);
|
||||
assert(dx <= image->width);
|
||||
|
||||
assert(sy <= height);
|
||||
assert(sx <= width);
|
||||
|
||||
|
||||
/* clip */
|
||||
width -= sx;
|
||||
height -= sy;
|
||||
|
||||
if (height > image->height - dy)
|
||||
height = image->height - dy;
|
||||
|
||||
d = image->data + dy*image->width*dch + dx;
|
||||
dwi = (image->width - width)*dch;
|
||||
|
||||
c_opaqueness = 255 - opaqueness;
|
||||
#define OP opaqueness
|
||||
if (!HAS_ALPHA(src)) {
|
||||
#define COP c_opaqueness
|
||||
|
||||
s = src->data + sy*src->width*3;
|
||||
swi = (src->width - width) * 3;
|
||||
|
||||
for (y=0; y < height; y++) {
|
||||
for (x=0; x < width; x++) {
|
||||
*d = (((int)*d *(int)COP) + ((int)*s *(int)OP))/256;
|
||||
s++; d++;
|
||||
*d = (((int)*d *(int)COP) + ((int)*s *(int)OP))/256;
|
||||
s++; d++;
|
||||
*d = (((int)*d *(int)COP) + ((int)*s *(int)OP))/256;
|
||||
s++; d++;
|
||||
if (dalpha)
|
||||
d++;
|
||||
}
|
||||
d += dwi; s += swi;
|
||||
}
|
||||
#undef COP
|
||||
} else {
|
||||
int tmp;
|
||||
|
||||
s = src->data + sy*src->width*4;
|
||||
swi = (src->width - width) * 4;
|
||||
|
||||
for (y=0; y < height; y++) {
|
||||
for (x=0; x < width; x++) {
|
||||
tmp= (*(s+3) * opaqueness)/256;
|
||||
*d = (((int)*d *(int)(255-tmp)) + ((int)*s *(int)tmp))/256;
|
||||
d++; s++;
|
||||
*d = (((int)*d *(int)(255-tmp)) + ((int)*s *(int)tmp))/256;
|
||||
d++; s++;
|
||||
*d = (((int)*d *(int)(255-tmp)) + ((int)*s *(int)tmp))/256;
|
||||
d++; s++;
|
||||
s++;
|
||||
if (dalpha)
|
||||
d++;
|
||||
}
|
||||
d += dwi; s += swi;
|
||||
}
|
||||
}
|
||||
#undef OP
|
||||
}
|
||||
|
||||
|
||||
|
||||
void
|
||||
RCombineImageWithColor(RImage *image, RColor *color)
|
||||
{
|
||||
register int i;
|
||||
unsigned char *d;
|
||||
int alpha, nalpha, r, g, b;
|
||||
|
||||
d = image->data;
|
||||
|
||||
if (!HAS_ALPHA(image)) {
|
||||
/* Image has no alpha channel, so we consider it to be all 255.
|
||||
* Thus there are no transparent parts to be filled. */
|
||||
return;
|
||||
}
|
||||
r = color->red;
|
||||
g = color->green;
|
||||
b = color->blue;
|
||||
|
||||
for (i=0; i < image->width*image->height; i++) {
|
||||
alpha = *(d+3);
|
||||
nalpha = 255 - alpha;
|
||||
|
||||
*d = (((int)*d * alpha) + (r * nalpha))/256;
|
||||
d++;
|
||||
*d = (((int)*d * alpha) + (g * nalpha))/256;
|
||||
d++;
|
||||
*d = (((int)*d * alpha) + (b * nalpha))/256;
|
||||
d++;
|
||||
d++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
RImage*
|
||||
RMakeTiledImage(RImage *tile, unsigned width, unsigned height)
|
||||
{
|
||||
int x, y;
|
||||
unsigned w;
|
||||
unsigned long tile_size = tile->width * tile->height;
|
||||
unsigned long tx = 0;
|
||||
RImage *image;
|
||||
unsigned char *s, *d;
|
||||
|
||||
if (width == tile->width && height == tile->height)
|
||||
image = RCloneImage(tile);
|
||||
else if (width <= tile->width && height <= tile->height)
|
||||
image = RGetSubImage(tile, 0, 0, width, height);
|
||||
else {
|
||||
int has_alpha = HAS_ALPHA(tile);
|
||||
|
||||
image = RCreateImage(width, height, has_alpha);
|
||||
|
||||
d = image->data;
|
||||
s = tile->data;
|
||||
|
||||
for (y = 0; y < height; y++) {
|
||||
for (x = 0; x < width; x += tile->width) {
|
||||
|
||||
w = (width - x < tile->width) ? width - x : tile->width;
|
||||
|
||||
if (has_alpha) {
|
||||
w *= 4;
|
||||
memcpy(d, s+tx*4, w);
|
||||
} else {
|
||||
w *= 3;
|
||||
memcpy(d, s+tx*3, w);
|
||||
}
|
||||
d += w;
|
||||
}
|
||||
|
||||
tx = (tx + tile->width) % tile_size;
|
||||
}
|
||||
}
|
||||
return image;
|
||||
}
|
||||
|
||||
|
||||
RImage*
|
||||
RMakeCenteredImage(RImage *image, unsigned width, unsigned height, RColor *color)
|
||||
{
|
||||
int x, y, w, h, sx, sy;
|
||||
RImage *tmp;
|
||||
|
||||
tmp = RCreateImage(width, height, False);
|
||||
if (!tmp) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
RClearImage(tmp, color);
|
||||
|
||||
if (image->height < height) {
|
||||
h = image->height;
|
||||
y = (height - h)/2;
|
||||
sy = 0;
|
||||
} else {
|
||||
sy = (image->height - height)/2;
|
||||
y = 0;
|
||||
h = height;
|
||||
}
|
||||
if (image->width < width) {
|
||||
w = image->width;
|
||||
x = (width - w)/2;
|
||||
sx = 0;
|
||||
} else {
|
||||
sx = (image->width - width)/2;
|
||||
x = 0;
|
||||
w = width;
|
||||
}
|
||||
RCombineArea(tmp, image, sx, sy, w, h, x, y);
|
||||
|
||||
return tmp;
|
||||
}
|
623
Source/x11/scale.c
Normal file
623
Source/x11/scale.c
Normal file
|
@ -0,0 +1,623 @@
|
|||
/* scale.c - image scaling
|
||||
*
|
||||
* Raster graphics library
|
||||
*
|
||||
* Copyright (c) 1997, 1988, 1999 Alfredo K. Kojima
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free
|
||||
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <X11/Xlib.h>
|
||||
#include <math.h>
|
||||
|
||||
#ifndef PI
|
||||
#define PI 3.141592
|
||||
#endif
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include "xrtools.h"
|
||||
|
||||
|
||||
/*
|
||||
*----------------------------------------------------------------------
|
||||
* RScaleImage--
|
||||
* Creates a scaled copy of an image.
|
||||
*
|
||||
* Returns:
|
||||
* The new scaled image.
|
||||
*
|
||||
*----------------------------------------------------------------------
|
||||
*/
|
||||
#ifndef broken_code
|
||||
RImage*
|
||||
RScaleImage(RImage *image, unsigned new_width, unsigned new_height)
|
||||
{
|
||||
int ox;
|
||||
int px, py;
|
||||
register int x, y, t;
|
||||
int dx, dy;
|
||||
unsigned char *s;
|
||||
unsigned char *d;
|
||||
RImage *img;
|
||||
|
||||
assert(new_width >= 0 && new_height >= 0);
|
||||
|
||||
if (new_width == image->width && new_height == image->height)
|
||||
return RCloneImage(image);
|
||||
|
||||
img = RCreateImage(new_width, new_height, image->format==RRGBAFormat);
|
||||
|
||||
if (!img)
|
||||
return NULL;
|
||||
|
||||
/* fixed point math idea taken from Imlib by
|
||||
* Carsten Haitzler (Rasterman) */
|
||||
dx = (image->width<<16)/new_width;
|
||||
dy = (image->height<<16)/new_height;
|
||||
|
||||
py = 0;
|
||||
|
||||
d = img->data;
|
||||
|
||||
if (image->format == RRGBAFormat) {
|
||||
for (y=0; y<new_height; y++) {
|
||||
t = image->width*(py>>16);
|
||||
|
||||
s = image->data+(t<<2); /* image->data+t*4 */
|
||||
|
||||
ox = 0;
|
||||
px = 0;
|
||||
for (x=0; x<new_width; x++) {
|
||||
px += dx;
|
||||
|
||||
*(d++) = *(s);
|
||||
*(d++) = *(s+1);
|
||||
*(d++) = *(s+2);
|
||||
*(d++) = *(s+3);
|
||||
|
||||
t = (px - ox)>>16;
|
||||
ox += t<<16;
|
||||
|
||||
s += t<<2; /* t*4 */
|
||||
}
|
||||
py += dy;
|
||||
}
|
||||
} else {
|
||||
for (y=0; y<new_height; y++) {
|
||||
t = image->width*(py>>16);
|
||||
|
||||
s = image->data+(t<<1)+t; /* image->data+t*3 */
|
||||
|
||||
ox = 0;
|
||||
px = 0;
|
||||
for (x=0; x<new_width; x++) {
|
||||
px += dx;
|
||||
|
||||
*(d++) = *(s);
|
||||
*(d++) = *(s+1);
|
||||
*(d++) = *(s+2);
|
||||
|
||||
t = (px - ox)>>16;
|
||||
ox += t<<16;
|
||||
|
||||
s += (t<<1)+t; /* t*3 */
|
||||
}
|
||||
py += dy;
|
||||
}
|
||||
}
|
||||
|
||||
return img;
|
||||
}
|
||||
|
||||
#else
|
||||
RImage*
|
||||
RScaleImage(RImage *src, unsigned new_width, unsigned new_height)
|
||||
{
|
||||
int ddy, ee;
|
||||
int h2;
|
||||
int yd;
|
||||
int xd, xs;
|
||||
RImage *dst;
|
||||
int e, xd2;
|
||||
unsigned char *sr, *sg, *sb, *sa;
|
||||
unsigned char *dr, *dg, *db, *da;
|
||||
int ys = 0;
|
||||
|
||||
|
||||
|
||||
dst = RCreateImage(new_width, new_height, src->data[3]!=NULL);
|
||||
|
||||
ddy = src->height/2;
|
||||
ee = (ddy/2) - dst->height;
|
||||
h2 = new_height/2;
|
||||
|
||||
xd = dst->width;
|
||||
xs = src->width/2;
|
||||
e = (src->width/2)-xd;
|
||||
xd2 = xd/2;
|
||||
|
||||
sr = src->data[0];
|
||||
sg = src->data[1];
|
||||
sb = src->data[2];
|
||||
sa = src->data[3];
|
||||
|
||||
dr = dst->data[0];
|
||||
dg = dst->data[1];
|
||||
db = dst->data[2];
|
||||
da = dst->data[3];
|
||||
|
||||
if (sa == NULL) {
|
||||
for (yd = 0; yd < new_height; yd++) {
|
||||
int x;
|
||||
|
||||
sr = src->data[0] + ys * src->width;
|
||||
sg = src->data[1] + ys * src->width;
|
||||
sb = src->data[2] + ys * src->width;
|
||||
|
||||
for (x = 0; x < xd; x++) {
|
||||
*(dr++) = *sr;
|
||||
*(dg++) = *sg;
|
||||
*(db++) = *sb;
|
||||
|
||||
while (e >= 0) {
|
||||
sr++;
|
||||
sg++;
|
||||
sb++;
|
||||
e -= xd2;
|
||||
}
|
||||
e += xs;
|
||||
}
|
||||
while (ee >= 0) {
|
||||
ys++;
|
||||
ee -= h2;
|
||||
}
|
||||
ee += ddy;
|
||||
}
|
||||
} else {
|
||||
for (yd = 0; yd < new_height; yd++) {
|
||||
int x;
|
||||
|
||||
sr = src->data[0] + ys * src->width;
|
||||
sg = src->data[1] + ys * src->width;
|
||||
sb = src->data[2] + ys * src->width;
|
||||
sa = src->data[3] + ys * src->width;
|
||||
|
||||
for (x = 0; x < xd; x++) {
|
||||
*(dr++) = *sr;
|
||||
*(dg++) = *sg;
|
||||
*(db++) = *sb;
|
||||
*(da++) = *sa;
|
||||
|
||||
while (e >= 0) {
|
||||
sr++;
|
||||
sg++;
|
||||
sb++;
|
||||
sa++;
|
||||
e -= xd2;
|
||||
}
|
||||
e += xs;
|
||||
}
|
||||
while (ee >= 0) {
|
||||
ys++;
|
||||
ee -= h2;
|
||||
}
|
||||
ee += ddy;
|
||||
}
|
||||
}
|
||||
|
||||
return dst;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Filtered Image Rescaling code copy/pasted from
|
||||
* Graphics Gems III
|
||||
* Public Domain 1991 by Dale Schumacher
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* filter function definitions
|
||||
*/
|
||||
#if 0
|
||||
#define filter_support (1.0)
|
||||
|
||||
static double
|
||||
filter(t)
|
||||
double t;
|
||||
{
|
||||
/* f(t) = 2|t|^3 - 3|t|^2 + 1, -1 <= t <= 1 */
|
||||
if(t < 0.0) t = -t;
|
||||
if(t < 1.0) return((2.0 * t - 3.0) * t * t + 1.0);
|
||||
return(0.0);
|
||||
}
|
||||
#endif
|
||||
#define box_support (0.5)
|
||||
|
||||
static double
|
||||
box_filter(t)
|
||||
double t;
|
||||
{
|
||||
if((t > -0.5) && (t <= 0.5)) return(1.0);
|
||||
return(0.0);
|
||||
}
|
||||
|
||||
#define triangle_support (1.0)
|
||||
|
||||
static double
|
||||
triangle_filter(t)
|
||||
double t;
|
||||
{
|
||||
if(t < 0.0) t = -t;
|
||||
if(t < 1.0) return(1.0 - t);
|
||||
return(0.0);
|
||||
}
|
||||
|
||||
#define bell_support (1.5)
|
||||
|
||||
static double
|
||||
bell_filter(t) /* box (*) box (*) box */
|
||||
double t;
|
||||
{
|
||||
if(t < 0) t = -t;
|
||||
if(t < .5) return(.75 - (t * t));
|
||||
if(t < 1.5) {
|
||||
t = (t - 1.5);
|
||||
return(.5 * (t * t));
|
||||
}
|
||||
return(0.0);
|
||||
}
|
||||
|
||||
#define B_spline_support (2.0)
|
||||
|
||||
static double
|
||||
B_spline_filter(t) /* box (*) box (*) box (*) box */
|
||||
double t;
|
||||
{
|
||||
double tt;
|
||||
|
||||
if(t < 0) t = -t;
|
||||
if(t < 1) {
|
||||
tt = t * t;
|
||||
return((.5 * tt * t) - tt + (2.0 / 3.0));
|
||||
} else if(t < 2) {
|
||||
t = 2 - t;
|
||||
return((1.0 / 6.0) * (t * t * t));
|
||||
}
|
||||
return(0.0);
|
||||
}
|
||||
|
||||
static double
|
||||
sinc(x)
|
||||
double x;
|
||||
{
|
||||
x *= PI;
|
||||
if(x != 0) return(sin(x) / x);
|
||||
return(1.0);
|
||||
}
|
||||
|
||||
#define Lanczos3_support (3.0)
|
||||
|
||||
static double
|
||||
Lanczos3_filter(t)
|
||||
double t;
|
||||
{
|
||||
if(t < 0) t = -t;
|
||||
if(t < 3.0) return(sinc(t) * sinc(t/3.0));
|
||||
return(0.0);
|
||||
}
|
||||
|
||||
#define Mitchell_support (2.0)
|
||||
|
||||
#define B (1.0 / 3.0)
|
||||
#define C (1.0 / 3.0)
|
||||
|
||||
static double
|
||||
Mitchell_filter(t)
|
||||
double t;
|
||||
{
|
||||
double tt;
|
||||
|
||||
tt = t * t;
|
||||
if(t < 0) t = -t;
|
||||
if(t < 1.0) {
|
||||
t = (((12.0 - 9.0 * B - 6.0 * C) * (t * tt))
|
||||
+ ((-18.0 + 12.0 * B + 6.0 * C) * tt)
|
||||
+ (6.0 - 2 * B));
|
||||
return(t / 6.0);
|
||||
} else if(t < 2.0) {
|
||||
t = (((-1.0 * B - 6.0 * C) * (t * tt))
|
||||
+ ((6.0 * B + 30.0 * C) * tt)
|
||||
+ ((-12.0 * B - 48.0 * C) * t)
|
||||
+ (8.0 * B + 24 * C));
|
||||
return(t / 6.0);
|
||||
}
|
||||
return(0.0);
|
||||
}
|
||||
|
||||
static double (*filterf)() = Mitchell_filter;
|
||||
static double fwidth = Mitchell_support;
|
||||
|
||||
void
|
||||
_wraster_change_filter(int type)
|
||||
{
|
||||
switch (type) {
|
||||
case RBoxFilter:
|
||||
filterf = box_filter;
|
||||
fwidth = box_support;
|
||||
break;
|
||||
case RTriangleFilter:
|
||||
filterf = triangle_filter;
|
||||
fwidth = triangle_support;
|
||||
break;
|
||||
case RBellFilter:
|
||||
filterf = bell_filter;
|
||||
fwidth = bell_support;
|
||||
break;
|
||||
case RBSplineFilter:
|
||||
filterf = B_spline_filter;
|
||||
fwidth = B_spline_support;
|
||||
break;
|
||||
case RLanczos3Filter:
|
||||
filterf = Lanczos3_filter;
|
||||
fwidth = Lanczos3_support;
|
||||
break;
|
||||
default:
|
||||
case RMitchellFilter:
|
||||
filterf = Mitchell_filter;
|
||||
fwidth = Mitchell_support;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* image rescaling routine
|
||||
*/
|
||||
|
||||
typedef struct {
|
||||
int pixel;
|
||||
double weight;
|
||||
} CONTRIB;
|
||||
|
||||
typedef struct {
|
||||
int n; /* number of contributors */
|
||||
CONTRIB *p; /* pointer to list of contributions */
|
||||
} CLIST;
|
||||
|
||||
CLIST *contrib; /* array of contribution lists */
|
||||
|
||||
/* clamp the input to the specified range */
|
||||
#define CLAMP(v,l,h) ((v)<(l) ? (l) : (v) > (h) ? (h) : v)
|
||||
|
||||
|
||||
RImage*
|
||||
RSmoothScaleImage(RImage *src, unsigned new_width, unsigned new_height)
|
||||
{
|
||||
RImage *tmp; /* intermediate image */
|
||||
double xscale, yscale; /* zoom scale factors */
|
||||
int i, j, k; /* loop variables */
|
||||
int n; /* pixel number */
|
||||
double center, left, right; /* filter calculation variables */
|
||||
double width, fscale; /* filter calculation variables */
|
||||
double rweight, gweight, bweight;
|
||||
RImage *dst;
|
||||
unsigned char *p;
|
||||
unsigned char *sp;
|
||||
int sch = src->format == RRGBAFormat ? 4 : 3;
|
||||
|
||||
|
||||
dst = RCreateImage(new_width, new_height, False);
|
||||
|
||||
/* create intermediate image to hold horizontal zoom */
|
||||
tmp = RCreateImage(dst->width, src->height, False);
|
||||
xscale = (double)new_width / (double)src->width;
|
||||
yscale = (double)new_height / (double)src->height;
|
||||
|
||||
/* pre-calculate filter contributions for a row */
|
||||
contrib = (CLIST *)calloc(new_width, sizeof(CLIST));
|
||||
if (xscale < 1.0) {
|
||||
width = fwidth / xscale;
|
||||
fscale = 1.0 / xscale;
|
||||
for (i = 0; i < new_width; ++i) {
|
||||
contrib[i].n = 0;
|
||||
contrib[i].p = (CONTRIB *)calloc((int)(width * 2 + 1),
|
||||
sizeof(CONTRIB));
|
||||
center = (double) i / xscale;
|
||||
left = ceil(center - width);
|
||||
right = floor(center + width);
|
||||
for(j = left; j <= right; ++j) {
|
||||
rweight = center - (double) j;
|
||||
rweight = (*filterf)(rweight / fscale) / fscale;
|
||||
if(j < 0) {
|
||||
n = -j;
|
||||
} else if(j >= src->width) {
|
||||
n = (src->width - j) + src->width - 1;
|
||||
} else {
|
||||
n = j;
|
||||
}
|
||||
k = contrib[i].n++;
|
||||
contrib[i].p[k].pixel = n*sch;
|
||||
contrib[i].p[k].weight = rweight;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
for(i = 0; i < new_width; ++i) {
|
||||
contrib[i].n = 0;
|
||||
contrib[i].p = (CONTRIB *)calloc((int) (fwidth * 2 + 1),
|
||||
sizeof(CONTRIB));
|
||||
center = (double) i / xscale;
|
||||
left = ceil(center - fwidth);
|
||||
right = floor(center + fwidth);
|
||||
for(j = left; j <= right; ++j) {
|
||||
rweight = center - (double) j;
|
||||
rweight = (*filterf)(rweight);
|
||||
if(j < 0) {
|
||||
n = -j;
|
||||
} else if(j >= src->width) {
|
||||
n = (src->width - j) + src->width - 1;
|
||||
} else {
|
||||
n = j;
|
||||
}
|
||||
k = contrib[i].n++;
|
||||
contrib[i].p[k].pixel = n*sch;
|
||||
contrib[i].p[k].weight = rweight;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* apply filter to zoom horizontally from src to tmp */
|
||||
p = tmp->data;
|
||||
|
||||
|
||||
for(k = 0; k < tmp->height; ++k) {
|
||||
CONTRIB *pp;
|
||||
|
||||
sp = src->data + src->width*k*sch;
|
||||
|
||||
for(i = 0; i < tmp->width; ++i) {
|
||||
rweight = gweight = bweight = 0.0;
|
||||
|
||||
pp = contrib[i].p;
|
||||
|
||||
for(j = 0; j < contrib[i].n; ++j) {
|
||||
rweight += sp[pp[j].pixel] * pp[j].weight;
|
||||
gweight += sp[pp[j].pixel+1] * pp[j].weight;
|
||||
bweight += sp[pp[j].pixel+2] * pp[j].weight;
|
||||
}
|
||||
*p++ = CLAMP(rweight, 0, 255);
|
||||
*p++ = CLAMP(gweight, 0, 255);
|
||||
*p++ = CLAMP(bweight, 0, 255);
|
||||
}
|
||||
}
|
||||
|
||||
/* free the memory allocated for horizontal filter weights */
|
||||
for(i = 0; i < tmp->width; ++i) {
|
||||
free(contrib[i].p);
|
||||
}
|
||||
free(contrib);
|
||||
|
||||
/* pre-calculate filter contributions for a column */
|
||||
contrib = (CLIST *)calloc(dst->height, sizeof(CLIST));
|
||||
if(yscale < 1.0) {
|
||||
width = fwidth / yscale;
|
||||
fscale = 1.0 / yscale;
|
||||
for(i = 0; i < dst->height; ++i) {
|
||||
contrib[i].n = 0;
|
||||
contrib[i].p = (CONTRIB *)calloc((int) (width * 2 + 1),
|
||||
sizeof(CONTRIB));
|
||||
center = (double) i / yscale;
|
||||
left = ceil(center - width);
|
||||
right = floor(center + width);
|
||||
for(j = left; j <= right; ++j) {
|
||||
rweight = center - (double) j;
|
||||
rweight = (*filterf)(rweight / fscale) / fscale;
|
||||
if(j < 0) {
|
||||
n = -j;
|
||||
} else if(j >= tmp->height) {
|
||||
n = (tmp->height - j) + tmp->height - 1;
|
||||
} else {
|
||||
n = j;
|
||||
}
|
||||
k = contrib[i].n++;
|
||||
contrib[i].p[k].pixel = n*3;
|
||||
contrib[i].p[k].weight = rweight;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for(i = 0; i < dst->height; ++i) {
|
||||
contrib[i].n = 0;
|
||||
contrib[i].p = (CONTRIB *)calloc((int) (fwidth * 2 + 1),
|
||||
sizeof(CONTRIB));
|
||||
center = (double) i / yscale;
|
||||
left = ceil(center - fwidth);
|
||||
right = floor(center + fwidth);
|
||||
for(j = left; j <= right; ++j) {
|
||||
rweight = center - (double) j;
|
||||
rweight = (*filterf)(rweight);
|
||||
if(j < 0) {
|
||||
n = -j;
|
||||
} else if(j >= tmp->height) {
|
||||
n = (tmp->height - j) + tmp->height - 1;
|
||||
} else {
|
||||
n = j;
|
||||
}
|
||||
k = contrib[i].n++;
|
||||
contrib[i].p[k].pixel = n*3;
|
||||
contrib[i].p[k].weight = rweight;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* apply filter to zoom vertically from tmp to dst */
|
||||
sp = malloc(tmp->height*3);
|
||||
|
||||
for(k = 0; k < new_width; ++k) {
|
||||
CONTRIB *pp;
|
||||
|
||||
p = dst->data + k*3;
|
||||
|
||||
/* copy a column into a row */
|
||||
{
|
||||
int i;
|
||||
unsigned char *p, *d;
|
||||
|
||||
d = sp;
|
||||
for(i = tmp->height, p = tmp->data + k*3; i-- > 0;
|
||||
p += tmp->width*3) {
|
||||
*d++ = *p;
|
||||
*d++ = *(p+1);
|
||||
*d++ = *(p+2);
|
||||
}
|
||||
}
|
||||
for(i = 0; i < new_height; ++i) {
|
||||
rweight = gweight = bweight = 0.0;
|
||||
|
||||
pp = contrib[i].p;
|
||||
|
||||
for(j = 0; j < contrib[i].n; ++j) {
|
||||
rweight += sp[pp[j].pixel] * pp[j].weight;
|
||||
gweight += sp[pp[j].pixel+1] * pp[j].weight;
|
||||
bweight += sp[pp[j].pixel+2] * pp[j].weight;
|
||||
}
|
||||
*p = CLAMP(rweight, 0, 255);
|
||||
*(p+1) = CLAMP(gweight, 0, 255);
|
||||
*(p+2) = CLAMP(bweight, 0, 255);
|
||||
p += new_width*3;
|
||||
}
|
||||
}
|
||||
free(sp);
|
||||
|
||||
/* free the memory allocated for vertical filter weights */
|
||||
for(i = 0; i < dst->height; ++i) {
|
||||
free(contrib[i].p);
|
||||
}
|
||||
free(contrib);
|
||||
|
||||
RDestroyImage(tmp);
|
||||
|
||||
return dst;
|
||||
}
|
||||
|
395
Source/x11/xdnd.c
Normal file
395
Source/x11/xdnd.c
Normal file
|
@ -0,0 +1,395 @@
|
|||
/*
|
||||
xdnd.c, xdnd.h - C program library for handling the Xdnd protocol
|
||||
|
||||
Copyright (C) 1998 Paul Sheer
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
|
||||
|
||||
http://www.cco.caltech.edu/~jafl/xdnd/
|
||||
|
||||
Further info can also be obtained by emailing the author at,
|
||||
psheer@obsidian.co.za
|
||||
|
||||
Released 1998-08-07
|
||||
*/
|
||||
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/X.h>
|
||||
#include <X11/Xatom.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include "x11/xdnd.h"
|
||||
|
||||
|
||||
// #define DND_DEBUG
|
||||
#define dnd_version_at_least(a,b) ((a) <= (b))
|
||||
|
||||
#ifdef DND_DEBUG
|
||||
#define dnd_debug(a,b...) printf("%s: %d: " a "\n", __FILE__, __LINE__ , ## b)
|
||||
#else
|
||||
|
||||
#ifdef NeXT_RUNTIME
|
||||
#define dnd_debug //
|
||||
#else /* !NeXT_RUNTIME */
|
||||
#define dnd_debug(a,b...)
|
||||
#endif /* NeXT_RUNTIME */
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
void
|
||||
xdnd_reset(DndClass * dnd)
|
||||
{
|
||||
dnd->stage = XDND_DROP_STAGE_IDLE;
|
||||
dnd->dragging_version = 0;
|
||||
dnd->internal_drag = 0;
|
||||
dnd->want_position = 0;
|
||||
dnd->ready_to_drop = 0;
|
||||
dnd->will_accept = 0;
|
||||
dnd->rectangle.x = dnd->rectangle.y = 0;
|
||||
dnd->rectangle.width = dnd->rectangle.height = 0;
|
||||
dnd->dropper_window = 0;
|
||||
dnd->dragger_window = 0;
|
||||
dnd->dragger_typelist = 0;
|
||||
dnd->desired_type = 0;
|
||||
dnd->time = 0;
|
||||
}
|
||||
|
||||
void
|
||||
xdnd_init(DndClass * dnd, Display * display)
|
||||
{
|
||||
memset (dnd, 0, sizeof (*dnd));
|
||||
|
||||
dnd->display = display;
|
||||
dnd->root_window = DefaultRootWindow (display);
|
||||
dnd->version = XDND_VERSION;
|
||||
dnd->XdndAware = XInternAtom (dnd->display, "XdndAware", False);
|
||||
dnd->XdndSelection = XInternAtom (dnd->display, "XdndSelection", False);
|
||||
dnd->XdndEnter = XInternAtom (dnd->display, "XdndEnter", False);
|
||||
dnd->XdndLeave = XInternAtom (dnd->display, "XdndLeave", False);
|
||||
dnd->XdndPosition = XInternAtom (dnd->display, "XdndPosition", False);
|
||||
dnd->XdndDrop = XInternAtom (dnd->display, "XdndDrop", False);
|
||||
dnd->XdndFinished = XInternAtom (dnd->display, "XdndFinished", False);
|
||||
dnd->XdndStatus = XInternAtom (dnd->display, "XdndStatus", False);
|
||||
dnd->XdndActionCopy = XInternAtom (dnd->display, "XdndActionCopy", False);
|
||||
dnd->XdndActionMove = XInternAtom (dnd->display, "XdndActionMove", False);
|
||||
dnd->XdndActionLink = XInternAtom (dnd->display, "XdndActionLink", False);
|
||||
dnd->XdndActionAsk = XInternAtom (dnd->display, "XdndActionAsk", False);
|
||||
dnd->XdndActionPrivate=XInternAtom(dnd->display,"XdndActionPrivate",False);
|
||||
dnd->XdndTypeList = XInternAtom (dnd->display, "XdndTypeList", False);
|
||||
dnd->XdndActionList = XInternAtom (dnd->display, "XdndActionList", False);
|
||||
dnd->XdndActionDescription = XInternAtom(dnd->display,
|
||||
"XdndActionDescription", False);
|
||||
xdnd_reset(dnd);
|
||||
}
|
||||
|
||||
static int
|
||||
array_length(Atom * a)
|
||||
{ // typelist is a null terminated array
|
||||
int n = 0;
|
||||
|
||||
while (a[n])
|
||||
n++;
|
||||
return n;
|
||||
}
|
||||
|
||||
void
|
||||
xdnd_set_dnd_aware (DndClass * dnd, Window window, Atom * typelist)
|
||||
{
|
||||
XChangeProperty (dnd->display, window, dnd->XdndAware, XA_ATOM, 32,
|
||||
PropModeReplace, (unsigned char *) &dnd->version, 1);
|
||||
if (typelist)
|
||||
{
|
||||
int n = array_length (typelist);
|
||||
if (n)
|
||||
XChangeProperty (dnd->display, window, dnd->XdndAware, XA_ATOM, 32,
|
||||
PropModeAppend, (unsigned char *) typelist, n);
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
xdnd_is_dnd_aware(DndClass *dnd, Window window, int *version, Atom *typelist)
|
||||
{
|
||||
Atom actual;
|
||||
int format;
|
||||
unsigned long count, remaining;
|
||||
unsigned char *data = 0;
|
||||
Atom *types, *t;
|
||||
int result = 1;
|
||||
|
||||
*version = 0;
|
||||
XGetWindowProperty (dnd->display, window, dnd->XdndAware,
|
||||
0, 0x8000000L, False, XA_ATOM, &actual, &format,
|
||||
&count, &remaining, &data);
|
||||
|
||||
if (actual != XA_ATOM || format != 32 || count == 0 || !data)
|
||||
{
|
||||
dnd_debug("XGetWindowProperty failed in xdnd_is_dnd_aware - XdndAware = %ld", dnd->XdndAware);
|
||||
if (data)
|
||||
XFree(data);
|
||||
return 0;
|
||||
}
|
||||
|
||||
types = (Atom *) data;
|
||||
*version = dnd->version < types[0] ? dnd->version : types[0]; // minimum
|
||||
dnd_debug ("Using XDND version %d", *version);
|
||||
if (count > 1)
|
||||
{
|
||||
result = 0;
|
||||
for (t = typelist; *t; t++)
|
||||
{
|
||||
int j;
|
||||
for (j = 1; j < count; j++)
|
||||
{
|
||||
if (types[j] == *t)
|
||||
{
|
||||
result = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (result)
|
||||
break;
|
||||
}
|
||||
}
|
||||
XFree(data);
|
||||
return result;
|
||||
}
|
||||
|
||||
void
|
||||
xdnd_send_enter(DndClass *dnd, Window window, Window from, Atom *typelist)
|
||||
{
|
||||
XEvent xevent;
|
||||
int n, i;
|
||||
|
||||
n = array_length (typelist);
|
||||
|
||||
memset(&xevent, 0, sizeof (xevent));
|
||||
|
||||
xevent.xany.type = ClientMessage;
|
||||
xevent.xany.display = dnd->display;
|
||||
xevent.xclient.window = window;
|
||||
xevent.xclient.message_type = dnd->XdndEnter;
|
||||
xevent.xclient.format = 32;
|
||||
|
||||
XDND_ENTER_SOURCE_WIN (&xevent) = from;
|
||||
XDND_ENTER_THREE_TYPES_SET (&xevent, n > XDND_THREE);
|
||||
XDND_ENTER_VERSION_SET (&xevent, dnd->version);
|
||||
for (i = 0; i < n && i < XDND_THREE; i++)
|
||||
{
|
||||
XDND_ENTER_TYPE (&xevent, i) = typelist[i];
|
||||
}
|
||||
|
||||
XSendEvent (dnd->display, window, 0, 0, &xevent);
|
||||
}
|
||||
|
||||
void
|
||||
xdnd_send_position(DndClass *dnd, Window window, Window from, Atom action,
|
||||
int x, int y, unsigned long time)
|
||||
{
|
||||
XEvent xevent;
|
||||
|
||||
memset (&xevent, 0, sizeof (xevent));
|
||||
|
||||
xevent.xany.type = ClientMessage;
|
||||
xevent.xany.display = dnd->display;
|
||||
xevent.xclient.window = window;
|
||||
xevent.xclient.message_type = dnd->XdndPosition;
|
||||
xevent.xclient.format = 32;
|
||||
|
||||
XDND_POSITION_SOURCE_WIN (&xevent) = from;
|
||||
XDND_POSITION_ROOT_SET (&xevent, x, y);
|
||||
if (dnd_version_at_least (dnd->dragging_version, 1))
|
||||
XDND_POSITION_TIME (&xevent) = time;
|
||||
if (dnd_version_at_least (dnd->dragging_version, 2))
|
||||
XDND_POSITION_ACTION (&xevent) = action;
|
||||
|
||||
XSendEvent (dnd->display, window, 0, 0, &xevent);
|
||||
}
|
||||
|
||||
void
|
||||
xdnd_send_status(DndClass *dnd, Window window, Window from, int will_accept,
|
||||
int want_position, int x, int y, int w, int h, Atom action)
|
||||
{
|
||||
XEvent xevent;
|
||||
|
||||
memset (&xevent, 0, sizeof (xevent));
|
||||
|
||||
xevent.xany.type = ClientMessage;
|
||||
xevent.xany.display = dnd->display;
|
||||
xevent.xclient.window = window;
|
||||
xevent.xclient.message_type = dnd->XdndStatus;
|
||||
xevent.xclient.format = 32;
|
||||
|
||||
XDND_STATUS_TARGET_WIN (&xevent) = from;
|
||||
XDND_STATUS_WILL_ACCEPT_SET (&xevent, will_accept);
|
||||
if (will_accept)
|
||||
XDND_STATUS_WANT_POSITION_SET (&xevent, want_position);
|
||||
if (want_position)
|
||||
XDND_STATUS_RECT_SET (&xevent, x, y, w, h);
|
||||
if (dnd_version_at_least (dnd->dragging_version, 2))
|
||||
if (will_accept)
|
||||
XDND_STATUS_ACTION (&xevent) = action;
|
||||
|
||||
XSendEvent (dnd->display, window, 0, 0, &xevent);
|
||||
}
|
||||
|
||||
void
|
||||
xdnd_send_leave(DndClass *dnd, Window window, Window from)
|
||||
{
|
||||
XEvent xevent;
|
||||
|
||||
memset(&xevent, 0, sizeof (xevent));
|
||||
|
||||
xevent.xany.type = ClientMessage;
|
||||
xevent.xany.display = dnd->display;
|
||||
xevent.xclient.window = window;
|
||||
xevent.xclient.message_type = dnd->XdndLeave;
|
||||
xevent.xclient.format = 32;
|
||||
|
||||
XDND_LEAVE_SOURCE_WIN (&xevent) = from;
|
||||
|
||||
XSendEvent (dnd->display, window, 0, 0, &xevent);
|
||||
}
|
||||
|
||||
void
|
||||
xdnd_send_drop(DndClass *dnd, Window window, Window from, unsigned long time)
|
||||
{
|
||||
XEvent xevent;
|
||||
|
||||
memset (&xevent, 0, sizeof (xevent));
|
||||
|
||||
xevent.xany.type = ClientMessage;
|
||||
xevent.xany.display = dnd->display;
|
||||
xevent.xclient.window = window;
|
||||
xevent.xclient.message_type = dnd->XdndDrop;
|
||||
xevent.xclient.format = 32;
|
||||
|
||||
XDND_DROP_SOURCE_WIN (&xevent) = from;
|
||||
if (dnd_version_at_least (dnd->dragging_version, 1))
|
||||
XDND_DROP_TIME (&xevent) = time;
|
||||
|
||||
XSendEvent (dnd->display, window, 0, 0, &xevent);
|
||||
}
|
||||
|
||||
void
|
||||
xdnd_send_finished(DndClass * dnd, Window window, Window from, int error)
|
||||
{
|
||||
XEvent xevent;
|
||||
memset (&xevent, 0, sizeof (xevent));
|
||||
xevent.xany.type = ClientMessage;
|
||||
xevent.xany.display = dnd->display;
|
||||
xevent.xclient.window = window;
|
||||
xevent.xclient.message_type = dnd->XdndFinished;
|
||||
xevent.xclient.format = 32;
|
||||
|
||||
XDND_FINISHED_TARGET_WIN (&xevent) = from;
|
||||
|
||||
XSendEvent (dnd->display, window, 0, 0, &xevent);
|
||||
}
|
||||
|
||||
int
|
||||
xdnd_convert_selection(DndClass *dnd, Window window, Window requester, Atom type)
|
||||
{
|
||||
if (window != XGetSelectionOwner (dnd->display, dnd->XdndSelection))
|
||||
{
|
||||
dnd_debug ("xdnd_convert_selection(): XGetSelectionOwner failed");
|
||||
return 1;
|
||||
}
|
||||
|
||||
XConvertSelection (dnd->display, dnd->XdndSelection, type,
|
||||
dnd->Xdnd_NON_PROTOCOL_ATOM, requester, CurrentTime);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
xdnd_set_selection_owner(DndClass * dnd, Window window, Atom type)
|
||||
{
|
||||
if (!XSetSelectionOwner(dnd->display,dnd->XdndSelection,window,CurrentTime))
|
||||
{
|
||||
dnd_debug ("xdnd_set_selection_owner(): XSetSelectionOwner failed");
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
xdnd_selection_send(DndClass * dnd, XSelectionRequestEvent * request,
|
||||
unsigned char *data, int length)
|
||||
{
|
||||
XEvent xevent;
|
||||
|
||||
dnd_debug (" requestor = %ld", request->requestor);
|
||||
dnd_debug (" property = %ld", request->property);
|
||||
dnd_debug (" length = %d", length);
|
||||
|
||||
XChangeProperty (dnd->display, request->requestor, request->property,
|
||||
request->target, 8, PropModeReplace, data, length);
|
||||
|
||||
xevent.xselection.type = SelectionNotify;
|
||||
xevent.xselection.property = request->property;
|
||||
xevent.xselection.display = request->display;
|
||||
xevent.xselection.requestor = request->requestor;
|
||||
xevent.xselection.selection = request->selection;
|
||||
xevent.xselection.target = request->target;
|
||||
xevent.xselection.time = request->time;
|
||||
|
||||
XSendEvent (dnd->display, request->requestor, 0, 0, &xevent);
|
||||
}
|
||||
|
||||
//
|
||||
// Unused
|
||||
//
|
||||
|
||||
void
|
||||
xdnd_set_type_list(DndClass * dnd, Window window, Atom * typelist)
|
||||
{
|
||||
int n = array_length (typelist);
|
||||
|
||||
XChangeProperty (dnd->display, window, dnd->XdndTypeList, XA_ATOM, 32,
|
||||
PropModeReplace, (unsigned char *) typelist, n);
|
||||
}
|
||||
|
||||
/* result must be free'd */
|
||||
void
|
||||
xdnd_get_type_list(DndClass * dnd, Window window, Atom ** typelist)
|
||||
{
|
||||
Atom type, *a;
|
||||
int format, i;
|
||||
unsigned long count, remaining;
|
||||
unsigned char *data = NULL;
|
||||
|
||||
*typelist = 0;
|
||||
|
||||
XGetWindowProperty (dnd->display, window, dnd->XdndTypeList,
|
||||
0, 0x8000000L, False, XA_ATOM, &type, &format, &count, &remaining, &data);
|
||||
|
||||
if (type != XA_ATOM || format != 32 || count == 0 || !data)
|
||||
{
|
||||
if (data)
|
||||
XFree (data);
|
||||
dnd_debug ("XGetWindowProperty failed in xdnd_get_type_list - dnd->XdndTypeList = %ld", dnd->XdndTypeList);
|
||||
return;
|
||||
}
|
||||
*typelist = malloc ((count + 1) * sizeof (Atom));
|
||||
a = (Atom *) data;
|
||||
for (i = 0; i < count; i++)
|
||||
(*typelist)[i] = a[i];
|
||||
(*typelist)[count] = 0;
|
||||
|
||||
XFree (data);
|
||||
}
|
284
Source/x11/xutil.c
Normal file
284
Source/x11/xutil.c
Normal file
|
@ -0,0 +1,284 @@
|
|||
/* xutil.c - utility functions for X
|
||||
*
|
||||
* Raster graphics library
|
||||
*
|
||||
* Copyright (c) 1997 Alfredo K. Kojima
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free
|
||||
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xutil.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#ifdef XSHM
|
||||
#include <sys/ipc.h>
|
||||
#include <sys/shm.h>
|
||||
#endif /* XSHM */
|
||||
|
||||
#include "xrtools.h"
|
||||
|
||||
|
||||
#ifdef XSHM
|
||||
|
||||
static int shmError;
|
||||
|
||||
static int (*oldErrorHandler)();
|
||||
|
||||
static int
|
||||
errorHandler(Display *dpy, XErrorEvent *err)
|
||||
{
|
||||
shmError=1;
|
||||
if(err->error_code!=BadAccess)
|
||||
(*oldErrorHandler)(dpy, err);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
RXImage*
|
||||
RCreateXImage(RContext *context, int depth, unsigned width, unsigned height)
|
||||
{
|
||||
RXImage *rximg;
|
||||
Visual *visual = context->visual;
|
||||
|
||||
rximg = malloc(sizeof(RXImage));
|
||||
if (!rximg) {
|
||||
RErrorCode = RERR_NOMEMORY;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#ifndef XSHM
|
||||
rximg->image = XCreateImage(context->dpy, visual, depth,
|
||||
ZPixmap, 0, NULL, width, height, 8, 0);
|
||||
if (!rximg->image) {
|
||||
free(rximg);
|
||||
RErrorCode = RERR_XERROR;
|
||||
return NULL;
|
||||
}
|
||||
rximg->image->data = malloc(rximg->image->bytes_per_line*height);
|
||||
if (!rximg->image->data) {
|
||||
XDestroyImage(rximg->image);
|
||||
free(rximg);
|
||||
RErrorCode = RERR_NOMEMORY;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#else /* XSHM */
|
||||
if (!context->attribs->use_shared_memory) {
|
||||
retry_without_shm:
|
||||
|
||||
context->attribs->use_shared_memory = 0;
|
||||
rximg->is_shared = 0;
|
||||
rximg->image = XCreateImage(context->dpy, visual, depth,
|
||||
ZPixmap, 0, NULL, width, height, 8, 0);
|
||||
if (!rximg->image) {
|
||||
free(rximg);
|
||||
RErrorCode = RERR_XERROR;
|
||||
return NULL;
|
||||
}
|
||||
rximg->image->data = malloc(rximg->image->bytes_per_line*height);
|
||||
if (!rximg->image->data) {
|
||||
XDestroyImage(rximg->image);
|
||||
free(rximg);
|
||||
RErrorCode = RERR_NOMEMORY;
|
||||
return NULL;
|
||||
}
|
||||
} else {
|
||||
rximg->is_shared = 1;
|
||||
|
||||
rximg->info.readOnly = False;
|
||||
|
||||
rximg->image = XShmCreateImage(context->dpy, visual, depth,
|
||||
ZPixmap, NULL, &rximg->info, width,
|
||||
height);
|
||||
|
||||
rximg->info.shmid = shmget(IPC_PRIVATE,
|
||||
rximg->image->bytes_per_line*height,
|
||||
IPC_CREAT|0777);
|
||||
if (rximg->info.shmid < 0) {
|
||||
context->attribs->use_shared_memory = 0;
|
||||
perror("wrlib:could not allocate shared memory segment");
|
||||
XDestroyImage(rximg->image);
|
||||
goto retry_without_shm;
|
||||
}
|
||||
|
||||
rximg->info.shmaddr = shmat(rximg->info.shmid, 0, 0);
|
||||
if (rximg->info.shmaddr == (void*)-1) {
|
||||
context->attribs->use_shared_memory = 0;
|
||||
if (shmctl(rximg->info.shmid, IPC_RMID, 0) < 0)
|
||||
perror("wrlib:shmctl");
|
||||
perror("wrlib:could not allocate shared memory");
|
||||
XDestroyImage(rximg->image);
|
||||
goto retry_without_shm;
|
||||
}
|
||||
|
||||
shmError = 0;
|
||||
XSync(context->dpy, False);
|
||||
oldErrorHandler = XSetErrorHandler(errorHandler);
|
||||
XShmAttach(context->dpy, &rximg->info);
|
||||
XSync(context->dpy, False);
|
||||
XSetErrorHandler(oldErrorHandler);
|
||||
|
||||
rximg->image->data = rximg->info.shmaddr;
|
||||
/* rximg->image->obdata = &(rximg->info);*/
|
||||
|
||||
if (shmError) {
|
||||
context->attribs->use_shared_memory = 0;
|
||||
XDestroyImage(rximg->image);
|
||||
if (shmdt(rximg->info.shmaddr) < 0)
|
||||
perror("wrlib:shmdt");
|
||||
if (shmctl(rximg->info.shmid, IPC_RMID, 0) < 0)
|
||||
perror("wrlib:shmctl");
|
||||
/* printf("wrlib:error attaching shared memory segment to XImage\n");
|
||||
*/
|
||||
goto retry_without_shm;
|
||||
}
|
||||
}
|
||||
#endif /* XSHM */
|
||||
|
||||
return rximg;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
RDestroyXImage(RContext *context, RXImage *rximage)
|
||||
{
|
||||
#ifndef XSHM
|
||||
XDestroyImage(rximage->image);
|
||||
#else /* XSHM */
|
||||
if (rximage->is_shared) {
|
||||
XSync(context->dpy, False);
|
||||
XShmDetach(context->dpy, &rximage->info);
|
||||
XDestroyImage(rximage->image);
|
||||
if (shmdt(rximage->info.shmaddr) < 0)
|
||||
perror("wrlib:shmdt");
|
||||
if (shmctl(rximage->info.shmid, IPC_RMID, 0) < 0)
|
||||
perror("wrlib:shmctl");
|
||||
} else {
|
||||
XDestroyImage(rximage->image);
|
||||
}
|
||||
#endif
|
||||
free(rximage);
|
||||
}
|
||||
|
||||
|
||||
static unsigned
|
||||
getDepth(Display *dpy, Drawable d)
|
||||
{
|
||||
Window w;
|
||||
int foo;
|
||||
unsigned bar;
|
||||
unsigned depth;
|
||||
|
||||
XGetGeometry(dpy, d, &w, &foo, &foo, &bar, &bar, &bar, &depth);
|
||||
|
||||
return depth;
|
||||
}
|
||||
|
||||
|
||||
|
||||
RXImage*
|
||||
RGetXImage(RContext *context, Drawable d, int x, int y,
|
||||
unsigned width, unsigned height)
|
||||
{
|
||||
RXImage *ximg = NULL;
|
||||
|
||||
#ifdef XSHM
|
||||
if (context->attribs->use_shared_memory && 0) {
|
||||
ximg = RCreateXImage(context, getDepth(context->dpy, d),
|
||||
width, height);
|
||||
|
||||
if (ximg && !ximg->is_shared) {
|
||||
RDestroyXImage(context, ximg);
|
||||
ximg = NULL;
|
||||
}
|
||||
if (ximg) {
|
||||
XShmGetImage(context->dpy, d, ximg->image, x, y, AllPlanes);
|
||||
}
|
||||
}
|
||||
if (!ximg) {
|
||||
ximg = malloc(sizeof(RXImage));
|
||||
if (!ximg) {
|
||||
RErrorCode = RERR_NOMEMORY;
|
||||
return NULL;
|
||||
}
|
||||
ximg->is_shared = 0;
|
||||
ximg->image = XGetImage(context->dpy, d, x, y, width, height,
|
||||
AllPlanes, ZPixmap);
|
||||
}
|
||||
return ximg;
|
||||
#else /* !XSHM */
|
||||
ximg = malloc(sizeof(RXImage));
|
||||
if (!ximg) {
|
||||
RErrorCode = RERR_NOMEMORY;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ximg->image = XGetImage(context->dpy, d, x, y, width, height,
|
||||
AllPlanes, ZPixmap);
|
||||
|
||||
return ximg;
|
||||
#endif /* !XSHM */
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
RPutXImage(RContext *context, Drawable d, GC gc, RXImage *ximage, int src_x,
|
||||
int src_y, int dest_x, int dest_y,
|
||||
unsigned int width, unsigned int height)
|
||||
{
|
||||
#ifndef XSHM
|
||||
XPutImage(context->dpy, d, gc, ximage->image, src_x, src_y, dest_x,
|
||||
dest_y, width, height);
|
||||
#else
|
||||
if (ximage->is_shared) {
|
||||
XShmPutImage(context->dpy, d, gc, ximage->image, src_x, src_y,
|
||||
dest_x, dest_y, width, height, False);
|
||||
} else {
|
||||
XPutImage(context->dpy, d, gc, ximage->image, src_x, src_y, dest_x,
|
||||
dest_y, width, height);
|
||||
}
|
||||
XFlush(context->dpy);
|
||||
#endif /* XSHM */
|
||||
}
|
||||
|
||||
|
||||
#ifdef XSHM
|
||||
Pixmap
|
||||
R_CreateXImageMappedPixmap(RContext *context, RXImage *rximage)
|
||||
{
|
||||
Pixmap pix;
|
||||
|
||||
pix = XShmCreatePixmap(context->dpy, context->drawable,
|
||||
rximage->image->data, &rximage->info,
|
||||
rximage->image->width, rximage->image->height,
|
||||
rximage->image->depth);
|
||||
|
||||
return pix;
|
||||
}
|
||||
|
||||
#endif /* XSHM */
|
||||
|
88
Source/xdps/AFMFileFontInfo.h
Normal file
88
Source/xdps/AFMFileFontInfo.h
Normal file
|
@ -0,0 +1,88 @@
|
|||
/*
|
||||
AFMFileFontInfo.h
|
||||
|
||||
Private data of PXKFont class.
|
||||
|
||||
Copyright (C) 1996 Free Software Foundation, Inc.
|
||||
|
||||
Author: Ovidiu Predescu <ovidiu@bx.logicnet.ro>
|
||||
Date: February 1997
|
||||
|
||||
This file is part of the GNUstep GUI X/DPS Library.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
|
||||
*/
|
||||
|
||||
#ifndef __AFMFileFontInfo_h__
|
||||
#define __AFMFileFontInfo_h__
|
||||
|
||||
#include <Foundation/NSMapTable.h>
|
||||
#include <AppKit/GSFontInfo.h>
|
||||
#include "parseAFM.h"
|
||||
|
||||
typedef struct {
|
||||
NSGlyph glyph;
|
||||
NSSize advancement;
|
||||
} tPairKerningInfo;
|
||||
|
||||
@interface PXKFontEnumerator : GSFontEnumerator
|
||||
{
|
||||
}
|
||||
@end
|
||||
|
||||
@interface AFMGlyphInfo : NSObject <NSCopying>
|
||||
{
|
||||
NSString* name;
|
||||
NSGlyph code;
|
||||
NSRect bbox;
|
||||
NSSize advancement;
|
||||
int lastKernPair;
|
||||
int numOfPairs;
|
||||
tPairKerningInfo* kerning;
|
||||
}
|
||||
|
||||
+ (AFMGlyphInfo*) glyphFromAFMCharMetricInfo: (AFMCharMetricInfo*)metricInfo;
|
||||
|
||||
- (AFMGlyphInfo*)mutableCopyWithZone: (NSZone*)zone;
|
||||
|
||||
- (NSString*) name;
|
||||
- (NSGlyph) code;
|
||||
- (NSRect) boundingRect;
|
||||
- (NSSize) advancement;
|
||||
- (BOOL) isEncoded;
|
||||
|
||||
- (void) transformUsingMatrix: (const float*)matrix;
|
||||
|
||||
- (void) incrementNumberOfKernPairs;
|
||||
- (void) addPairKerningForGlyph:(NSGlyph)glyph advancement:(NSSize)advancement;
|
||||
- (NSSize) advancementIfFollowedByGlyph: (NSGlyph)glyph
|
||||
isNominal: (BOOL*)nominal;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@interface AFMFileFontInfo : GSFontInfo
|
||||
{
|
||||
NSString *afmFileName;
|
||||
NSMapTable *glyphsByName;
|
||||
AFMGlyphInfo *glyphs[256];
|
||||
}
|
||||
|
||||
- (AFMFileFontInfo*)mutableCopyWithZone: (NSZone*)zone;
|
||||
- (AFMFileFontInfo*)initUnscaledWithFontName: (NSString*)name;
|
||||
@end
|
||||
|
||||
#endif /* __AFMFileFontInfo_h__ */
|
||||
|
810
Source/xdps/AFMFileFontInfo.m
Normal file
810
Source/xdps/AFMFileFontInfo.m
Normal file
|
@ -0,0 +1,810 @@
|
|||
/*
|
||||
AFMFileFontInfo.m
|
||||
|
||||
Copyright (C) 1996 Free Software Foundation, Inc.
|
||||
|
||||
Author: Ovidiu Predescu <ovidiu@bx.logicnet.ro>
|
||||
Date: February 1997
|
||||
|
||||
This file is part of the GNUstep GUI X/DPS Library.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
|
||||
*/
|
||||
|
||||
#include <float.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <sys/file.h>
|
||||
#include <fcntl.h>
|
||||
#include "config.h"
|
||||
|
||||
#include <Foundation/NSDictionary.h>
|
||||
#include <Foundation/NSString.h>
|
||||
#include <Foundation/NSFileManager.h>
|
||||
#include <Foundation/NSAutoreleasePool.h>
|
||||
#include <Foundation/NSValue.h>
|
||||
#include <Foundation/NSDate.h>
|
||||
|
||||
#include <AppKit/NSFont.h>
|
||||
#include <DPS/PSres.h>
|
||||
|
||||
#include "xdps/NSDPSContext.h"
|
||||
#include "AFMFileFontInfo.h"
|
||||
#include "general.h"
|
||||
#include "fonts.h"
|
||||
|
||||
/* This dictionary keeps global font info objects indexed by AFM file names.
|
||||
A global font info instance is the representation of AFM file; all the
|
||||
dimensions are in the 1x1 space not in the 1000x1000 space of the AFM file.
|
||||
Each font object maintains a copy of this instance with all the dimensions
|
||||
scaled to the font size. */
|
||||
static NSMutableDictionary* globalFontInfoDictionary = nil;
|
||||
|
||||
static NSMutableDictionary* globalFileDictionary = nil;
|
||||
|
||||
#ifndef LIB_FOUNDATION_LIBRARY
|
||||
/* Define callbacks for a map table that has cStrings as keys */
|
||||
|
||||
/* hpjw from Aho, Sethi & Ullman: Principles of compiler design. */
|
||||
static unsigned __NSHashCString(void *table, const void *aString)
|
||||
{
|
||||
register const char* p = (char*)aString;
|
||||
register unsigned hash = 0, hash2;
|
||||
register int i, n = strlen((char*)aString);
|
||||
|
||||
for(i=0; i < n; i++) {
|
||||
hash <<= 4;
|
||||
hash += *p++;
|
||||
if((hash2 = hash & 0xf0000000))
|
||||
hash ^= (hash2 >> 24) ^ hash2;
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
static BOOL __NSCompareCString(void *table,
|
||||
const void *anObject1, const void *anObject2)
|
||||
{
|
||||
return strcmp((char*)anObject1, (char*)anObject2) == 0;
|
||||
}
|
||||
|
||||
static void __NSRetainNothing(void *table, const void *anObject)
|
||||
{
|
||||
}
|
||||
|
||||
static void __NSReleaseNothing(void *table, void *anObject)
|
||||
{
|
||||
}
|
||||
|
||||
static NSString* __NSDescribePointers(void *table, const void *anObject)
|
||||
{
|
||||
return [NSString stringWithCString:anObject];
|
||||
}
|
||||
|
||||
static const NSMapTableKeyCallBacks NSNonOwnedCStringMapKeyCallBacks = {
|
||||
(unsigned(*)(NSMapTable*, const void*))__NSHashCString,
|
||||
(BOOL(*)(NSMapTable*, const void*, const void*))__NSCompareCString,
|
||||
(void (*)(NSMapTable*, const void* anObject))__NSRetainNothing,
|
||||
(void (*)(NSMapTable*, void* anObject))__NSReleaseNothing,
|
||||
(NSString *(*)(NSMapTable*, const void*))__NSDescribePointers,
|
||||
(const void *)NULL
|
||||
};
|
||||
#endif /* LIB_FOUNDATION_LIBRARY */
|
||||
|
||||
static int
|
||||
afmEnumerator (char* resourceType, char* resourceName, char* resourceFile,
|
||||
char* fontsList)
|
||||
{
|
||||
NSString* afmFileName = [NSString stringWithCString: resourceFile];
|
||||
[(NSMutableArray*)fontsList addObject: afmFileName];
|
||||
return 0;
|
||||
}
|
||||
|
||||
@implementation AFMFileFontInfo
|
||||
|
||||
+ (void)initialize
|
||||
{
|
||||
static BOOL initialized = NO;
|
||||
|
||||
if (!initialized) {
|
||||
initialized = YES;
|
||||
globalFontInfoDictionary = [NSMutableDictionary new];
|
||||
globalFileDictionary = [NSMutableDictionary new];
|
||||
}
|
||||
}
|
||||
|
||||
- (NSString *) _getFontResource
|
||||
{
|
||||
NSString* fontFile;
|
||||
DPSContext ctxt;
|
||||
char font_file[FILENAME_MAX + 1];
|
||||
|
||||
ctxt = [(NSDPSContext *)GSCurrentContext() xDPSContext];
|
||||
|
||||
|
||||
fontFile = nil;
|
||||
PSWGetFontFile(ctxt, [fontName cString], font_file);
|
||||
if (strncmp(font_file, "/Resource", 9) == 0)
|
||||
{
|
||||
char completePath[FILENAME_MAX + 1];
|
||||
int found;
|
||||
/* We're using GS which returns files differently */
|
||||
PSWGSFontFile(ctxt, [fontName cString], font_file);
|
||||
PSWCompleteFilename (font_file, &found, completePath);
|
||||
if (found)
|
||||
{
|
||||
fontFile = [NSString stringWithCString: completePath];
|
||||
fontFile = [[fontFile stringByDeletingPathExtension]
|
||||
stringByAppendingPathExtension:@"afm"];
|
||||
}
|
||||
}
|
||||
else if (font_file[0] != '/')
|
||||
{
|
||||
/* Can't handle this yet, try the Adobe way... */
|
||||
NSMutableArray *fontsList = [[NSMutableArray new] autorelease];
|
||||
NSDebugLLog(@"Fonts", @"Font file resource returned relative-path %s",
|
||||
font_file);
|
||||
EnumeratePSResourceFiles (NULL, NULL, PSResFontAFM, [fontName cString],
|
||||
afmEnumerator, (char*)fontsList);
|
||||
if (![fontsList count])
|
||||
NSLog (@"WARNING: Font file not found! Check if the PSRESOURCEPATH "
|
||||
@"environment variable points to the right directory. If so then "
|
||||
@"probably you did not build the PS resource database using the "
|
||||
@"`makepsres' utility.");
|
||||
else
|
||||
fontFile = [fontsList objectAtIndex: 0];
|
||||
}
|
||||
|
||||
if (fontFile)
|
||||
NSDebugLLog(@"Fonts", @"Found AFM file %@ for font %@", fontFile, fontName);
|
||||
return fontFile;
|
||||
}
|
||||
|
||||
- _setFontInfo
|
||||
{
|
||||
NSAutoreleasePool* pool;
|
||||
AFMFontInfo* cFontInfo;
|
||||
AFMGlobalFontInfo* gfi;
|
||||
int fontType;
|
||||
FILE* file;
|
||||
int i, code;
|
||||
NSString *sweight;
|
||||
|
||||
afmFileName = [globalFileDictionary objectForKey: fontName];
|
||||
if (afmFileName == nil)
|
||||
{
|
||||
afmFileName = [self _getFontResource];
|
||||
if (afmFileName == nil)
|
||||
{
|
||||
NSLog (@"No AFM file for font %@. Can't get font info", fontName);
|
||||
return nil;
|
||||
}
|
||||
[globalFileDictionary setObject: afmFileName forKey: fontName];
|
||||
}
|
||||
RETAIN(afmFileName);
|
||||
|
||||
if (![[NSFileManager defaultManager] isReadableFileAtPath: afmFileName])
|
||||
{
|
||||
NSLog (@"Cannot read AFM file %@ for font %@", afmFileName, fontName);
|
||||
return nil;
|
||||
}
|
||||
|
||||
file = fopen ([afmFileName cString], "r");
|
||||
if (!file)
|
||||
{
|
||||
NSLog (@"Cannot open AFM file %@ for font %@", afmFileName, fontName);
|
||||
return nil;
|
||||
}
|
||||
|
||||
code = AFMParseFile (file, &cFontInfo, AFM_G | AFM_M | AFM_P);
|
||||
if (code != afm_ok) {
|
||||
switch (code) {
|
||||
case afm_parseError:
|
||||
NSLog (@"parse error in AFM file %@", afmFileName);
|
||||
break;
|
||||
case afm_earlyEOF:
|
||||
NSLog (@"unexpected EOF in AFM file %@", afmFileName);
|
||||
break;
|
||||
case afm_storageProblem:
|
||||
NSLog (@"memory allocation problem while parsing the AFM file %@",
|
||||
afmFileName);
|
||||
break;
|
||||
}
|
||||
fclose (file);
|
||||
return nil;
|
||||
}
|
||||
fclose (file);
|
||||
|
||||
gfi = cFontInfo->gfi;
|
||||
|
||||
pool = [NSAutoreleasePool new];
|
||||
|
||||
/*
|
||||
* Set the font information in instance variables and in the AFM dictionary.
|
||||
*/
|
||||
|
||||
/* The font may actually be a GS alias, so do not set the fontName
|
||||
* field. */
|
||||
// fontName = [[NSString stringWithCString:gfi->fontName] retain];
|
||||
[fontDictionary setObject: fontName forKey: NSAFMFontName];
|
||||
|
||||
familyName = [[NSString stringWithCString:gfi->familyName] retain];
|
||||
[fontDictionary setObject: familyName forKey: NSAFMFamilyName];
|
||||
|
||||
italicAngle = gfi->italicAngle;
|
||||
[fontDictionary setObject: [NSNumber numberWithFloat:gfi->italicAngle]
|
||||
forKey: NSAFMItalicAngle];
|
||||
|
||||
sweight = [NSString stringWithCString:gfi->weight];
|
||||
[fontDictionary setObject: sweight forKey: NSAFMWeight];
|
||||
|
||||
underlinePosition = ((float)gfi->underlinePosition) / 1000;
|
||||
[fontDictionary setObject: [NSNumber numberWithFloat:underlinePosition]
|
||||
forKey: NSAFMUnderlinePosition];
|
||||
|
||||
underlineThickness = ((float)gfi->underlineThickness) / 1000;
|
||||
[fontDictionary setObject: [NSNumber numberWithFloat:underlineThickness]
|
||||
forKey: NSAFMUnderlineThickness];
|
||||
|
||||
capHeight = ((float)gfi->capHeight) / 1000;
|
||||
[fontDictionary setObject: [NSNumber numberWithFloat:capHeight]
|
||||
forKey: NSAFMCapHeight];
|
||||
|
||||
xHeight = ((float)gfi->xHeight) / 1000;
|
||||
[fontDictionary setObject: [NSNumber numberWithFloat:xHeight]
|
||||
forKey: NSAFMXHeight];
|
||||
|
||||
descender = ((float)gfi->descender) / 1000;
|
||||
[fontDictionary setObject: [NSNumber numberWithFloat:descender]
|
||||
forKey: NSAFMDescender];
|
||||
|
||||
ascender = ((float)gfi->ascender) / 1000;
|
||||
[fontDictionary setObject: [NSNumber numberWithFloat:ascender]
|
||||
forKey: NSAFMAscender];
|
||||
|
||||
encodingScheme = [[NSString stringWithCString:gfi->encodingScheme]
|
||||
retain];
|
||||
[fontDictionary setObject: encodingScheme forKey: NSAFMEncodingScheme];
|
||||
|
||||
[fontDictionary setObject: [NSString stringWithCString:gfi->afmVersion]
|
||||
forKey: NSAFMFormatVersion];
|
||||
[fontDictionary setObject:[NSString stringWithCString:gfi->notice]
|
||||
forKey: NSAFMNotice];
|
||||
[fontDictionary setObject:[NSString stringWithCString:gfi->version]
|
||||
forKey: NSAFMVersion];
|
||||
|
||||
/* Setup bbox as expected by NSFont */
|
||||
fontBBox.origin.x = ((float)gfi->fontBBox.llx) / 1000;
|
||||
fontBBox.origin.y = ((float)gfi->fontBBox.lly) / 1000;
|
||||
fontBBox.size.width
|
||||
= ((float)(gfi->fontBBox.urx - gfi->fontBBox.llx)) / 1000;
|
||||
fontBBox.size.height
|
||||
= ((float)(gfi->fontBBox.ury - gfi->fontBBox.lly)) / 1000;
|
||||
|
||||
isFixedPitch = gfi->isFixedPitch;
|
||||
|
||||
/* Get the font type from the DGS server */
|
||||
PSWGetFontType ([fontName cString], &fontType);
|
||||
isBaseFont = (fontType != 0);
|
||||
|
||||
maximumAdvancement.width = FLT_MIN;
|
||||
maximumAdvancement.height = FLT_MIN;
|
||||
minimumAdvancement.width = FLT_MAX;
|
||||
minimumAdvancement.height = FLT_MAX;
|
||||
|
||||
/* Fill in the glyphs arrays. */
|
||||
glyphsByName = NSCreateMapTable (NSNonOwnedCStringMapKeyCallBacks,
|
||||
NSObjectMapValueCallBacks, 256);
|
||||
for (i = 0; i < cFontInfo->numOfChars; i++) {
|
||||
AFMCharMetricInfo charMetricInfo = cFontInfo->cmi[i];
|
||||
AFMGlyphInfo* glyph
|
||||
= [AFMGlyphInfo glyphFromAFMCharMetricInfo:&charMetricInfo];
|
||||
NSSize glyphAdvancement = [glyph advancement];
|
||||
|
||||
NSMapInsert (glyphsByName, [[glyph name] cString], glyph);
|
||||
maximumAdvancement.width
|
||||
= MAX (maximumAdvancement.width, glyphAdvancement.width);
|
||||
maximumAdvancement.height
|
||||
= MAX (maximumAdvancement.height, glyphAdvancement.height);
|
||||
minimumAdvancement.width
|
||||
= MIN (minimumAdvancement.width, glyphAdvancement.width);
|
||||
minimumAdvancement.height
|
||||
= MIN (minimumAdvancement.height, glyphAdvancement.height);
|
||||
if (charMetricInfo.code > 0) {
|
||||
glyphs[charMetricInfo.code] = [glyph retain];
|
||||
}
|
||||
}
|
||||
|
||||
/* Set the entries in the kerning array for all the glyphs in the pair
|
||||
kerning array. */
|
||||
{
|
||||
AFMGlyphInfo* glyph1 = nil;
|
||||
AFMGlyphInfo* glyph2 = nil;
|
||||
const char* previousGlyphName = "";
|
||||
AFMPairKernData pkd;
|
||||
NSSize advancement;
|
||||
|
||||
/* First compute the numbers of kern pairs for each glyph. This is used to
|
||||
avoid unnecessary allocations of kern pair arrays in glyph objects. */
|
||||
for (i = 0; i < cFontInfo->numOfPairs; i++) {
|
||||
pkd = cFontInfo->pkd[i];
|
||||
|
||||
/* Check the name of the first glyph. Use a hint here: the kern pairs are
|
||||
grouped on the first glyph. */
|
||||
if (strcmp (pkd.name1, previousGlyphName)) {
|
||||
previousGlyphName = pkd.name1;
|
||||
glyph1 = NSMapGet (glyphsByName, pkd.name1);
|
||||
}
|
||||
[glyph1 incrementNumberOfKernPairs];
|
||||
}
|
||||
|
||||
/* Now set the pair kerns in glyphs. */
|
||||
for (i = 0; i < cFontInfo->numOfPairs; i++) {
|
||||
pkd = cFontInfo->pkd[i];
|
||||
|
||||
if (strcmp (pkd.name1, previousGlyphName)) {
|
||||
previousGlyphName = pkd.name1;
|
||||
glyph1 = NSMapGet (glyphsByName, pkd.name1);
|
||||
}
|
||||
|
||||
glyph2 = NSMapGet (glyphsByName, pkd.name2);
|
||||
|
||||
if (!glyph1) {
|
||||
NSLog (@"unknown glyph name %s in AFM file %@", pkd.name1, afmFileName);
|
||||
continue;
|
||||
}
|
||||
if (!glyph2) {
|
||||
NSLog (@"unknown glyph name %s in AFM file %@", pkd.name2, afmFileName);
|
||||
continue;
|
||||
}
|
||||
|
||||
advancement = NSMakeSize (pkd.xamt, pkd.yamt);
|
||||
[glyph1 addPairKerningForGlyph:[glyph2 code] advancement:advancement];
|
||||
}
|
||||
}
|
||||
|
||||
/* Free the cFontInfo structure */
|
||||
free (gfi->afmVersion);
|
||||
free (gfi->fontName);
|
||||
free (gfi->fullName);
|
||||
free (gfi->familyName);
|
||||
free (gfi->weight);
|
||||
free (gfi->version);
|
||||
free (gfi->notice);
|
||||
free (gfi->encodingScheme);
|
||||
for (i = 0; i < cFontInfo->numOfChars; i++) {
|
||||
AFMCharMetricInfo cmi = cFontInfo->cmi[i];
|
||||
free (cmi.name);
|
||||
}
|
||||
for (i = 0; i < cFontInfo->numOfPairs; i++) {
|
||||
AFMPairKernData pkd = cFontInfo->pkd[i];
|
||||
free (pkd.name1);
|
||||
free (pkd.name2);
|
||||
}
|
||||
free (cFontInfo);
|
||||
|
||||
[pool release];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) transformUsingMatrix: (const float*)fmatrix
|
||||
{
|
||||
float a = fmatrix[0];
|
||||
float b = fmatrix[1];
|
||||
float c = fmatrix[2];
|
||||
float d = fmatrix[3];
|
||||
float tx = fmatrix[4];
|
||||
float ty = fmatrix[5];
|
||||
float x1, y1, width1, height1;
|
||||
int i;
|
||||
|
||||
memcpy(matrix, fmatrix, sizeof(matrix));
|
||||
|
||||
for (i = 0; i < 256; i++) {
|
||||
[glyphs[i] transformUsingMatrix: fmatrix];
|
||||
}
|
||||
|
||||
x1 = fontBBox.origin.x;
|
||||
y1 = fontBBox.origin.y;
|
||||
width1 = fontBBox.size.width;
|
||||
height1 = fontBBox.size.height;
|
||||
fontBBox.origin.x = a * x1 + c * y1 + tx;
|
||||
fontBBox.origin.y = b * x1 + d * y1 + ty;
|
||||
fontBBox.size.width = a * width1 + c * height1;
|
||||
fontBBox.size.height = b * width1 + d * height1;
|
||||
|
||||
width1 = maximumAdvancement.width;
|
||||
height1 = maximumAdvancement.height;
|
||||
maximumAdvancement.width = a * width1 + c * height1;
|
||||
maximumAdvancement.height = b * width1 + d * height1;
|
||||
|
||||
width1 = minimumAdvancement.width;
|
||||
height1 = minimumAdvancement.height;
|
||||
minimumAdvancement.width = a * width1 + c * height1;
|
||||
minimumAdvancement.height = b * width1 + d * height1;
|
||||
|
||||
underlinePosition = a * underlinePosition + tx;
|
||||
underlineThickness = a * underlineThickness + tx;
|
||||
capHeight = a * capHeight + tx;
|
||||
ascender = a * ascender + tx;
|
||||
descender = a * descender + tx;
|
||||
|
||||
xHeight = a * xHeight + tx;
|
||||
}
|
||||
|
||||
- (AFMFileFontInfo *) transformedFontInfoForMatrix: (const float *)fmatrix
|
||||
{
|
||||
AFMFileFontInfo *new = [self mutableCopy];
|
||||
[new transformUsingMatrix: fmatrix];
|
||||
return AUTORELEASE(new);
|
||||
}
|
||||
|
||||
- initUnscaledWithFontName: (NSString*)name
|
||||
{
|
||||
AFMFileFontInfo *fontInfo;
|
||||
|
||||
/* Check whether the font info is cached */
|
||||
fontInfo = [globalFontInfoDictionary objectForKey: name];
|
||||
if(fontInfo != nil)
|
||||
{
|
||||
RELEASE(self);
|
||||
// retain to act like we were alloc'd
|
||||
return RETAIN(fontInfo);
|
||||
}
|
||||
/* Tough. Parse the AFM file and create a new font info for
|
||||
the unscaled font. */
|
||||
[super init];
|
||||
fontName = RETAIN(name);
|
||||
if ([self _setFontInfo] == nil)
|
||||
{
|
||||
RELEASE(self);
|
||||
return nil;
|
||||
}
|
||||
/* Cache the font info for later use */
|
||||
[globalFontInfoDictionary setObject: self forKey: fontName];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- initWithFontName: (NSString*)name matrix: (const float *)fmatrix
|
||||
{
|
||||
AFMFileFontInfo *fontInfo, *baseFontInfo;
|
||||
|
||||
RELEASE(self);
|
||||
/* Grab an unscaled font info and create a new scaled one. */
|
||||
baseFontInfo = [[AFMFileFontInfo alloc] initUnscaledWithFontName: name];
|
||||
if(baseFontInfo == nil)
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
fontInfo = [baseFontInfo transformedFontInfoForMatrix: fmatrix];
|
||||
RELEASE(baseFontInfo);
|
||||
RETAIN(fontInfo);
|
||||
|
||||
return fontInfo;
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
int i;
|
||||
|
||||
/* Don't free the glyphsByName map table. It is owned by the first font info
|
||||
object that is never freed. */
|
||||
for (i = 0; i < 256; i++)
|
||||
TEST_RELEASE(glyphs[i]);
|
||||
|
||||
TEST_RELEASE(afmFileName);
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (void)set
|
||||
{
|
||||
if ([[GSCurrentContext() focusView] isFlipped])
|
||||
{
|
||||
float invmatrix[6];
|
||||
memcpy(invmatrix, matrix, sizeof(invmatrix));
|
||||
invmatrix[3] = -invmatrix[3];
|
||||
PSWSetFont ([fontName cString], invmatrix);
|
||||
}
|
||||
else
|
||||
PSWSetFont ([fontName cString], matrix);
|
||||
}
|
||||
|
||||
- (NSString*)afmFileContents
|
||||
{
|
||||
return [NSString stringWithContentsOfFile: afmFileName];
|
||||
}
|
||||
|
||||
- copyWithZone: (NSZone *)zone
|
||||
{
|
||||
AFMFileFontInfo* new;
|
||||
if (NSShouldRetainWithZone(self, zone))
|
||||
new = RETAIN(self);
|
||||
else
|
||||
{
|
||||
int i;
|
||||
new = [super copyWithZone: zone];
|
||||
for (i = 0; i < 256; i++) {
|
||||
new->glyphs[i] = [glyphs[i] copyWithZone: zone];
|
||||
}
|
||||
new->afmFileName = [afmFileName copyWithZone: zone];
|
||||
}
|
||||
return new;
|
||||
}
|
||||
|
||||
- mutableCopyWithZone: (NSZone *)zone
|
||||
{
|
||||
int i;
|
||||
AFMFileFontInfo* new = [super mutableCopyWithZone: zone];
|
||||
for (i = 0; i < 256; i++) {
|
||||
new->glyphs[i] = [glyphs[i] mutableCopyWithZone: zone];
|
||||
}
|
||||
new->afmFileName = [afmFileName copyWithZone: zone];
|
||||
|
||||
return new;
|
||||
}
|
||||
|
||||
- (NSSize)advancementForGlyph:(NSGlyph)glyph
|
||||
{
|
||||
return [glyphs[glyph] advancement];
|
||||
}
|
||||
|
||||
- (NSRect)boundingRectForGlyph:(NSGlyph)glyph
|
||||
{
|
||||
return [glyphs[glyph] boundingRect];
|
||||
}
|
||||
|
||||
- (BOOL)glyphIsEncoded:(NSGlyph)glyph
|
||||
{
|
||||
return [glyphs[glyph] isEncoded];
|
||||
}
|
||||
|
||||
- (NSGlyph)glyphWithName:(NSString*)glyphName
|
||||
{
|
||||
AFMGlyphInfo* glyph = NSMapGet (glyphsByName, [glyphName cString]);
|
||||
|
||||
return glyph ? [glyph code] : -1;
|
||||
}
|
||||
|
||||
- (NSPoint)positionOfGlyph:(NSGlyph)curGlyph
|
||||
precededByGlyph:(NSGlyph)prevGlyph
|
||||
isNominal:(BOOL*)nominal
|
||||
{
|
||||
NSPoint point;
|
||||
NSSize size;
|
||||
|
||||
if (curGlyph == NSControlGlyph || prevGlyph == NSControlGlyph
|
||||
|| curGlyph < 0 || curGlyph > 255 || prevGlyph < 0 || prevGlyph >255) {
|
||||
if (nominal)
|
||||
*nominal = NO;
|
||||
return NSZeroPoint;
|
||||
}
|
||||
|
||||
if (curGlyph == NSNullGlyph) {
|
||||
size = [glyphs[prevGlyph] advancement];
|
||||
point.x = size.width;
|
||||
point.y = size.height;
|
||||
if (nominal)
|
||||
*nominal = NO;
|
||||
return point;
|
||||
}
|
||||
|
||||
if (glyphs[prevGlyph]) {
|
||||
if (!glyphs[curGlyph]) {
|
||||
point.x = maximumAdvancement.width;
|
||||
point.y = maximumAdvancement.height;
|
||||
if (nominal)
|
||||
*nominal = NO;
|
||||
return point;
|
||||
}
|
||||
size = [glyphs[prevGlyph] advancementIfFollowedByGlyph:
|
||||
[glyphs[curGlyph] code]
|
||||
isNominal:nominal];
|
||||
point.x = size.width;
|
||||
point.y = size.height;
|
||||
return point;
|
||||
}
|
||||
return NSZeroPoint;
|
||||
}
|
||||
|
||||
- (float)widthOfString:(NSString*)string
|
||||
{
|
||||
/* TODO: We should really map here the characters from string to
|
||||
series of glyphs. Until then we consider the glyphs to be
|
||||
equivalent with characters. */
|
||||
|
||||
int i, length = [string length];
|
||||
const char* cString = [string cString];
|
||||
float width = 0;
|
||||
|
||||
for (i = 0; i < length; i++) {
|
||||
width += [glyphs[(int)cString[i]] advancement].width;
|
||||
}
|
||||
|
||||
return width;
|
||||
}
|
||||
|
||||
@end /* AFMFileFontInfo */
|
||||
|
||||
|
||||
@implementation AFMGlyphInfo
|
||||
|
||||
+ (AFMGlyphInfo*)glyphFromAFMCharMetricInfo:(AFMCharMetricInfo*)mi
|
||||
{
|
||||
AFMGlyphInfo* glyph = [[self new] autorelease];
|
||||
|
||||
glyph->name = [[NSString stringWithCString:mi->name] retain];
|
||||
glyph->code = mi->code;
|
||||
|
||||
/* Setup bbox as defined by NSRect */
|
||||
glyph->bbox.origin.x = ((float)mi->charBBox.llx) / 1000;
|
||||
glyph->bbox.origin.y = ((float)mi->charBBox.lly) / 1000;
|
||||
glyph->bbox.size.width = ((float)mi->charBBox.urx - mi->charBBox.llx) / 1000;
|
||||
glyph->bbox.size.height = ((float)mi->charBBox.ury - mi->charBBox.lly)/ 1000;
|
||||
|
||||
glyph->advancement.width = ((float)mi->wx) / 1000;
|
||||
glyph->advancement.height = ((float)mi->wy) / 1000;
|
||||
|
||||
return glyph;
|
||||
}
|
||||
|
||||
- (void)transformUsingMatrix:(const float*)matrix;
|
||||
{
|
||||
float a = matrix[0];
|
||||
float b = matrix[1];
|
||||
float c = matrix[2];
|
||||
float d = matrix[3];
|
||||
float tx = matrix[4];
|
||||
float ty = matrix[5];
|
||||
float x1 = bbox.origin.x;
|
||||
float y1 = bbox.origin.y;
|
||||
float width1 = bbox.size.width;
|
||||
float height1 = bbox.size.height;
|
||||
int i;
|
||||
|
||||
bbox.origin.x = a * x1 + c * y1 + tx;
|
||||
bbox.origin.y = b * x1 + d * y1 + ty;
|
||||
bbox.size.width = a * width1 + c * height1;
|
||||
bbox.size.height = b * width1 + d * height1;
|
||||
|
||||
x1 = advancement.width;
|
||||
y1 = advancement.height;
|
||||
advancement.width = a * x1 + c * y1 + tx;
|
||||
advancement.height = b * x1 + d * y1 + ty;
|
||||
|
||||
for (i = 0; i < numOfPairs; i++) {
|
||||
x1 = kerning[i].advancement.width;
|
||||
y1 = kerning[i].advancement.height;
|
||||
kerning[i].advancement.width = a * x1 + c * y1 + tx;
|
||||
kerning[i].advancement.height = b * x1 + d * y1 + ty;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)incrementNumberOfKernPairs
|
||||
{
|
||||
numOfPairs++;
|
||||
}
|
||||
|
||||
- (void)addPairKerningForGlyph:(NSGlyph)glyph advancement:(NSSize)_advancement
|
||||
{
|
||||
tPairKerningInfo kernInfo = {
|
||||
glyph,
|
||||
{ advancement.width + ((float)_advancement.width) / 1000,
|
||||
advancement.height + ((float)_advancement.height) / 1000
|
||||
}
|
||||
};
|
||||
int i;
|
||||
|
||||
if (kerning == NULL)
|
||||
kerning = malloc (numOfPairs * sizeof (tPairKerningInfo));
|
||||
|
||||
/* Insert the glyph in the proper position in the kerning array so this will
|
||||
be sorted ascending after the glyph code. */
|
||||
for (i = 0; i < lastKernPair; i++)
|
||||
if (kerning[i].glyph > glyph) {
|
||||
/* Make room for a new kerning pair in this position. */
|
||||
memmove (&kerning[i + 1], &kerning[i],
|
||||
(lastKernPair - i) * sizeof (tPairKerningInfo));
|
||||
break;
|
||||
}
|
||||
|
||||
kerning[i] = kernInfo;
|
||||
lastKernPair++;
|
||||
}
|
||||
|
||||
- (NSSize)advancementIfFollowedByGlyph:(NSGlyph)glyph
|
||||
isNominal:(BOOL*)nominal
|
||||
{
|
||||
/* Search for the glyph using a binary search algorithm */
|
||||
int lower = 0;
|
||||
int upper = numOfPairs;
|
||||
int midpoint;
|
||||
|
||||
if (!kerning) {
|
||||
if (nominal)
|
||||
*nominal = NO;
|
||||
return advancement;
|
||||
}
|
||||
|
||||
while (upper >= lower) {
|
||||
midpoint = (lower + upper) / 2;
|
||||
if (kerning[midpoint].glyph == glyph) {
|
||||
if (nominal)
|
||||
*nominal = YES;
|
||||
return kerning[midpoint].advancement;
|
||||
}
|
||||
else if (kerning[midpoint].glyph > glyph)
|
||||
upper = midpoint - 1;
|
||||
else if (kerning[midpoint].glyph < glyph)
|
||||
lower = midpoint + 1;
|
||||
}
|
||||
|
||||
/* The glyph was not found in the kernings array. Return the advancement of
|
||||
receiver. */
|
||||
if (nominal)
|
||||
*nominal = NO;
|
||||
return advancement;
|
||||
}
|
||||
|
||||
- copyWithZone: (NSZone *)zone
|
||||
{
|
||||
AFMGlyphInfo *copy;
|
||||
if (NSShouldRetainWithZone(self, zone))
|
||||
copy = RETAIN(self);
|
||||
else
|
||||
{
|
||||
copy = (AFMGlyphInfo*) NSCopyObject (self, 0, zone);
|
||||
copy->name = [name copyWithZone: zone];
|
||||
if (kerning)
|
||||
{
|
||||
copy->kerning = malloc (numOfPairs * sizeof (tPairKerningInfo));
|
||||
memcpy (copy->kerning, kerning,
|
||||
numOfPairs * sizeof (tPairKerningInfo));
|
||||
}
|
||||
}
|
||||
return copy;
|
||||
}
|
||||
|
||||
- mutableCopyWithZone: (NSZone *)zone
|
||||
{
|
||||
AFMGlyphInfo *copy;
|
||||
copy = (AFMGlyphInfo*) NSCopyObject (self, 0, zone);
|
||||
copy->name = [name copyWithZone: zone];
|
||||
if (kerning)
|
||||
{
|
||||
copy->kerning = malloc (numOfPairs * sizeof (tPairKerningInfo));
|
||||
memcpy (copy->kerning, kerning,
|
||||
numOfPairs * sizeof (tPairKerningInfo));
|
||||
}
|
||||
return copy;
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
RELEASE(name);
|
||||
if (kerning)
|
||||
free (kerning);
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (NSString*)name { return name; }
|
||||
- (NSGlyph)code { return code; }
|
||||
- (NSRect)boundingRect { return bbox; }
|
||||
- (NSSize)advancement { return advancement; }
|
||||
- (BOOL)isEncoded { return YES; }
|
||||
|
||||
@end /* AFMGlyphInfo */
|
66
Source/xdps/GNUmakefile
Normal file
66
Source/xdps/GNUmakefile
Normal file
|
@ -0,0 +1,66 @@
|
|||
#
|
||||
# Main makefile for GNUstep Backend xdps
|
||||
#
|
||||
# Copyright (C) 1997 Free Software Foundation, Inc.
|
||||
#
|
||||
# Author: Adam Fedor <fedor@gnu.org>
|
||||
#
|
||||
# This file is part of the GNUstep Backend.
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Library General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This library is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# Library General Public License for more details.
|
||||
#
|
||||
# If you are interested in a warranty or support for this source code,
|
||||
# contact Scott Christley at scottc@net-community.com
|
||||
#
|
||||
# You should have received a copy of the GNU Library General Public
|
||||
# License along with this library; see the file COPYING.LIB.
|
||||
# If not, write to the Free Software Foundation,
|
||||
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
GNUSTEP_INSTALLATION_DIR = $(GNUSTEP_SYSTEM_ROOT)
|
||||
|
||||
GNUSTEP_MAKEFILES = $(GNUSTEP_SYSTEM_ROOT)/Makefiles
|
||||
|
||||
GNUSTEP_LOCAL_ADDITIONAL_MAKEFILES=../../back.make
|
||||
include $(GNUSTEP_MAKEFILES)/common.make
|
||||
|
||||
SUBPROJECT_NAME=xdps
|
||||
|
||||
# The pswrap source files to be compiled
|
||||
xdps_PSWRAP_FILES = \
|
||||
general.psw \
|
||||
drawingfuncs.psw \
|
||||
extensions.psw \
|
||||
fonts.psw
|
||||
|
||||
# The C source files to be compiled
|
||||
xdps_C_FILES = \
|
||||
parseAFM.c
|
||||
|
||||
# The Objective-C source files to be compiled
|
||||
xdps_OBJC_FILES = \
|
||||
AFMFileFontInfo.m \
|
||||
NSDPSContext.m \
|
||||
NSDPSContextOps.m \
|
||||
PXKFontManager.m
|
||||
|
||||
xdps_HEADER_FILES_DIR = ../../Headers/xdps
|
||||
xdps_HEADER_FILES_INSTALL_DIR = gnustep/xdps
|
||||
|
||||
xdps_HEADER_FILES = \
|
||||
NSDPSContext.h
|
||||
|
||||
-include GNUmakefile.preamble
|
||||
|
||||
include $(GNUSTEP_MAKEFILES)/subproject.make
|
||||
|
||||
-include GNUmakefile.postamble
|
||||
|
53
Source/xdps/GNUmakefile.preamble
Normal file
53
Source/xdps/GNUmakefile.preamble
Normal file
|
@ -0,0 +1,53 @@
|
|||
#
|
||||
# GNUmakefile.preamble
|
||||
#
|
||||
# Copyright (C) 2002 Free Software Foundation, Inc.
|
||||
#
|
||||
# Author: Adam Fedor <fedor@gnu.org>
|
||||
#
|
||||
# This file is part of the GNUstep Backend.
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Library General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This library is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# Library General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Library General Public
|
||||
# License along with this library; see the file COPYING.LIB.
|
||||
# If not, write to the Free Software Foundation,
|
||||
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
#
|
||||
# Flags dealing with compiling and linking
|
||||
#
|
||||
|
||||
# Additional flags to pass to the preprocessor
|
||||
GNUSTEP_INSTALL_LIBDIR=$(GNUSTEP_LIBRARIES_ROOT)
|
||||
ADDITIONAL_CPPFLAGS += -Wall $(CONFIG_SYSTEM_DEFS)
|
||||
|
||||
# Additional flags to pass to the Objective-C compiler
|
||||
#ADDITIONAL_OBJCFLAGS =
|
||||
|
||||
# Additional flags to pass to the C compiler
|
||||
#ADDITIONAL_CFLAGS =
|
||||
|
||||
# Additional include directories the compiler should search
|
||||
ADDITIONAL_INCLUDE_DIRS = -I../../Headers \
|
||||
-I../$(GNUSTEP_TARGET_DIR)
|
||||
|
||||
# Additional LDFLAGS to pass to the linker
|
||||
ADDITIONAL_LDFLAGS =
|
||||
|
||||
# Additional library directories the linker should search
|
||||
ADDITIONAL_LIB_DIRS =
|
||||
|
||||
#
|
||||
# Flags dealing with installing and uninstalling
|
||||
#
|
||||
|
||||
|
764
Source/xdps/NSDPSContext.m
Normal file
764
Source/xdps/NSDPSContext.m
Normal file
|
@ -0,0 +1,764 @@
|
|||
/*
|
||||
NSDPSContext.m
|
||||
|
||||
Encapsulation of Display Postscript contexts
|
||||
|
||||
Copyright (C) 1996 Free Software Foundation, Inc.
|
||||
|
||||
Author: Scott Christley <scottc@net-community.com>
|
||||
Date: 1996
|
||||
|
||||
This file is part of the GNUstep GUI Library.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; see the file COPYING.LIB.
|
||||
If not, write to the Free Software Foundation,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
#include <math.h>
|
||||
#include <Foundation/NSString.h>
|
||||
#include <Foundation/NSThread.h>
|
||||
#include <Foundation/NSLock.h>
|
||||
#include <Foundation/NSData.h>
|
||||
#include <Foundation/NSDictionary.h>
|
||||
|
||||
#include <AppKit/NSAffineTransform.h>
|
||||
#include <AppKit/NSView.h>
|
||||
#include <AppKit/NSWindow.h>
|
||||
#include <AppKit/NSWindow.h>
|
||||
#include <AppKit/GSFontInfo.h>
|
||||
|
||||
#include "x11/XGServer.h"
|
||||
#include "xdps/NSDPSContext.h"
|
||||
|
||||
#define BOOL XWINDOWSBOOL
|
||||
#include <DPS/dpsXclient.h>
|
||||
#include <DPS/dpsXshare.h>
|
||||
#undef BOOL
|
||||
|
||||
#ifdef HAVE_WRASTER_H
|
||||
#include "wraster.h"
|
||||
#else
|
||||
#include "x11/wraster.h"
|
||||
#endif
|
||||
|
||||
#include "general.h"
|
||||
#include "extensions.h"
|
||||
#include "drawingfuncs.h"
|
||||
#include "AFMFileFontInfo.h"
|
||||
|
||||
//
|
||||
// DPS exceptions
|
||||
//
|
||||
NSString *DPSPostscriptErrorException = @"DPSPostscriptErrorException";
|
||||
NSString *DPSNameTooLongException = @"DPSNameTooLongException";
|
||||
NSString *DPSResultTagCheckException = @"DPSResultTagCheckException";
|
||||
NSString *DPSResultTypeCheckException = @"DPSResultTypeCheckException";
|
||||
NSString *DPSInvalidContextException = @"DPSInvalidContextException";
|
||||
NSString *DPSSelectException = @"DPSSelectException";
|
||||
NSString *DPSConnectionClosedException = @"DPSConnectionClosedException";
|
||||
NSString *DPSReadException = @"DPSReadException";
|
||||
NSString *DPSWriteException = @"DPSWriteException";
|
||||
NSString *DPSInvalidFDException = @"DPSInvalidFDException";
|
||||
NSString *DPSInvalidTEException = @"DPSInvalidTEException";
|
||||
NSString *DPSInvalidPortException = @"DPSInvalidPortException";
|
||||
NSString *DPSOutOfMemoryException = @"DPSOutOfMemoryException";
|
||||
NSString *DPSCantConnectException = @"DPSCantConnectException";
|
||||
|
||||
#define XDPY (((RContext *)context)->dpy)
|
||||
#define XDRW (((RContext *)context)->drawable)
|
||||
|
||||
enum {
|
||||
A_COEFF = 0,
|
||||
B_COEFF,
|
||||
C_COEFF,
|
||||
D_COEFF,
|
||||
TX_CONS,
|
||||
TY_CONS
|
||||
};
|
||||
|
||||
//
|
||||
// Class variables
|
||||
//
|
||||
static BOOL GNU_CONTEXT_TRACED = NO;
|
||||
static BOOL GNU_CONTEXT_SYNCHRONIZED = NO;
|
||||
|
||||
static NSDPSContext *context_list = nil;
|
||||
static FILE *gstream = NULL;
|
||||
|
||||
/* Text handler for text contexts */
|
||||
static void
|
||||
GNUstepOutputTextProc (DPSContext ctxt, char *buf, long unsigned int count)
|
||||
{
|
||||
/* FIXME: If there's a possibility of having more than one text context
|
||||
we should have some simple hash to determine what stream to write to */
|
||||
if (gstream)
|
||||
fwrite(buf, 1, count, gstream);
|
||||
else
|
||||
DPSDefaultTextBackstop (ctxt, buf, count);
|
||||
}
|
||||
|
||||
/* Text handler for screen contexts */
|
||||
static void
|
||||
GNUstepTextProc (DPSContext ctxt, char *buf, long unsigned int count)
|
||||
{
|
||||
DPSDefaultTextBackstop (ctxt, buf, count);
|
||||
}
|
||||
|
||||
/* Error handler for all types of contexts */
|
||||
static void
|
||||
GNUstepErrorProc (DPSContext ctxt, DPSErrorCode errCode,
|
||||
unsigned arg1, unsigned args)
|
||||
{
|
||||
DPSDefaultErrorProc (ctxt, errCode, arg1, arg1);
|
||||
}
|
||||
|
||||
@interface NSDPSContext (Private)
|
||||
- (void) createDPSContext;
|
||||
- (void) createTextContext;
|
||||
@end
|
||||
|
||||
@implementation NSDPSContext
|
||||
|
||||
+ (void)initialize
|
||||
{
|
||||
if (self == [NSDPSContext class])
|
||||
{
|
||||
// Set initial version
|
||||
[self setVersion: 1];
|
||||
|
||||
GNU_CONTEXT_TRACED = NO;
|
||||
GNU_CONTEXT_SYNCHRONIZED = NO;
|
||||
}
|
||||
}
|
||||
|
||||
/* Initialize AppKit backend */
|
||||
+ (void)initializeBackend
|
||||
{
|
||||
NSDebugLog(@"Initializing GNUstep GUI X/DPS Backend.\n");
|
||||
[NSGraphicsContext setDefaultContextClass: [NSDPSContext class]];
|
||||
[GSFontEnumerator setDefaultClass: [PXKFontEnumerator class]];
|
||||
[GSFontInfo setDefaultClass: [AFMFileFontInfo class]];
|
||||
}
|
||||
|
||||
+ (void) setCurrentContext: (NSGraphicsContext *)aContext
|
||||
{
|
||||
[super setCurrentContext: aContext];
|
||||
DPSSetContext([(NSDPSContext *)aContext xDPSContext]);
|
||||
}
|
||||
|
||||
//
|
||||
// Initializing a Context
|
||||
//
|
||||
- init
|
||||
{
|
||||
return [self initWithContextInfo: nil];
|
||||
}
|
||||
|
||||
- (id) initWithContextInfo: (NSDictionary *)info
|
||||
{
|
||||
NSString *contextType;
|
||||
|
||||
[super initWithContextInfo: info];
|
||||
|
||||
/* A context is only associated with one server. Do not retain
|
||||
the server, however */
|
||||
server = GSCurrentServer();
|
||||
|
||||
chained_parent = nil;
|
||||
chained_child = nil;
|
||||
contextType = [info objectForKey:
|
||||
NSGraphicsContextRepresentationFormatAttributeName];
|
||||
if (contextType && [contextType isEqual: NSGraphicsContextPSFormat])
|
||||
{
|
||||
NSString *path;
|
||||
is_screen_context = NO;
|
||||
error_proc = GNUstepErrorProc;
|
||||
text_proc = GNUstepOutputTextProc;
|
||||
path = [info objectForKey: @"NSOutputFile"];
|
||||
if (path == nil)
|
||||
{
|
||||
NSLog(@"Warning: No path set for stream context, default temp.ps");
|
||||
path = @"temp.ps";
|
||||
}
|
||||
gstream = fopen([path cString], "w");
|
||||
if (gstream == NULL)
|
||||
{
|
||||
NSLog(@"Error: Could not open output path for stream context");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
is_screen_context = YES;
|
||||
error_proc = GNUstepErrorProc;
|
||||
text_proc = GNUstepTextProc;
|
||||
}
|
||||
|
||||
context = [self xrContext];
|
||||
if (is_screen_context && !XDPSExtensionPresent(XDPY))
|
||||
{
|
||||
#if HAVE_DPS_DPSNXARGS_H
|
||||
/* Make it possible for this client to start a DPS NX agent */
|
||||
XDPSNXSetClientArg(XDPSNX_AUTO_LAUNCH, (void *)True);
|
||||
#else
|
||||
NSLog (@"DPS extension not in server!");
|
||||
exit (1);
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* Create the context
|
||||
*/
|
||||
if (is_screen_context)
|
||||
{
|
||||
[self createDPSContext];
|
||||
}
|
||||
else
|
||||
{
|
||||
[self createTextContext];
|
||||
}
|
||||
|
||||
if (dps_context == NULL)
|
||||
{
|
||||
[self dealloc];
|
||||
return nil;
|
||||
}
|
||||
|
||||
/* Add context to global list of contexts */
|
||||
next_context = context_list;
|
||||
context_list = self;
|
||||
|
||||
if (GSDebugSet(@"NSDPSContext") == YES)
|
||||
{
|
||||
NSLog(@"NSDPSContext: Tracing Postscript \n");
|
||||
[self setOutputTraced: YES];
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
DESTROY(chained_child);
|
||||
|
||||
DPSDestroySpace(DPSSpaceFromContext(dps_context));
|
||||
if (is_screen_context == 0)
|
||||
{
|
||||
if (gstream)
|
||||
fclose(gstream);
|
||||
}
|
||||
/* Remove context from global list of contexts */
|
||||
{
|
||||
NSDPSContext *ctxt = context_list, *previous=nil;
|
||||
|
||||
while(ctxt)
|
||||
{
|
||||
if(ctxt == self)
|
||||
break;
|
||||
previous = ctxt;
|
||||
ctxt = ctxt->next_context;
|
||||
}
|
||||
if(!ctxt)
|
||||
NSLog(@"Internal Error: Couldn't find context to delete");
|
||||
else
|
||||
{
|
||||
if(previous)
|
||||
previous->next_context = next_context;
|
||||
else
|
||||
context_list = next_context;
|
||||
}
|
||||
}
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
//
|
||||
// Testing the Drawing Destination
|
||||
//
|
||||
- (BOOL)isDrawingToScreen
|
||||
{
|
||||
return is_screen_context;
|
||||
}
|
||||
|
||||
- (NSDPSContext *)DPSContext
|
||||
{
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)wait
|
||||
{
|
||||
DPSWaitContext (dps_context);
|
||||
}
|
||||
|
||||
+ (void) waitAllContexts
|
||||
{
|
||||
NSDPSContext *ctxt;
|
||||
ctxt = context_list;
|
||||
while(ctxt)
|
||||
{
|
||||
[ctxt wait];
|
||||
ctxt = ctxt->next_context;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Managing Returned Text and Errors
|
||||
//
|
||||
+ (NSString *)stringForDPSError:(const DPSBinObjSeqRec *)error
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (DPSErrorProc)errorProc
|
||||
{
|
||||
return error_proc;
|
||||
}
|
||||
|
||||
- (void)setErrorProc:(DPSErrorProc)proc
|
||||
{
|
||||
error_proc = proc;
|
||||
}
|
||||
|
||||
- (void)setTextProc:(DPSTextProc)proc
|
||||
{
|
||||
text_proc = proc;
|
||||
}
|
||||
|
||||
- (DPSTextProc)textProc
|
||||
{
|
||||
return text_proc;
|
||||
}
|
||||
|
||||
//
|
||||
// Managing Chained Contexts
|
||||
//
|
||||
- (void)setParentContext:(NSDPSContext *)parent
|
||||
{
|
||||
chained_parent = parent;
|
||||
}
|
||||
|
||||
- (void)chainChildContext:(NSDPSContext *)child
|
||||
{
|
||||
if (child)
|
||||
{
|
||||
chained_child = [child retain];
|
||||
[child setParentContext: self];
|
||||
}
|
||||
}
|
||||
|
||||
- (NSDPSContext *)childContext
|
||||
{
|
||||
return chained_child;
|
||||
}
|
||||
|
||||
- (NSDPSContext *)parentContext
|
||||
{
|
||||
return chained_parent;
|
||||
}
|
||||
|
||||
- (void)unchainContext
|
||||
{
|
||||
if (chained_child)
|
||||
{
|
||||
[chained_child setParentContext: nil];
|
||||
[chained_child release];
|
||||
chained_child = nil;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Debugging Aids
|
||||
//
|
||||
+ (BOOL)areAllContextsOutputTraced
|
||||
{
|
||||
return GNU_CONTEXT_TRACED;
|
||||
}
|
||||
|
||||
+ (BOOL)areAllContextsSynchronized
|
||||
{
|
||||
return GNU_CONTEXT_SYNCHRONIZED;
|
||||
}
|
||||
|
||||
+ (void)setAllContextsOutputTraced:(BOOL)flag
|
||||
{
|
||||
GNU_CONTEXT_TRACED = flag;
|
||||
}
|
||||
|
||||
+ (void)setAllContextsSynchronized:(BOOL)flag
|
||||
{
|
||||
GNU_CONTEXT_SYNCHRONIZED = flag;
|
||||
}
|
||||
|
||||
- (BOOL)isOutputTraced
|
||||
{
|
||||
return is_output_traced;
|
||||
}
|
||||
|
||||
- (BOOL)isSynchronized
|
||||
{
|
||||
return is_synchronized;
|
||||
}
|
||||
|
||||
- (void)setOutputTraced:(BOOL)flag
|
||||
{
|
||||
is_output_traced = flag;
|
||||
XDPSChainTextContext(dps_context, flag);
|
||||
}
|
||||
|
||||
- (void)setSynchronized:(BOOL)flag
|
||||
{
|
||||
is_synchronized = flag;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
//
|
||||
// Methods for XWindows implementation
|
||||
//
|
||||
@implementation NSDPSContext (GNUstepXDPS)
|
||||
|
||||
- (Display*)xDisplay
|
||||
{
|
||||
if (is_screen_context)
|
||||
return [(XGServer *)server xDisplay];
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
- (void *) xrContext
|
||||
{
|
||||
if (is_screen_context)
|
||||
return [(XGServer *)server xrContext];
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
- (DPSContext)xDPSContext
|
||||
{
|
||||
return dps_context;
|
||||
}
|
||||
|
||||
- (void)createDPSContext
|
||||
{
|
||||
int x, y, supported;
|
||||
unsigned long valuemask;
|
||||
XGCValues values;
|
||||
|
||||
/* Create a GC for the initial window */
|
||||
values.foreground = ((RContext *)context)->black;
|
||||
values.background = ((RContext *)context)->white;
|
||||
values.function = GXcopy;
|
||||
values.plane_mask = AllPlanes;
|
||||
values.clip_mask = None;
|
||||
valuemask = (GCFunction | GCPlaneMask | GCClipMask
|
||||
| GCForeground|GCBackground);
|
||||
((RContext *)context)->copy_gc =
|
||||
XCreateGC(XDPY, XDRW, valuemask, &values);
|
||||
|
||||
/* Create the context if need be */
|
||||
if (!dps_context)
|
||||
{
|
||||
/* Pass None as the drawable argument; the program will execute correctly
|
||||
but will not render any text or graphics. */
|
||||
dps_context = XDPSCreateSimpleContext(XDPY, None,
|
||||
((RContext *)context)->copy_gc,
|
||||
0, 0,
|
||||
text_proc,
|
||||
error_proc,
|
||||
NULL);
|
||||
if (dps_context == NULL)
|
||||
{
|
||||
NSLog(@"Could not connect to DPS\n");
|
||||
NSLog(@"Trying again...\n");
|
||||
dps_context = XDPSCreateSimpleContext(XDPY, None,
|
||||
((RContext *)context)->copy_gc,
|
||||
0, 0,
|
||||
text_proc,
|
||||
error_proc,
|
||||
NULL);
|
||||
|
||||
if (dps_context == NULL)
|
||||
{
|
||||
NSLog(@"DPS is not available\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
// Make it the active context
|
||||
DPSSetContext(dps_context);
|
||||
XDPSRegisterContext(dps_context, NO);
|
||||
|
||||
// Use pass-through event handling
|
||||
XDPSSetEventDelivery(XDPY, dps_event_pass_through);
|
||||
}
|
||||
|
||||
PSWinitcontext (XGContextFromGC (((RContext *)context)->copy_gc),
|
||||
XDRW, 0, 0);
|
||||
PSWGetTransform (dps_context, ctm, invctm, &x, &y);
|
||||
PSWinitcontext (XGContextFromGC (((RContext *)context)->copy_gc),
|
||||
None, 0, 0);
|
||||
PSWRevision(&dps_revision);
|
||||
|
||||
/* Check for operator extensions */
|
||||
DPSWKnownExtensions(dps_context, &ext_flags);
|
||||
/* Check if composite-related extensions work */
|
||||
/* FIXME: This crashes DPS on some implementations */
|
||||
//DPSWWorkingExtensions(dps_context, &supported);
|
||||
supported = 0;
|
||||
if (supported == 0)
|
||||
ext_flags = (ext_flags
|
||||
& ~(COMPOSITE_EXT | ALPHAIMAGE_EXT | COMPOSITERECT_EXT
|
||||
| DISSOLVE_EXT | READIMAGE_EXT | SETALPHA_EXT));
|
||||
/* FIXME: alphaimage and composite work badly in DGS 5.50. Perhaps when
|
||||
we find a version that works we can put an additional test here. For now,
|
||||
just turn them off.
|
||||
*/
|
||||
ext_flags = (ext_flags & ~(COMPOSITE_EXT | ALPHAIMAGE_EXT | DISSOLVE_EXT ));
|
||||
|
||||
NSDebugLLog(@"NSDPSContext", @"Using DPS Revision: %d\n", dps_revision);
|
||||
NSDebugLLog(@"NSDPSContext", @"DPS Default Matrix: [%f %f %f %f %f %f]\n",
|
||||
ctm[0], ctm[1], ctm[2], ctm[3], ctm[4], ctm[5]);
|
||||
NSDebugLLog(@"NSDPSContext", @"DPS Extensions flags: %d\n", ext_flags);
|
||||
if ([[NSUserDefaults standardUserDefaults] boolForKey: @"DPSDefaultMatrix"]
|
||||
== NO)
|
||||
{
|
||||
NSDebugLog(@"Reseting default matrix\n");
|
||||
ctm[0] /= fabs(ctm[0]);
|
||||
ctm[3] /= fabs(ctm[3]);
|
||||
PSWSetMatrix(ctm);
|
||||
}
|
||||
}
|
||||
|
||||
- (void)createTextContext
|
||||
{
|
||||
if (dps_context)
|
||||
return;
|
||||
|
||||
dps_context = DPSCreateTextContext(text_proc, error_proc);
|
||||
if (dps_context == NULL)
|
||||
{
|
||||
NSLog(@"Could not create DPS text context");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
- (void) flushGraphics
|
||||
{
|
||||
DPSFlushContext(dps_context);
|
||||
XFlush([(XGServer *)server xDisplay]);
|
||||
}
|
||||
|
||||
- (void) _localTransform: (float *)local_ctm inverse: (float *)local_inv
|
||||
offset: (NSPoint *)offset
|
||||
{
|
||||
int x, y;
|
||||
if (local_ctm == NULL || local_inv == NULL)
|
||||
return;
|
||||
PSWGetTransform (dps_context, local_ctm, local_inv, &x, &y);
|
||||
if (offset)
|
||||
{
|
||||
offset->x = x;
|
||||
offset->y = y;
|
||||
}
|
||||
}
|
||||
|
||||
- (NSPoint)userPointFromXPoint:(NSPoint)xPoint
|
||||
{
|
||||
float lctm[6], linv[6];
|
||||
NSPoint offset, userPoint;
|
||||
|
||||
[self _localTransform: lctm inverse: linv offset: &offset];
|
||||
//xPoint.x -= offset.x;
|
||||
//xPoint.y -= offset.y;
|
||||
userPoint.x = linv[A_COEFF] * xPoint.x + linv[C_COEFF] * xPoint.y
|
||||
+ linv[TX_CONS];
|
||||
userPoint.y = linv[B_COEFF] * xPoint.x + linv[D_COEFF] * xPoint.y
|
||||
+ linv[TY_CONS];
|
||||
return userPoint;
|
||||
}
|
||||
|
||||
- (NSPoint)XPointFromUserPoint:(NSPoint)userPoint
|
||||
{
|
||||
float lctm[6], linv[6];
|
||||
NSPoint offset, xPoint;
|
||||
|
||||
[self _localTransform: lctm inverse: linv offset: &offset];
|
||||
xPoint.x = lctm[A_COEFF] * userPoint.x + lctm[C_COEFF] * userPoint.y
|
||||
+ lctm[TX_CONS] + offset.x;
|
||||
xPoint.y = lctm[B_COEFF] * userPoint.x + lctm[D_COEFF] * userPoint.y
|
||||
+ lctm[TY_CONS] + offset.y;
|
||||
xPoint.x = floor (xPoint.x);
|
||||
xPoint.y = floor (xPoint.y);
|
||||
NSDebugLLog(@"CTM", @"Matrix [%f,%f,%f,%f,%f,%f] (%f,%f)\n",
|
||||
lctm[A_COEFF], lctm[B_COEFF], lctm[C_COEFF], lctm[D_COEFF],
|
||||
lctm[TX_CONS], lctm[TY_CONS], offset.x, offset.y);
|
||||
return xPoint;
|
||||
}
|
||||
|
||||
- (NSRect)userRectFromXRect:(NSRect)xrect
|
||||
{
|
||||
float lctm[6], linv[6];
|
||||
float x, y, w, h;
|
||||
|
||||
[self _localTransform: lctm inverse: linv offset: NULL];
|
||||
x = linv[A_COEFF] * NSMinX(xrect) + linv[C_COEFF] * NSMinY(xrect)
|
||||
+ linv[TX_CONS];
|
||||
y = linv[B_COEFF] * NSMinX(xrect) + linv[D_COEFF] * NSMinY(xrect)
|
||||
+ linv[TY_CONS];
|
||||
w = linv[A_COEFF] * NSWidth(xrect) + linv[C_COEFF] * NSHeight(xrect);
|
||||
h = linv[B_COEFF] * NSWidth(xrect) + linv[D_COEFF] * NSHeight(xrect);
|
||||
if (h < 0)
|
||||
y -= h;
|
||||
h = fabs(h);
|
||||
if (w < 0)
|
||||
x -= w;
|
||||
w = fabs(w);
|
||||
return NSMakeRect(x, y, w, h);
|
||||
}
|
||||
|
||||
- (NSRect)XRectFromUserRect:(NSRect)urect
|
||||
{
|
||||
NSPoint offset;
|
||||
float lctm[6], linv[6];
|
||||
float x, y, w, h;
|
||||
|
||||
[self _localTransform: lctm inverse: linv offset: &offset];
|
||||
x = lctm[A_COEFF] * NSMinX(urect) + lctm[C_COEFF] * NSMinY(urect)
|
||||
+ lctm[TX_CONS] + offset.x;
|
||||
y = lctm[B_COEFF] * NSMinX(urect) + lctm[D_COEFF] * NSMinY(urect)
|
||||
+ lctm[TY_CONS] + offset.y;
|
||||
w = lctm[A_COEFF] * NSWidth(urect) + lctm[C_COEFF] * NSHeight(urect);
|
||||
h = lctm[B_COEFF] * NSWidth(urect) + lctm[D_COEFF] * NSHeight(urect);
|
||||
NSDebugLLog(@"CTM", @"Matrix [%f,%f,%f,%f,%f,%f] (%f,%f)\n",
|
||||
lctm[A_COEFF], lctm[B_COEFF], lctm[C_COEFF], lctm[D_COEFF],
|
||||
lctm[TX_CONS], lctm[TY_CONS], offset.x, offset.y);
|
||||
if (h < 0)
|
||||
y += h;
|
||||
h = fabs(floor(h));
|
||||
if (w < 0)
|
||||
x += w;
|
||||
w = fabs(floor(w));
|
||||
x = floor(x);
|
||||
y = floor(y);
|
||||
return NSMakeRect(x, y, w, h);
|
||||
}
|
||||
|
||||
- (op_extensions_t) operatorExtensions
|
||||
{
|
||||
return ext_flags;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation NSDPSContext (NSGraphics)
|
||||
|
||||
/* Optimized drawing functions */
|
||||
- (void) NSRectFillList: (const NSRect *)rects : (int) count
|
||||
{
|
||||
int i;
|
||||
float rectvals[count*4];
|
||||
|
||||
if (count*4 > 65536)
|
||||
{
|
||||
NSLog(@"DPS Rendering Error: RectFillList with > 16384 rects");
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
rectvals[i*4 ] = NSMinX(rects[i]);
|
||||
rectvals[i*4 + 1] = NSMinY(rects[i]);
|
||||
rectvals[i*4 + 2] = NSWidth(rects[i]);
|
||||
rectvals[i*4 + 3] = NSHeight(rects[i]);
|
||||
}
|
||||
PSWRectFillList(rectvals, count*4);
|
||||
}
|
||||
|
||||
- (void) NSRectFillListWithGrays: (const NSRect *)rects : (const float *)grays
|
||||
:(int) count
|
||||
{
|
||||
#if 1
|
||||
int i;
|
||||
float rectvals[count*5];
|
||||
|
||||
if (count*5 > 65536)
|
||||
{
|
||||
NSLog(@"DPS Rendering Error: RectFillListGray with > 13107 rects");
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
rectvals[i*5 ] = NSMinX(rects[i]);
|
||||
rectvals[i*5 + 1] = NSMinY(rects[i]);
|
||||
rectvals[i*5 + 2] = NSWidth(rects[i]);
|
||||
rectvals[i*5 + 3] = NSHeight(rects[i]);
|
||||
rectvals[i*5 + 4] = grays[i];
|
||||
}
|
||||
PSWRectFillListGray(rectvals, count*5);
|
||||
#else
|
||||
int i, last_gray, tcount;
|
||||
|
||||
PSsetgray(grays[0]);
|
||||
last_gray = grays[0];
|
||||
tcount = 0;
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
if (grays[i] != last_gray)
|
||||
{
|
||||
NSRectFillList(&rects[i-tcount], tcount);
|
||||
tcount = 0;
|
||||
PSsetgray(grays[i]);
|
||||
last_gray = grays[i];
|
||||
}
|
||||
else
|
||||
tcount++;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
- (void) NSDottedFrameRect: (const NSRect) aRect
|
||||
{
|
||||
PSWDottedFrameRect (aRect.origin.x, aRect.origin.y,
|
||||
aRect.size.width, aRect.size.height);
|
||||
}
|
||||
|
||||
- (void) NSFrameRect: (const NSRect) aRect
|
||||
{
|
||||
PSWFrameRect (aRect.origin.x, aRect.origin.y,
|
||||
aRect.size.width, aRect.size.height);
|
||||
}
|
||||
|
||||
- (void) NSFrameRectWithWidth: (const NSRect) aRect : (float) frameWidth
|
||||
{
|
||||
PSWFrameRectWithWidth (aRect.origin.x, aRect.origin.y,
|
||||
aRect.size.width, aRect.size.height, frameWidth);
|
||||
}
|
||||
|
||||
//
|
||||
// Read the Color at a Screen Position
|
||||
//
|
||||
- (NSColor *) NSReadPixel: (NSPoint) location
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
|
||||
|
||||
|
||||
- (void) NSBeep
|
||||
{
|
||||
XBell([(XGServer *)server xDisplay], 50);
|
||||
}
|
||||
|
||||
@end
|
1368
Source/xdps/NSDPSContextOps.m
Normal file
1368
Source/xdps/NSDPSContextOps.m
Normal file
File diff suppressed because it is too large
Load diff
45
Source/xdps/PXKEPSImageRep.m
Normal file
45
Source/xdps/PXKEPSImageRep.m
Normal file
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
PXKEPSImageRep.m
|
||||
|
||||
Copyright (C) 1996 Free Software Foundation, Inc.
|
||||
|
||||
Author: Scott Christley <scottc@net-community.com>
|
||||
Date: March 1996
|
||||
|
||||
This file is part of the GNUstep GUI X/DPS Backend.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; see the file COPYING.LIB.
|
||||
If not, write to the Free Software Foundation,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "xdps/NSDPSContext.h"
|
||||
|
||||
@interface PXKEPSImageRep : NSEPSImageRep
|
||||
{
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation PXKEPSImageRep
|
||||
|
||||
- (Class) classForCoder: aCoder
|
||||
{
|
||||
if ([self class] == [PXKEPSImageRep class])
|
||||
return [super class];
|
||||
return [self class];
|
||||
}
|
||||
|
||||
@end
|
75
Source/xdps/PXKFontManager.m
Normal file
75
Source/xdps/PXKFontManager.m
Normal file
|
@ -0,0 +1,75 @@
|
|||
/*
|
||||
PXKFontEnumerator.m
|
||||
|
||||
NSFontManager helper for GNUstep GUI X/DPS Backend
|
||||
|
||||
Copyright (C) 1996 Free Software Foundation, Inc.
|
||||
|
||||
Author: Ovidiu Predescu <ovidiu@bx.logicnet.ro>
|
||||
Date: February 1997
|
||||
A completely rewritten version of the original source of Scott Christley.
|
||||
|
||||
This file is part of the GNUstep GUI X/DPS Library.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "config.h"
|
||||
|
||||
#include <DPS/psops.h>
|
||||
|
||||
#include <Foundation/NSDictionary.h>
|
||||
#include <Foundation/NSArray.h>
|
||||
#include <Foundation/NSAutoreleasePool.h>
|
||||
#include <Foundation/NSString.h>
|
||||
#include <Foundation/NSSet.h>
|
||||
#include "xdps/NSDPSContext.h"
|
||||
#include "AFMFileFontInfo.h"
|
||||
#include "general.h"
|
||||
#include "fonts.h"
|
||||
|
||||
@implementation PXKFontEnumerator
|
||||
|
||||
/* It would be probably more portable to use the standard PS resource
|
||||
enumerator functions, but the makepsres utility does not understand how
|
||||
DGS organize its resources. So we use the below techniques to identify
|
||||
the font and AFM files.
|
||||
|
||||
For Adobe DPS implementations I use the PS resources because it's more
|
||||
portable.
|
||||
*/
|
||||
|
||||
- (void)enumerateFontsAndFamilies
|
||||
{
|
||||
int count, length;
|
||||
DPSContext ctxt;
|
||||
NSArray *fontList;
|
||||
NSMutableData *data;
|
||||
|
||||
ctxt = [(NSDPSContext *)GSCurrentContext() xDPSContext];
|
||||
|
||||
PSWEnumerateFonts(ctxt, "*", &count, &length);
|
||||
NSDebugLLog(@"Fonts", @"FontManager found %d font names\n", count);
|
||||
data = [NSMutableData dataWithLength: count+length];
|
||||
PSWGetFontList(ctxt, count+length, (char *)[data mutableBytes]);
|
||||
fontList = [[[NSString alloc] initWithData: data encoding: NSASCIIStringEncoding]
|
||||
componentsSeparatedByString: @" "];
|
||||
allFontNames = RETAIN(fontList);
|
||||
// FIXME Enumeration of font families is missing
|
||||
allFontFamilies = nil;
|
||||
}
|
||||
|
||||
@end
|
64
Source/xdps/drawingfuncs.psw
Normal file
64
Source/xdps/drawingfuncs.psw
Normal file
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
drawingfuncs.psw
|
||||
|
||||
Support functions for the C drawing functions defined in OpenStep.
|
||||
|
||||
Copyright (C) 1996,2001 Free Software Foundation, Inc.
|
||||
|
||||
Author: Ovidiu Predescu <ovidiu@bx.logicnet.ro>
|
||||
Date: January 1997
|
||||
Rewritten: Adam Fedor <fedor@gnu.org>
|
||||
Date: May 2001
|
||||
|
||||
This file is part of the GNUstep GUI X/DPS Library.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
|
||||
*/
|
||||
|
||||
#include <DPS/dpsclient.h>
|
||||
|
||||
defineps PSWFrameRectWithWidth (float x, y, w, h, linewidth)
|
||||
linewidth setlinewidth
|
||||
0 setgray
|
||||
x y w h rectstroke
|
||||
endps
|
||||
|
||||
defineps PSWFrameRect (float x, y, w, h)
|
||||
1 setlinewidth
|
||||
0 setgray
|
||||
x y w h rectstroke
|
||||
endps
|
||||
|
||||
defineps PSWDottedFrameRect (float x, y, w, h)
|
||||
1 setlinewidth
|
||||
[1] 0 setdash
|
||||
0 setgray
|
||||
x y w h rectstroke
|
||||
endps
|
||||
|
||||
/* Optimized drawing of a list of rectangles. The list consists of
|
||||
sucessive 4-tuples of rectangle values x, y, w, and h. Note that the
|
||||
number of rectangles cannot exceed 65536/4 = 16384 */
|
||||
defineps PSWRectFillList (float numstring rectvals[x]; int x)
|
||||
rectvals rectfill
|
||||
endps
|
||||
|
||||
/* Optimized drawing of a list of rectangles with different gray
|
||||
values. The list consists of
|
||||
sucessive 5-tuples of rectangle values x, y, w, h, and gray. Note that the
|
||||
number of rectangles cannot exceed 65536/5 = 13107 */
|
||||
defineps PSWRectFillListGray (float rectvals[x]; int x)
|
||||
mark rectvals {counttomark 4 gt {setgray rectfill} if} forall pop
|
||||
endps
|
103
Source/xdps/extensions.psw
Normal file
103
Source/xdps/extensions.psw
Normal file
|
@ -0,0 +1,103 @@
|
|||
/*
|
||||
general.psw
|
||||
|
||||
Copyright (C) 2000 Free Software Foundation, Inc.
|
||||
|
||||
Author: Adam Fedor <fedor@gnu.org>
|
||||
Date: May 2000
|
||||
|
||||
This file is part of the GNUstep GUI X/DPS Library.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
|
||||
*/
|
||||
|
||||
#include <DPS/dpsclient.h>
|
||||
|
||||
defineps DPSWKnownExtensions (DPSContext ctxt | int *extflag)
|
||||
|
||||
0
|
||||
systemdict /alphaimage known {1 add} if
|
||||
systemdict /composite known {2 add} if
|
||||
systemdict /compositerect known {4 add} if
|
||||
systemdict /dissolve known {8 add} if
|
||||
systemdict /readimage known {16 add} if
|
||||
systemdict /setalpha known {32 add} if
|
||||
systemdict /flushpage known {64 add} if
|
||||
extflag
|
||||
|
||||
endps
|
||||
|
||||
defineps DPSWWorkingExtensions(DPSContext ctxt | boolean *supported)
|
||||
|
||||
{
|
||||
0 0 10 10 null 10 10 2 composite
|
||||
} stopped not
|
||||
supported
|
||||
|
||||
endps
|
||||
|
||||
/* Define our own versions of NeXT extension wrappers since they
|
||||
aren't neccesarily in the DPS library
|
||||
*/
|
||||
|
||||
defineps PSWalphaimage ()
|
||||
alphaimage
|
||||
endps
|
||||
|
||||
defineps PSWcomposite (float x, y, w, h; int gstateNum; float dx, dy; int op)
|
||||
x y w h
|
||||
gstateNum dup 0 eq {null} {execuserobject} ifelse
|
||||
dx dy op composite
|
||||
endps
|
||||
|
||||
defineps PSWcompositerect (float x, y, w, h; int op)
|
||||
x y w h op compositerect
|
||||
endps
|
||||
|
||||
defineps PSWdissolve (float x, y, w, h; int gstateNum; float dx, dy, delta)
|
||||
x y w h
|
||||
gstateNum dup 0 eq {null} {execuserobject} ifelse
|
||||
dx dy delta dissolve
|
||||
endps
|
||||
|
||||
defineps PSWreadimage ()
|
||||
readimage
|
||||
endps
|
||||
|
||||
defineps PSWsetalpha (float alpha)
|
||||
alpha setalpha
|
||||
endps
|
||||
|
||||
defineps PSWcurrentalpha (| float *alpha)
|
||||
currentalpha alpha
|
||||
endps
|
||||
|
||||
defineps PSWflushpage ()
|
||||
flushpage
|
||||
endps
|
||||
|
||||
/* Image helper wrappers */
|
||||
|
||||
defineps PSWColorImageHeader(int width, height, bps, spp)
|
||||
width height bps
|
||||
[width 0 0 height neg 0 height]
|
||||
currentfile false spp colorimage
|
||||
endps
|
||||
|
||||
defineps PSWImageHeader(int width, height, bps)
|
||||
width height bps
|
||||
[width 0 0 height neg 0 height]
|
||||
currentfile image
|
||||
endps
|
165
Source/xdps/fonts.psw
Normal file
165
Source/xdps/fonts.psw
Normal file
|
@ -0,0 +1,165 @@
|
|||
/*
|
||||
fonts.psw
|
||||
|
||||
Support functions to determine the installed fonts.
|
||||
|
||||
Copyright (C) 1996 Free Software Foundation, Inc.
|
||||
|
||||
Author: Ovidiu Predescu <ovidiu@bx.logicnet.ro>
|
||||
Date: February 1997
|
||||
|
||||
This file is part of the GNUstep GUI X/DPS Library.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
|
||||
*/
|
||||
|
||||
#include <DPS/dpsclient.h>
|
||||
|
||||
/* These next two procedues are meant to be used together. They find all font
|
||||
names and then fills an array with those names
|
||||
*/
|
||||
defineps PSWEnumerateFonts(DPSContext ctxt; char *pattern |
|
||||
int *count; int *total_length)
|
||||
0 0 % count total_length
|
||||
(pattern) {
|
||||
dup length string cvs % fonts count total_length newfont
|
||||
3 1 roll % fonts newfont count total_length
|
||||
exch 1 add exch % fonts newfont newcount total_length
|
||||
2 index length add % fonts newfont newcount newtotal_length
|
||||
} 256 string /Font resourceforall
|
||||
total_length dup count
|
||||
% fonts count
|
||||
endps
|
||||
|
||||
defineps PSWGetFontList(DPSContext ctxt; int length |
|
||||
char fontNames[length])
|
||||
% fonts count
|
||||
{
|
||||
fontNames ( ) fontNames
|
||||
} repeat
|
||||
endps
|
||||
|
||||
/* The mapping between font names and file name is DPS dependent. On NeXTSTEP
|
||||
for example (and on systems conforming to red book), you can find out the
|
||||
filename where a font is defined like below:
|
||||
|
||||
/Font /Category findresource
|
||||
begin
|
||||
/Times-Roman 1024 string ResourceFileName
|
||||
end
|
||||
|
||||
This pushes on the stack %font%Times-Roman. The program should search in
|
||||
the standard places a directory called `Times-Roman.font' to determine the
|
||||
definition of the font.
|
||||
*/
|
||||
defineps PSWGetFontFile(DPSContext ctxt; char *fontn | char *filen)
|
||||
/Font /Category findresource
|
||||
begin
|
||||
/fontn 1024 string ResourceFileName
|
||||
end
|
||||
filen
|
||||
endps
|
||||
|
||||
/* Procedure for finding font file with GS. */
|
||||
defineps PSWGSFontFile(DPSContext ctxt; char *fontn | char *filen)
|
||||
|
||||
userdict /Fontmap get % Get the Fontmap dictionary
|
||||
/fontn get % Lookup the desired font
|
||||
aload pop % Filename is stored in an array
|
||||
dup type (test string) type ne % If fontn was just an alias
|
||||
{ % Get the real file name
|
||||
userdict /Fontmap get exch get
|
||||
aload pop
|
||||
} if
|
||||
filen
|
||||
|
||||
endps
|
||||
|
||||
/* PSWFontNames() puts on the PS stack a sequence of two elements pairs and
|
||||
returns the number of the total elements. Each pair of elements consists
|
||||
from the name of the font and either the filename where the font is defined
|
||||
or the name of the font whose alias is. To get each pair of elements call
|
||||
the PSWGetNextFont() function.
|
||||
|
||||
Note: This procedure depends on DGS. The function to be used on a DPS system
|
||||
conforming to red book should use the following statements to find out the
|
||||
font names:
|
||||
|
||||
/fonts [
|
||||
(%font%*) {100 string copy} 100 string filenameforall
|
||||
] def
|
||||
|
||||
The mapping between font names and file name is DPS dependent. On NeXTSTEP
|
||||
for example (and on systems conforming to red book), you can find out the
|
||||
filename where a font is defined like below:
|
||||
|
||||
/Font /Category findresource
|
||||
begin
|
||||
/Times-Roman 1024 string ResourceFileName
|
||||
end
|
||||
|
||||
This pushes on the stack %font%Times-Roman. The program should search in
|
||||
the standard places a directory called `Times-Roman.font' to determine the
|
||||
definition of the font.
|
||||
|
||||
Maybe we should place in Postscript all the DPS dependencies and present to
|
||||
the program the same interface.
|
||||
*/
|
||||
|
||||
defineps PSWFontNames (| int* noOfFonts)
|
||||
mark
|
||||
/temp 1024 string def
|
||||
userdict /Fontmap get {
|
||||
/filename exch
|
||||
% In 3.53 the filename was passed as name; in 4.03 it is passed
|
||||
% as an array that contains the file name
|
||||
dup type /arraytype eq {aload pop} if
|
||||
temp cvs dup length string copy
|
||||
def
|
||||
/fontname exch temp cvs dup length string copy def
|
||||
fontname filename
|
||||
}
|
||||
forall
|
||||
counttomark 2 idiv noOfFonts
|
||||
endps
|
||||
|
||||
defineps PSWGetFontsArray (| char *fontname, *fileOrFont)
|
||||
fileOrFont fontname
|
||||
endps
|
||||
|
||||
|
||||
/* PSWCompleteFilename() returns the complete path to the filename passed as
|
||||
argument. The file is searched in the standard DGS places. */
|
||||
defineps PSWCompleteFilename (char* filename; | boolean *found; char* completePath)
|
||||
(filename) findlibfile
|
||||
{closefile completePath true found} {false found pop} ifelse
|
||||
endps
|
||||
|
||||
|
||||
defineps PSWGetFontAndType (| char* fontname; int* fonttype)
|
||||
fontname fonttype
|
||||
endps
|
||||
|
||||
|
||||
/* Set the current font */
|
||||
defineps PSWSetFont (char* font; float fontMatrix[6])
|
||||
(font) findfont fontMatrix makefont setfont
|
||||
endps
|
||||
|
||||
|
||||
/* Get the font type */
|
||||
defineps PSWGetFontType (char* font; | int* fontType)
|
||||
(font) findfont /FontType get fontType
|
||||
endps
|
65
Source/xdps/general.psw
Normal file
65
Source/xdps/general.psw
Normal file
|
@ -0,0 +1,65 @@
|
|||
/*
|
||||
general.psw
|
||||
|
||||
Copyright (C) 1996 Free Software Foundation, Inc.
|
||||
|
||||
Author: Ovidiu Predescu <ovidiu@net-community.com>
|
||||
Date: August 1997
|
||||
|
||||
This file is part of the GNUstep GUI X/DPS Library.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
|
||||
*/
|
||||
|
||||
#include <DPS/dpsclient.h>
|
||||
|
||||
/* Initialize the graphic context */
|
||||
defineps PSWinitcontext (int gc, drawable, x, y)
|
||||
gc drawable x y setXgcdrawable
|
||||
initmatrix initclip
|
||||
gsave initgraphics currenttransfer grestore settransfer
|
||||
endps
|
||||
|
||||
|
||||
defineps PSWGetTransform (DPSContext ctxt | float ctm[6], invctm[6];
|
||||
int *XOffset, *YOffset)
|
||||
matrix currentmatrix dup ctm
|
||||
matrix invertmatrix invctm
|
||||
currentXoffset YOffset XOffset
|
||||
endps
|
||||
|
||||
|
||||
defineps PSWConcatMatrix (float matrix[6])
|
||||
matrix concat
|
||||
endps
|
||||
|
||||
defineps PSWSetMatrix (float matrix[6])
|
||||
matrix setmatrix
|
||||
endps
|
||||
|
||||
defineps PSWVersion (| char* versionstr)
|
||||
version versionstr
|
||||
endps
|
||||
|
||||
defineps PSWRevision (| int* revstr)
|
||||
revision revstr
|
||||
endps
|
||||
|
||||
defineps PSWProduct (| char* productname)
|
||||
product productname
|
||||
endps
|
||||
|
||||
|
||||
|
1138
Source/xdps/parseAFM.c
Normal file
1138
Source/xdps/parseAFM.c
Normal file
File diff suppressed because it is too large
Load diff
324
Source/xdps/parseAFM.h
Normal file
324
Source/xdps/parseAFM.h
Normal file
|
@ -0,0 +1,324 @@
|
|||
/*
|
||||
* parseAFM.h,v
|
||||
*
|
||||
* (c) Copyright 1991-1994 Adobe Systems Incorporated.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission to use, copy, modify, distribute, and sublicense this software
|
||||
* and its documentation for any purpose and without fee is hereby granted,
|
||||
* provided that the above copyright notices appear in all copies and that
|
||||
* both those copyright notices and this permission notice appear in
|
||||
* supporting documentation and that the name of Adobe Systems Incorporated
|
||||
* not be used in advertising or publicity pertaining to distribution of the
|
||||
* software without specific, written prior permission. No trademark license
|
||||
* to use the Adobe trademarks is hereby granted. If the Adobe trademark
|
||||
* "Display PostScript"(tm) is used to describe this software, its
|
||||
* functionality or for any other purpose, such use shall be limited to a
|
||||
* statement that this software works in conjunction with the Display
|
||||
* PostScript system. Proper trademark attribution to reflect Adobe's
|
||||
* ownership of the trademark shall be given whenever any such reference to
|
||||
* the Display PostScript system is made.
|
||||
*
|
||||
* ADOBE MAKES NO REPRESENTATIONS ABOUT THE SUITABILITY OF THE SOFTWARE FOR
|
||||
* ANY PURPOSE. IT IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
|
||||
* ADOBE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NON- INFRINGEMENT OF THIRD PARTY RIGHTS. IN NO EVENT SHALL ADOBE BE LIABLE
|
||||
* TO YOU OR ANY OTHER PARTY FOR ANY SPECIAL, INDIRECT, OR CONSEQUENTIAL
|
||||
* DAMAGES OR ANY DAMAGES WHATSOEVER WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE, STRICT LIABILITY OR ANY OTHER ACTION ARISING OUT OF OR IN
|
||||
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ADOBE WILL NOT
|
||||
* PROVIDE ANY TRAINING OR OTHER SUPPORT FOR THE SOFTWARE.
|
||||
*
|
||||
* Adobe, PostScript, and Display PostScript are trademarks of Adobe Systems
|
||||
* Incorporated which may be registered in certain jurisdictions
|
||||
*
|
||||
* Author: Adobe Systems Incorporated
|
||||
*/
|
||||
|
||||
/***************************************************************
|
||||
**
|
||||
** This header file is used in conjuction with the parseAFM.c file.
|
||||
** Together these files provide the functionality to parse Adobe Font
|
||||
** Metrics files and store the information in predefined data structures.
|
||||
** It is intended to work with an application program that needs font metric
|
||||
** information. The program can be used as is by making a procedure call to
|
||||
** parse an AFM file and have the data stored, or an application developer
|
||||
** may wish to customize the code.
|
||||
**
|
||||
** This header file defines the data structures used as well as the key
|
||||
** strings that are currently recognized by this version of the AFM parser.
|
||||
** This program is based on the document "Adobe Font Metrics Files,
|
||||
** Specification Version 2.0".
|
||||
**
|
||||
** AFM files are separated into distinct sections of different data. Because
|
||||
** of this, the parseAFM program can parse a specified file to only save
|
||||
** certain sections of information based on the application's needs. A record
|
||||
** containing the requested information will be returned to the application.
|
||||
**
|
||||
** AFM files are divided into five sections of data:
|
||||
** 1) The Global Font Information
|
||||
** 2) The Character Metrics Information
|
||||
** 3) The Track Kerning Data
|
||||
** 4) The Pair-Wise Kerning Data
|
||||
** 5) The Composite Character Data
|
||||
**
|
||||
** Basically, the application can request any of these sections independent
|
||||
** of what other sections are requested. In addition, in recognizing that
|
||||
** many applications will want ONLY the x-width of characters and not all
|
||||
** of the other character metrics information, there is a way to receive
|
||||
** only the width information so as not to pay the storage cost for the
|
||||
** unwanted data. An application should never request both the
|
||||
** "quick and dirty" char metrics (widths only) and the Character Metrics
|
||||
** Information since the Character Metrics Information will contain all
|
||||
** of the character widths as well.
|
||||
**
|
||||
** There is a procedure in parseAFM.c, called parseFile, that can be
|
||||
** called from any application wishing to get information from the AFM File.
|
||||
** This procedure expects 3 parameters: a vaild file descriptor, a pointer
|
||||
** to a (AFMFontInfo *) variable (for which space will be allocated and then
|
||||
** will be filled in with the data requested), and a mask specifying
|
||||
** which data from the AFM File should be saved in the AFMFontInfo structure.
|
||||
**
|
||||
** The flags that can be used to set the appropriate mask are defined below.
|
||||
** In addition, several commonly used masks have already been defined.
|
||||
**
|
||||
** History:
|
||||
** original: DSM Thu Oct 20 17:39:59 PDT 1988
|
||||
** modified: DSM Mon Jul 3 14:17:50 PDT 1989
|
||||
** - added 'storageProblem' return code
|
||||
** - fixed typos
|
||||
**
|
||||
**************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
/*
|
||||
** Flags that can be AND'ed together to specify exactly what
|
||||
** information from the AFM file should be saved.
|
||||
*/
|
||||
#define AFM_G 0x01 /* 0000 0001 */ /* Global Font Info */
|
||||
#define AFM_W 0x02 /* 0000 0010 */ /* Character Widths ONLY */
|
||||
#define AFM_M 0x06 /* 0000 0110 */ /* All Char Metric Info */
|
||||
#define AFM_P 0x08 /* 0000 1000 */ /* Pair Kerning Info */
|
||||
#define AFM_T 0x10 /* 0001 0000 */ /* Track Kerning Info */
|
||||
#define AFM_C 0x20 /* 0010 0000 */ /* Composite Char Info */
|
||||
|
||||
/*
|
||||
** Commonly used flags
|
||||
*/
|
||||
#define AFM_GW (AFM_G | AFM_W)
|
||||
#define AFM_GM (AFM_G | AFM_M)
|
||||
#define AFM_GMP (AFM_G | AFM_M | AFM_P)
|
||||
#define AFM_GMK (AFM_G | AFM_M | AFM_P | AFM_T)
|
||||
#define AFM_ALL (AFM_G | AFM_M | AFM_P | AFM_T | AFM_C)
|
||||
|
||||
/*
|
||||
** Possible return codes from the AFMParseFile procedure.
|
||||
**
|
||||
** afm_ok means there were no problems parsing the file.
|
||||
**
|
||||
** afm_parseError means that there was some kind of parsing error, but the
|
||||
** parser went on. This could include problems like the count for any given
|
||||
** section does not add up to how many entries there actually were, or
|
||||
** there was a key that was not recognized. The return record may contain
|
||||
** vaild data or it may not.
|
||||
**
|
||||
** afm_earlyEOF means that an End of File was encountered before expected. This
|
||||
** may mean that the AFM file had been truncated, or improperly formed.
|
||||
**
|
||||
** afm_storageProblem means that there were problems allocating storage for
|
||||
** the data structures that would have contained the AFM data.
|
||||
*/
|
||||
#define afm_ok 0
|
||||
#define afm_parseError -1
|
||||
#define afm_earlyEOF -2
|
||||
#define afm_storageProblem -3
|
||||
|
||||
/************************* TYPES ********************************/
|
||||
/*
|
||||
** Below are all of the data structure definitions. These structures
|
||||
** try to map as closely as possible to grouping and naming of data
|
||||
** in the AFM Files.
|
||||
*/
|
||||
|
||||
/*
|
||||
** Bounding box definition. Used for the Font BBox as well as the
|
||||
** Character BBox.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
int llx; /* lower left x-position */
|
||||
int lly; /* lower left y-position */
|
||||
int urx; /* upper right x-position */
|
||||
int ury; /* upper right y-position */
|
||||
} AFMBBox;
|
||||
|
||||
/*
|
||||
** Global Font information.
|
||||
** The key that each field is associated with is in comments. For an
|
||||
** explanation about each key and its value please refer to the AFM
|
||||
** documentation (full title & version given above).
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
char *afmVersion; /* key: StartFontMetrics */
|
||||
char *fontName; /* key: FontName */
|
||||
char *fullName; /* key: FullName */
|
||||
char *familyName; /* key: FamilyName */
|
||||
char *weight; /* key: Weight */
|
||||
float italicAngle; /* key: ItalicAngle */
|
||||
int isFixedPitch; /* key: IsFixedPitch */
|
||||
AFMBBox fontBBox; /* key: FontBBox */
|
||||
int underlinePosition; /* key: UnderlinePosition */
|
||||
int underlineThickness; /* key: UnderlineThickness */
|
||||
char *version; /* key: Version */
|
||||
char *notice; /* key: Notice */
|
||||
char *encodingScheme; /* key: EncodingScheme */
|
||||
int capHeight; /* key: CapHeight */
|
||||
int xHeight; /* key: XHeight */
|
||||
int ascender; /* key: Ascender */
|
||||
int descender; /* key: Descender */
|
||||
} AFMGlobalFontInfo;
|
||||
|
||||
/*
|
||||
** Ligature definition is a linked list since any character can have
|
||||
** any number of ligatures.
|
||||
*/
|
||||
typedef struct _t_ligature
|
||||
{
|
||||
char *succ, *lig;
|
||||
struct _t_ligature *next;
|
||||
} AFMLigature;
|
||||
|
||||
/*
|
||||
** Character Metric Information. This structure is used only if ALL
|
||||
** character metric information is requested. If only the character
|
||||
** widths is requested, then only an array of the character x-widths
|
||||
** is returned.
|
||||
**
|
||||
** The key that each field is associated with is in comments. For an
|
||||
** explanation about each key and its value please refer to the
|
||||
** Character Metrics section of the AFM documentation (full title
|
||||
** & version given above).
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
int code, /* key: C */
|
||||
wx, /* key: WX */
|
||||
wy; /* together wx and wy are associated with key: W */
|
||||
char *name; /* key: N */
|
||||
AFMBBox charBBox; /* key: B */
|
||||
AFMLigature *ligs; /* key: L (linked list; not a fixed number of Ls */
|
||||
} AFMCharMetricInfo;
|
||||
|
||||
/*
|
||||
** Track kerning data structure.
|
||||
** The fields of this record are the five values associated with every
|
||||
** TrackKern entry.
|
||||
**
|
||||
** For an explanation about each value please refer to the
|
||||
** Track Kerning section of the AFM documentation (full title
|
||||
** & version given above).
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
int degree;
|
||||
float minPtSize,
|
||||
minKernAmt,
|
||||
maxPtSize,
|
||||
maxKernAmt;
|
||||
} AFMTrackKernData;
|
||||
|
||||
/*
|
||||
** Pair Kerning data structure.
|
||||
** The fields of this record are the four values associated with every
|
||||
** KP entry. For KPX entries, the yamt will be zero.
|
||||
**
|
||||
** For an explanation about each value please refer to the
|
||||
** Pair Kerning section of the AFM documentation (full title
|
||||
** & version given above).
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
char *name1;
|
||||
char *name2;
|
||||
int xamt,
|
||||
yamt;
|
||||
} AFMPairKernData;
|
||||
|
||||
/*
|
||||
** PCC is a piece of a composite character. This is a sub structure of a
|
||||
** compCharData described below.
|
||||
** These fields will be filled in with the values from the key PCC.
|
||||
**
|
||||
** For an explanation about each key and its value please refer to the
|
||||
** Composite Character section of the AFM documentation (full title
|
||||
** & version given above).
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
char *pccName;
|
||||
int deltax,
|
||||
deltay;
|
||||
} AFMPcc;
|
||||
|
||||
/*
|
||||
** Composite Character Information data structure.
|
||||
** The fields ccName and numOfPieces are filled with the values associated
|
||||
** with the key CC. The field pieces points to an array (size = numOfPieces)
|
||||
** of information about each of the parts of the composite character. That
|
||||
** array is filled in with the values from the key PCC.
|
||||
**
|
||||
** For an explanation about each key and its value please refer to the
|
||||
** Composite Character section of the AFM documentation (full title
|
||||
** & version given above).
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
char *ccName;
|
||||
int numOfPieces;
|
||||
AFMPcc *pieces;
|
||||
} AFMCompCharData;
|
||||
|
||||
/*
|
||||
** AFMFontInfo
|
||||
** Record type containing pointers to all of the other data
|
||||
** structures containing information about a font.
|
||||
** A a record of this type is filled with data by the
|
||||
** parseFile function.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
AFMGlobalFontInfo *gfi; /* ptr to a GlobalAFMFontInfo record */
|
||||
float *cwi; /* ptr to 256 element array of char widths */
|
||||
int numOfChars; /* number of entries in char metrics array */
|
||||
AFMCharMetricInfo *cmi; /* ptr to char metrics array */
|
||||
int numOfTracks; /* number to entries in track kerning array */
|
||||
AFMTrackKernData *tkd; /* ptr to track kerning array */
|
||||
int numOfPairs; /* number to entries in pair kerning array */
|
||||
AFMPairKernData *pkd; /* ptr to pair kerning array */
|
||||
int numOfComps; /* number to entries in comp char array */
|
||||
AFMCompCharData *ccd; /* ptr to comp char array */
|
||||
} AFMFontInfo;
|
||||
|
||||
/************************* PROCEDURES ***************************/
|
||||
|
||||
/*
|
||||
** Call this procedure to do the grunt work of parsing an AFM file.
|
||||
**
|
||||
** "fp" should be a valid file pointer to an AFM file.
|
||||
**
|
||||
** "fi" is a pointer to a pointer to a AFMFontInfo record sturcture
|
||||
** (defined above). Storage for the AFMFontInfo structure will be
|
||||
** allocated in parseFile and the structure will be filled in
|
||||
** with the requested data from the AFM File.
|
||||
**
|
||||
** "flags" is a mask with bits set representing what data should
|
||||
** be saved. Defined above are valid flags that can be used to set
|
||||
** the mask, as well as a few commonly used masks.
|
||||
**
|
||||
** The possible return codes from AFMParseFile are defined above.
|
||||
*/
|
||||
|
||||
extern int AFMParseFile ( /* FILE *fp; AFMFontInfo **fi; int flags; */ );
|
73
Source/xlib/GNUmakefile
Normal file
73
Source/xlib/GNUmakefile
Normal file
|
@ -0,0 +1,73 @@
|
|||
#
|
||||
# Main makefile for GNUstep Backend xlib
|
||||
#
|
||||
# Copyright (C) 1997 Free Software Foundation, Inc.
|
||||
#
|
||||
# Author: Adam Fedor <fedor@gnu.org>
|
||||
#
|
||||
# This file is part of the GNUstep Backend.
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Library General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This library is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# Library General Public License for more details.
|
||||
#
|
||||
# If you are interested in a warranty or support for this source code,
|
||||
# contact Scott Christley at scottc@net-community.com
|
||||
#
|
||||
# You should have received a copy of the GNU Library General Public
|
||||
# License along with this library; see the file COPYING.LIB.
|
||||
# If not, write to the Free Software Foundation,
|
||||
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
GNUSTEP_INSTALLATION_DIR = $(GNUSTEP_SYSTEM_ROOT)
|
||||
|
||||
GNUSTEP_MAKEFILES = $(GNUSTEP_SYSTEM_ROOT)/Makefiles
|
||||
|
||||
GNUSTEP_LOCAL_ADDITIONAL_MAKEFILES=../../back.make
|
||||
include $(GNUSTEP_MAKEFILES)/common.make
|
||||
|
||||
include ../../config.make
|
||||
|
||||
SUBPROJECT_NAME=xlib
|
||||
|
||||
# The C source files to be compiled
|
||||
xlib_C_FILES = xrtools.c
|
||||
|
||||
# The Objective-C source files to be compiled
|
||||
xlib_OBJC_FILES = \
|
||||
XGBitmapImageRep.m \
|
||||
XGBitmap.m \
|
||||
XGCommonFont.m \
|
||||
XGFont.m \
|
||||
XGFontManager.m \
|
||||
XGContext.m \
|
||||
XGGState.m \
|
||||
XGGeometry.m \
|
||||
linking.m
|
||||
|
||||
ifeq ($(WITH_XFT),yes)
|
||||
xlib_OBJC_FILES += XftFontInfo.m
|
||||
endif
|
||||
|
||||
xlib_HEADER_FILES_DIR = ../../Headers/xlib
|
||||
xlib_HEADER_FILES_INSTALL_DIR = gnustep/xlib
|
||||
|
||||
xlib_HEADER_FILES = \
|
||||
XGContext.h \
|
||||
XGPrivate.h \
|
||||
XGGeometry.h \
|
||||
XGGState.h \
|
||||
XGGStateOps.h
|
||||
|
||||
-include GNUmakefile.preamble
|
||||
|
||||
include $(GNUSTEP_MAKEFILES)/subproject.make
|
||||
|
||||
-include GNUmakefile.postamble
|
||||
|
53
Source/xlib/GNUmakefile.preamble
Normal file
53
Source/xlib/GNUmakefile.preamble
Normal file
|
@ -0,0 +1,53 @@
|
|||
#
|
||||
# GNUmakefile.preamble
|
||||
#
|
||||
# Copyright (C) 2002 Free Software Foundation, Inc.
|
||||
#
|
||||
# Author: Adam Fedor <fedor@gnu.org>
|
||||
#
|
||||
# This file is part of the GNUstep Backend.
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Library General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This library is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# Library General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Library General Public
|
||||
# License along with this library; see the file COPYING.LIB.
|
||||
# If not, write to the Free Software Foundation,
|
||||
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
#
|
||||
# Flags dealing with compiling and linking
|
||||
#
|
||||
|
||||
# Additional flags to pass to the preprocessor
|
||||
GNUSTEP_INSTALL_LIBDIR=$(GNUSTEP_LIBRARIES_ROOT)
|
||||
ADDITIONAL_CPPFLAGS += -Wall $(CONFIG_SYSTEM_DEFS)
|
||||
|
||||
# Additional flags to pass to the Objective-C compiler
|
||||
#ADDITIONAL_OBJCFLAGS =
|
||||
|
||||
# Additional flags to pass to the C compiler
|
||||
#ADDITIONAL_CFLAGS =
|
||||
|
||||
# Additional include directories the compiler should search
|
||||
ADDITIONAL_INCLUDE_DIRS = -I../../Headers \
|
||||
-I../$(GNUSTEP_TARGET_DIR)
|
||||
|
||||
# Additional LDFLAGS to pass to the linker
|
||||
ADDITIONAL_LDFLAGS =
|
||||
|
||||
# Additional library directories the linker should search
|
||||
ADDITIONAL_LIB_DIRS =
|
||||
|
||||
#
|
||||
# Flags dealing with installing and uninstalling
|
||||
#
|
||||
|
||||
|
1144
Source/xlib/XGBitmap.m
Normal file
1144
Source/xlib/XGBitmap.m
Normal file
File diff suppressed because it is too large
Load diff
169
Source/xlib/XGBitmapImageRep.m
Normal file
169
Source/xlib/XGBitmapImageRep.m
Normal file
|
@ -0,0 +1,169 @@
|
|||
/*
|
||||
XGBitmapImageRep.m
|
||||
|
||||
NSBitmapImageRep for GNUstep GUI X/GPS Backend
|
||||
|
||||
Copyright (C) 1996-1999 Free Software Foundation, Inc.
|
||||
|
||||
Author: Adam Fedor <fedor@colorado.edu>
|
||||
Author: Scott Christley <scottc@net-community.com>
|
||||
Date: Feb 1996
|
||||
Author: Felipe A. Rodriguez <far@ix.netcom.com>
|
||||
Date: May 1998
|
||||
Author: Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
||||
Date: Mar 1999
|
||||
Rewritten: Adam Fedor <fedor@gnu.org>
|
||||
Date: May 2000
|
||||
|
||||
This file is part of the GNUstep GUI X/GPS Backend.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; see the file COPYING.LIB.
|
||||
If not, write to the Free Software Foundation,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
#include <stdlib.h>
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xutil.h>
|
||||
|
||||
#include "xlib/XGContext.h"
|
||||
#include "xlib/xrtools.h"
|
||||
#include "x11/XGServerWindow.h"
|
||||
#include <Foundation/NSData.h>
|
||||
#include <Foundation/NSDebug.h>
|
||||
#include <Foundation/NSUserDefaults.h>
|
||||
#include <AppKit/NSBitmapImageRep.h>
|
||||
#include <AppKit/NSGraphics.h>
|
||||
#include <AppKit/NSImage.h>
|
||||
|
||||
@interface NSBitmapImageRep (BackEnd)
|
||||
- (Pixmap) xPixmapMask;
|
||||
@end
|
||||
|
||||
|
||||
@implementation NSBitmapImageRep (Backend)
|
||||
|
||||
#ifdef WITH_WRASTER
|
||||
+ (NSArray *) _wrasterFileTypes
|
||||
{
|
||||
int i;
|
||||
NSMutableArray *warray;
|
||||
char **types = RSupportedFileFormats();
|
||||
|
||||
i = 0;
|
||||
warray = [NSMutableArray arrayWithCapacity: 4];
|
||||
while (types[i] != NULL)
|
||||
{
|
||||
NSString *type = [NSString stringWithCString: types[i]];
|
||||
type = [type lowercaseString];
|
||||
if (strcmp(types[i], "TIFF") != 0)
|
||||
{
|
||||
[warray addObject: type];
|
||||
if (strcmp(types[i], "JPEG") == 0)
|
||||
[warray addObject: @"jpg"];
|
||||
else if (strcmp(types[i], "PPM") == 0)
|
||||
[warray addObject: @"pgm"];
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return warray;
|
||||
}
|
||||
|
||||
- _initFromWrasterFile: (NSString *)filename number: (int)imageNumber
|
||||
{
|
||||
RImage *image;
|
||||
RContext *context;
|
||||
|
||||
if (imageNumber > 0)
|
||||
{
|
||||
/* RLoadImage doesn't handle this very well */
|
||||
RELEASE(self);
|
||||
return nil;
|
||||
}
|
||||
|
||||
NSDebugLLog(@"NSImage", @"Loading %@ using wraster routines", filename);
|
||||
context = [(XGContext *)GSCurrentContext() xrContext];
|
||||
image = RLoadImage(context, (char *)[filename cString], imageNumber);
|
||||
if (!image)
|
||||
{
|
||||
RELEASE(self);
|
||||
return nil;
|
||||
}
|
||||
[self initWithBitmapDataPlanes: &(image->data)
|
||||
pixelsWide: image->width
|
||||
pixelsHigh: image->height
|
||||
bitsPerSample: 8
|
||||
samplesPerPixel: (image->format == RRGBAFormat) ? 4 : 3
|
||||
hasAlpha: (image->format == RRGBAFormat) ? YES : NO
|
||||
isPlanar: NO
|
||||
colorSpaceName: NSDeviceRGBColorSpace
|
||||
bytesPerRow: 0
|
||||
bitsPerPixel: 0];
|
||||
|
||||
/* Make NSBitmapImageRep own the data */
|
||||
_imageData = [NSMutableData dataWithBytesNoCopy: image->data
|
||||
length: (_bytesPerRow*image->height)];
|
||||
RETAIN(_imageData);
|
||||
free(image);
|
||||
|
||||
return self;
|
||||
}
|
||||
#endif /* WITH_WRASTER */
|
||||
|
||||
- (Pixmap) xPixmapMask
|
||||
{
|
||||
unsigned char *bData;
|
||||
XGContext *ctxt = (XGContext*)GSCurrentContext();
|
||||
Display *xDisplay = [ctxt xDisplay];
|
||||
Drawable xDrawable;
|
||||
GC gc;
|
||||
int x, y;
|
||||
|
||||
// Only produce pixmaps for meshed images with alpha
|
||||
if ((_numColors != 4) || _isPlanar)
|
||||
return 0;
|
||||
|
||||
bData = [self bitmapData];
|
||||
|
||||
[ctxt DPScurrentgcdrawable: (void**)&gc : (void**)&xDrawable : &x : &y];
|
||||
|
||||
// FIXME: This optimistic computing works only, if there are no
|
||||
// additional bytes at the end of a line.
|
||||
return xgps_cursor_mask (xDisplay, xDrawable, bData, _pixelsWide, _pixelsHigh, _numColors);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation NSImage (Backend)
|
||||
|
||||
- (Pixmap) xPixmapMask
|
||||
{
|
||||
NSArray *reps = [self representations];
|
||||
NSEnumerator *enumerator = [reps objectEnumerator];
|
||||
NSImageRep *rep;
|
||||
|
||||
while ((rep = [enumerator nextObject]) != nil)
|
||||
{
|
||||
if ([rep isKindOfClass: [NSBitmapImageRep class]])
|
||||
{
|
||||
return [(NSBitmapImageRep*)rep xPixmapMask];
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@end
|
282
Source/xlib/XGCommonFont.m
Normal file
282
Source/xlib/XGCommonFont.m
Normal file
|
@ -0,0 +1,282 @@
|
|||
/*
|
||||
XGFontInfo
|
||||
|
||||
NSFont helper for GNUstep GUI X/GPS Backend
|
||||
|
||||
Copyright (C) 1996 Free Software Foundation, Inc.
|
||||
|
||||
Author: Scott Christley
|
||||
Author: Ovidiu Predescu <ovidiu@bx.logicnet.ro>
|
||||
Date: February 1997
|
||||
Author: Felipe A. Rodriguez <far@ix.netcom.com>
|
||||
Date: May, October 1998
|
||||
Author: Michael Hanni <mhanni@sprintmail.com>
|
||||
Date: August 1998
|
||||
Author: Fred Kiefer <fredkiefer@gmx.de>
|
||||
Date: September 2000
|
||||
|
||||
This file is part of the GNUstep GUI X/GPS Backend.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; see the file COPYING.LIB.
|
||||
If not, write to the Free Software Foundation,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <X11/Xatom.h>
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xutil.h>
|
||||
#include "xlib/XGContext.h"
|
||||
#include "xlib/XGPrivate.h"
|
||||
#include <Foundation/NSDebug.h>
|
||||
// For the encoding functions
|
||||
#include <base/Unicode.h>
|
||||
|
||||
static Atom XA_SLANT = (Atom)0;
|
||||
static Atom XA_SETWIDTH_NAME = (Atom)0;
|
||||
static Atom XA_CHARSET_REGISTRY = (Atom)0;
|
||||
static Atom XA_CHARSET_ENCODING = (Atom)0;
|
||||
static Atom XA_SPACING = (Atom)0;
|
||||
static Atom XA_PIXEL_SIZE = (Atom)0;
|
||||
static Atom XA_WEIGHT_NAME = (Atom)0;
|
||||
|
||||
/*
|
||||
static Atom XA_RESOLUTION_X = (Atom)0;
|
||||
static Atom XA_RESOLUTION_Y = (Atom)0;
|
||||
static Atom XA_ADD_STYLE_NAME = (Atom)0;
|
||||
static Atom XA_AVERAGE_WIDTH = (Atom)0;
|
||||
static Atom XA_FACE_NAME = (Atom)0;
|
||||
*/
|
||||
|
||||
/*
|
||||
* Initialise the X atoms we are going to use
|
||||
*/
|
||||
static BOOL XGInitAtoms(Display *dpy)
|
||||
{
|
||||
// X atoms used to query a font
|
||||
|
||||
if (!dpy)
|
||||
{
|
||||
NSDebugLog(@"No Display opened in XGInitAtoms");
|
||||
return NO;
|
||||
}
|
||||
|
||||
XA_PIXEL_SIZE = XInternAtom(dpy, "PIXEL_SIZE", False);
|
||||
XA_SPACING = XInternAtom(dpy, "SPACING", False);
|
||||
XA_WEIGHT_NAME = XInternAtom(dpy, "WEIGHT_NAME", False);
|
||||
XA_SLANT = XInternAtom(dpy, "SLANT", False);
|
||||
XA_SETWIDTH_NAME = XInternAtom(dpy, "SETWIDTH_NAME", False);
|
||||
XA_CHARSET_REGISTRY = XInternAtom(dpy, "CHARSET_REGISTRY", False);
|
||||
XA_CHARSET_ENCODING = XInternAtom(dpy, "CHARSET_ENCODING", False);
|
||||
|
||||
/*
|
||||
XA_ADD_STYLE_NAME = XInternAtom(dpy, "ADD_STYLE_NAME", False);
|
||||
XA_RESOLUTION_X = XInternAtom(dpy, "RESOLUTION_X", False);
|
||||
XA_RESOLUTION_Y = XInternAtom(dpy, "RESOLUTION_Y", False);
|
||||
XA_AVERAGE_WIDTH = XInternAtom(dpy, "AVERAGE_WIDTH", False);
|
||||
XA_FACE_NAME = XInternAtom(dpy, "FACE_NAME", False);
|
||||
*/
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
/*
|
||||
* Read an X Font property of type unsigned long
|
||||
*/
|
||||
unsigned long XGFontPropULong(Display *dpy, XFontStruct *font_struct,
|
||||
Atom atom)
|
||||
{
|
||||
unsigned long lvalue;
|
||||
|
||||
if (XGetFontProperty(font_struct, atom, &lvalue))
|
||||
return lvalue;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Read an X Font property of type string
|
||||
*/
|
||||
NSString *XGFontPropString(Display *dpy, XFontStruct *font_struct, Atom atom)
|
||||
{
|
||||
unsigned long lvalue;
|
||||
char *value;
|
||||
NSString *ret = nil;
|
||||
|
||||
if (XGetFontProperty(font_struct, atom, &lvalue) && dpy)
|
||||
{
|
||||
value = XGetAtomName(dpy, lvalue);
|
||||
if (value != NULL)
|
||||
{
|
||||
// We convert all props to lowercase so comparing is easier
|
||||
ret = [[NSString stringWithCString: value] lowercaseString];
|
||||
XFree(value);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
NSString *XGFontName(Display *dpy, XFontStruct *font_struct)
|
||||
{
|
||||
return XGFontPropString(dpy, font_struct, XA_FONT);
|
||||
}
|
||||
|
||||
float XGFontPointSize(Display *dpy, XFontStruct *font_struct)
|
||||
{
|
||||
float size = 12.0;
|
||||
long pointSize;
|
||||
|
||||
if (!XA_PIXEL_SIZE)
|
||||
XGInitAtoms(dpy);
|
||||
|
||||
/*
|
||||
* We use pixel size here not point size, which is about 10 times its size.
|
||||
* Perhaps we will change that later on!
|
||||
*/
|
||||
pointSize = XGFontPropULong(dpy, font_struct, XA_PIXEL_SIZE);
|
||||
if (pointSize != 0)
|
||||
{
|
||||
size = (float) pointSize;
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
BOOL XGFontIsFixedPitch(Display *dpy, XFontStruct *font_struct)
|
||||
{
|
||||
/* Is this font fixed pitch? default, NO */
|
||||
BOOL fixedFont = NO;
|
||||
NSString *spacing;
|
||||
|
||||
// If there is no information per character, all must be equal
|
||||
if (!font_struct->per_char)
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
|
||||
if (!XA_SPACING)
|
||||
XGInitAtoms(dpy);
|
||||
|
||||
/*
|
||||
* We could also check the value of MONOSPACED, but I have never seen it set.
|
||||
*/
|
||||
spacing = XGFontPropString(dpy, font_struct, XA_SPACING);
|
||||
if (spacing != nil)
|
||||
{
|
||||
if ([spacing isEqualToString: @"m"])
|
||||
fixedFont = YES;
|
||||
}
|
||||
|
||||
/*
|
||||
* We could calculate the pitch from the XLFD but that does not seem to be
|
||||
* saved. If we can't get the property, say no and cope.
|
||||
*/
|
||||
return fixedFont;
|
||||
}
|
||||
|
||||
NSString *XGFontFamily(Display *dpy, XFontStruct *font_struct)
|
||||
{
|
||||
NSString *family;
|
||||
|
||||
family = XGFontPropString(dpy, font_struct, XA_FAMILY_NAME);
|
||||
if (family == nil)
|
||||
return @"Unknown"; // FIXME: We should return the font name instead
|
||||
|
||||
return [family capitalizedString];
|
||||
}
|
||||
|
||||
// Get the weight of a X font
|
||||
int XGWeightOfFont(Display *dpy, XFontStruct *info)
|
||||
{
|
||||
int w = 5;
|
||||
NSString *string;
|
||||
|
||||
if (!XA_WEIGHT_NAME)
|
||||
XGInitAtoms(dpy);
|
||||
|
||||
string = XGFontPropString(dpy, info, XA_WEIGHT_NAME);
|
||||
|
||||
if (string != nil)
|
||||
{
|
||||
w = [GSFontInfo weightForString: string];
|
||||
}
|
||||
|
||||
return w;
|
||||
}
|
||||
|
||||
// Get the traits of a X font
|
||||
NSFontTraitMask XGTraitsOfFont(Display *dpy, XFontStruct *info)
|
||||
{
|
||||
NSFontTraitMask mask = 0;
|
||||
NSString *string;
|
||||
int w = XGWeightOfFont(dpy, info);
|
||||
|
||||
if (w >= 9)
|
||||
mask |= NSBoldFontMask;
|
||||
else
|
||||
mask |= NSUnboldFontMask;
|
||||
|
||||
if (XGFontIsFixedPitch(dpy, info))
|
||||
mask |= NSFixedPitchFontMask;
|
||||
|
||||
string = XGFontPropString(dpy, info, XA_SLANT);
|
||||
if (string != nil)
|
||||
{
|
||||
char c = [string cString][0];
|
||||
|
||||
if (c == 'o' || c == 'i')
|
||||
mask |= NSItalicFontMask;
|
||||
else
|
||||
mask |= NSUnitalicFontMask;
|
||||
}
|
||||
|
||||
string = XGFontPropString(dpy, info, XA_CHARSET_REGISTRY);
|
||||
if (string != nil)
|
||||
{
|
||||
if (![string isEqualToString: @"iso8859"] &&
|
||||
![string isEqualToString: @"iso10646"] )
|
||||
mask |= NSNonStandardCharacterSetFontMask;
|
||||
}
|
||||
string = XGFontPropString(dpy, info, XA_CHARSET_ENCODING);
|
||||
if (string != nil)
|
||||
{
|
||||
if (![string isEqualToString: @"1"])
|
||||
mask |= NSNonStandardCharacterSetFontMask;
|
||||
}
|
||||
|
||||
string = XGFontPropString(dpy, info, XA_SETWIDTH_NAME);
|
||||
if (string != nil)
|
||||
{
|
||||
if ([string isEqualToString: @"narrow"])
|
||||
mask |= NSNarrowFontMask;
|
||||
else if ([string isEqualToString: @"semicondensed"])
|
||||
mask |= NSCondensedFontMask;
|
||||
}
|
||||
|
||||
string = XGFontPropString(dpy, info, XA_SPACING);
|
||||
if (string != nil)
|
||||
{
|
||||
if ([string isEqualToString: @"c"])
|
||||
mask |= NSCompressedFontMask;
|
||||
}
|
||||
|
||||
//FIXME: How can I find out about the other traits?
|
||||
/*
|
||||
unsigned long weight = XGFontPropULong(dpy, info, XA_WEIGHT);
|
||||
*/
|
||||
|
||||
return mask;
|
||||
}
|
185
Source/xlib/XGContext.m
Normal file
185
Source/xlib/XGContext.m
Normal file
|
@ -0,0 +1,185 @@
|
|||
/* -*- mode:ObjC -*-
|
||||
XGContext - Drawing context using the Xlib Library.
|
||||
|
||||
Copyright (C) 1998,1999,2002 Free Software Foundation, Inc.
|
||||
|
||||
Written by: Adam Fedor <fedor@boulder.colorado.edu>
|
||||
Date: Nov 1998
|
||||
|
||||
This file is part of the GNU Objective C User Interface Library.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include <AppKit/AppKitExceptions.h>
|
||||
#include <AppKit/NSAffineTransform.h>
|
||||
#include <AppKit/NSColor.h>
|
||||
#include <AppKit/NSView.h>
|
||||
#include <AppKit/NSWindow.h>
|
||||
#include <Foundation/NSException.h>
|
||||
#include <Foundation/NSArray.h>
|
||||
#include <Foundation/NSDictionary.h>
|
||||
#include <Foundation/NSData.h>
|
||||
#include <Foundation/NSValue.h>
|
||||
#include <Foundation/NSString.h>
|
||||
#include <Foundation/NSUserDefaults.h>
|
||||
#include <Foundation/NSDebug.h>
|
||||
|
||||
#include "x11/XGServer.h"
|
||||
#include "xlib/XGContext.h"
|
||||
#include "xlib/XGPrivate.h"
|
||||
#include "xlib/XGGState.h"
|
||||
#include "xlib/xrtools.h"
|
||||
|
||||
#if HAVE_XFT
|
||||
#include "xlib/XftFontInfo.h"
|
||||
#endif
|
||||
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xutil.h>
|
||||
#include <X11/keysym.h>
|
||||
|
||||
/**
|
||||
<unit>
|
||||
<heading>XGContext</heading>
|
||||
<p>
|
||||
The documentation below mostly describes methods that are specific to
|
||||
this backend and wouldn't necessarily be used in other backends. The methods
|
||||
that this class does implement that would need to be in every backend are
|
||||
the methods of its NSGraphicContext superclass. See the documentation
|
||||
for NSGraphicContext for more information.
|
||||
</p>
|
||||
</unit>
|
||||
*/
|
||||
@implementation XGContext
|
||||
|
||||
/* Initialize AppKit backend */
|
||||
+ (void)initializeBackend
|
||||
{
|
||||
Class fontClass = Nil;
|
||||
|
||||
NSDebugLog(@"Initializing GNUstep xlib backend.\n");
|
||||
|
||||
[NSGraphicsContext setDefaultContextClass: [XGContext class]];
|
||||
[GSFontEnumerator setDefaultClass: [XGFontEnumerator class]];
|
||||
|
||||
#if HAVE_XFT
|
||||
if ([[NSUserDefaults standardUserDefaults] boolForKey: @"GSFontAntiAlias"])
|
||||
{
|
||||
fontClass = [XftFontInfo class];
|
||||
}
|
||||
#endif
|
||||
if (fontClass == Nil)
|
||||
{
|
||||
fontClass = [XGFontInfo class];
|
||||
}
|
||||
[GSFontInfo setDefaultClass: fontClass];
|
||||
}
|
||||
|
||||
- (id) initWithContextInfo: (NSDictionary *)info
|
||||
{
|
||||
[super initWithContextInfo: info];
|
||||
|
||||
/* Create a default gstate */
|
||||
gstate = [[XGGState allocWithZone: [self zone]] initWithDrawContext: self];
|
||||
|
||||
drawMechanism = [(XGServer *)server drawMechanism];
|
||||
return self;
|
||||
}
|
||||
|
||||
/**
|
||||
Returns the XGDrawMechanism, which roughly describes the depth of
|
||||
the screen and how pixels should be drawn to the screen for maximum
|
||||
speed.
|
||||
*/
|
||||
- (XGDrawMechanism) drawMechanism
|
||||
{
|
||||
return drawMechanism;
|
||||
}
|
||||
|
||||
/**
|
||||
Returns a pointer to a structure which describes aspects of the
|
||||
X windows display
|
||||
*/
|
||||
- (void *) xrContext
|
||||
{
|
||||
return [(XGServer *)server xrContext];
|
||||
}
|
||||
|
||||
/**
|
||||
Returns a pointer to the X windows display variable
|
||||
*/
|
||||
- (Display *) xDisplay
|
||||
{
|
||||
return [(XGServer *)server xDisplay];
|
||||
}
|
||||
|
||||
- (void) flushGraphics
|
||||
{
|
||||
XFlush([(XGServer *)server xDisplay]);
|
||||
}
|
||||
|
||||
//
|
||||
// Read the Color at a Screen Position
|
||||
//
|
||||
- (NSColor *) NSReadPixel: (NSPoint) location
|
||||
{
|
||||
[self notImplemented: _cmd];
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (void) NSBeep
|
||||
{
|
||||
XBell([(XGServer *)server xDisplay], 50);
|
||||
}
|
||||
|
||||
/* Private backend methods */
|
||||
- (void) contextDevice: (int)num
|
||||
{
|
||||
[(XGGState *)gstate setWindow: num];
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
|
||||
@implementation XGContext (Ops)
|
||||
|
||||
/* ----------------------------------------------------------------------- */
|
||||
/* Window system ops */
|
||||
/* ----------------------------------------------------------------------- */
|
||||
- (void) DPScurrentgcdrawable: (void **)gc : (void **)draw
|
||||
: (int *)x : (int *)y
|
||||
{
|
||||
if (gc)
|
||||
*gc = (void *)[(XGGState *)gstate graphicContext];
|
||||
if (draw)
|
||||
*draw = (void *)[(XGGState *)gstate drawable];
|
||||
if (x && y)
|
||||
{
|
||||
NSPoint offset = [gstate offset];
|
||||
*x = offset.x;
|
||||
*y = offset.y;
|
||||
}
|
||||
}
|
||||
|
||||
- (void) DPSsetgcdrawable: (void *)gc : (void *)draw : (int)x : (int)y
|
||||
{
|
||||
[(XGGState *)gstate setGraphicContext: (GC)gc];
|
||||
[(XGGState *)gstate setDrawable: (Drawable)draw];
|
||||
[gstate setOffset: NSMakePoint(x, y)];
|
||||
}
|
||||
|
||||
@end
|
380
Source/xlib/XGFont.m
Normal file
380
Source/xlib/XGFont.m
Normal file
|
@ -0,0 +1,380 @@
|
|||
/*
|
||||
XGFontInfo
|
||||
|
||||
NSFont helper for GNUstep GUI X/GPS Backend
|
||||
|
||||
Copyright (C) 1996 Free Software Foundation, Inc.
|
||||
|
||||
Author: Scott Christley
|
||||
Author: Ovidiu Predescu <ovidiu@bx.logicnet.ro>
|
||||
Date: February 1997
|
||||
Author: Felipe A. Rodriguez <far@ix.netcom.com>
|
||||
Date: May, October 1998
|
||||
Author: Michael Hanni <mhanni@sprintmail.com>
|
||||
Date: August 1998
|
||||
Author: Fred Kiefer <fredkiefer@gmx.de>
|
||||
Date: September 2000
|
||||
|
||||
This file is part of the GNUstep GUI X/GPS Backend.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; see the file COPYING.LIB.
|
||||
If not, write to the Free Software Foundation,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "xlib/XGContext.h"
|
||||
#include "xlib/XGPrivate.h"
|
||||
#include "xlib/XGGState.h"
|
||||
#include "x11/XGServer.h"
|
||||
#include <Foundation/NSDebug.h>
|
||||
#include <Foundation/NSData.h>
|
||||
#include <Foundation/NSValue.h>
|
||||
// For the encoding functions
|
||||
#include <base/Unicode.h>
|
||||
|
||||
static Atom XA_SLANT = (Atom)0;
|
||||
static Atom XA_SETWIDTH_NAME = (Atom)0;
|
||||
static Atom XA_CHARSET_REGISTRY = (Atom)0;
|
||||
static Atom XA_CHARSET_ENCODING = (Atom)0;
|
||||
static Atom XA_SPACING = (Atom)0;
|
||||
static Atom XA_PIXEL_SIZE = (Atom)0;
|
||||
static Atom XA_WEIGHT_NAME = (Atom)0;
|
||||
|
||||
/*
|
||||
* Initialise the X atoms we are going to use
|
||||
*/
|
||||
static BOOL XGInitAtoms(Display *dpy)
|
||||
{
|
||||
// X atoms used to query a font
|
||||
|
||||
if (!dpy)
|
||||
{
|
||||
NSDebugLog(@"No Display opened in XGInitAtoms");
|
||||
return NO;
|
||||
}
|
||||
|
||||
XA_PIXEL_SIZE = XInternAtom(dpy, "PIXEL_SIZE", False);
|
||||
XA_SPACING = XInternAtom(dpy, "SPACING", False);
|
||||
XA_WEIGHT_NAME = XInternAtom(dpy, "WEIGHT_NAME", False);
|
||||
XA_SLANT = XInternAtom(dpy, "SLANT", False);
|
||||
XA_SETWIDTH_NAME = XInternAtom(dpy, "SETWIDTH_NAME", False);
|
||||
XA_CHARSET_REGISTRY = XInternAtom(dpy, "CHARSET_REGISTRY", False);
|
||||
XA_CHARSET_ENCODING = XInternAtom(dpy, "CHARSET_ENCODING", False);
|
||||
|
||||
/*
|
||||
XA_ADD_STYLE_NAME = XInternAtom(dpy, "ADD_STYLE_NAME", False);
|
||||
XA_RESOLUTION_X = XInternAtom(dpy, "RESOLUTION_X", False);
|
||||
XA_RESOLUTION_Y = XInternAtom(dpy, "RESOLUTION_Y", False);
|
||||
XA_AVERAGE_WIDTH = XInternAtom(dpy, "AVERAGE_WIDTH", False);
|
||||
XA_FACE_NAME = XInternAtom(dpy, "FACE_NAME", False);
|
||||
*/
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
|
||||
@interface XGFontInfo (Private)
|
||||
|
||||
- (BOOL) setupAttributes;
|
||||
- (XCharStruct *)xCharStructForGlyph: (NSGlyph) glyph;
|
||||
|
||||
@end
|
||||
|
||||
@implementation XGFontInfo
|
||||
|
||||
- (XFontStruct*) xFontStruct
|
||||
{
|
||||
return font_info;
|
||||
}
|
||||
|
||||
- initWithFontName: (NSString*)name matrix: (const float *)fmatrix
|
||||
{
|
||||
[super init];
|
||||
ASSIGN(fontName, name);
|
||||
memcpy(matrix, fmatrix, sizeof(matrix));
|
||||
|
||||
if (![self setupAttributes])
|
||||
{
|
||||
RELEASE(self);
|
||||
return nil;
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
if (font_info != NULL)
|
||||
XUnloadFont([XGServer currentXDisplay], font_info->fid);
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (NSMultibyteGlyphPacking)glyphPacking
|
||||
{
|
||||
if (font_info->min_byte1 == 0 &&
|
||||
font_info->max_byte1 == 0)
|
||||
return NSOneByteGlyphPacking;
|
||||
else
|
||||
return NSTwoByteGlyphPacking;
|
||||
}
|
||||
|
||||
- (NSSize) advancementForGlyph: (NSGlyph)glyph
|
||||
{
|
||||
XCharStruct *pc = [self xCharStructForGlyph: glyph];
|
||||
|
||||
// if per_char is NULL assume max bounds
|
||||
if (!pc)
|
||||
pc = &(font_info->max_bounds);
|
||||
|
||||
return NSMakeSize((float)pc->width, 0);
|
||||
}
|
||||
|
||||
- (NSRect) boundingRectForGlyph: (NSGlyph)glyph
|
||||
{
|
||||
XCharStruct *pc = [self xCharStructForGlyph: glyph];
|
||||
|
||||
// if per_char is NULL assume max bounds
|
||||
if (!pc)
|
||||
return fontBBox;
|
||||
|
||||
return NSMakeRect((float)pc->lbearing, (float)-pc->descent,
|
||||
(float)(pc->rbearing - pc->lbearing),
|
||||
(float)(pc->ascent + pc->descent));
|
||||
}
|
||||
|
||||
- (BOOL) glyphIsEncoded: (NSGlyph)glyph
|
||||
{
|
||||
XCharStruct *pc = [self xCharStructForGlyph: glyph];
|
||||
|
||||
return (pc != NULL);
|
||||
}
|
||||
|
||||
- (NSGlyph) glyphWithName: (NSString*)glyphName
|
||||
{
|
||||
// FIXME: There is a mismatch between PS names and X names, that we should
|
||||
// try to correct here
|
||||
KeySym k = XStringToKeysym([glyphName cString]);
|
||||
|
||||
if (k == NoSymbol)
|
||||
return 0;
|
||||
else
|
||||
return (NSGlyph)k;
|
||||
}
|
||||
|
||||
- (void) drawString: (NSString*)string
|
||||
onDisplay: (Display*) xdpy drawable: (Drawable) draw
|
||||
with: (GC) xgcntxt at: (XPoint) xp
|
||||
{
|
||||
XGCValues gcv;
|
||||
NSData *d = [string dataUsingEncoding: mostCompatibleStringEncoding
|
||||
allowLossyConversion: YES];
|
||||
int length = [d length];
|
||||
const char *cstr = (const char*)[d bytes];
|
||||
|
||||
// Select this font, although it might already be current.
|
||||
gcv.font = font_info->fid;
|
||||
XChangeGC(xdpy, xgcntxt, GCFont, &gcv);
|
||||
|
||||
// FIXME: Use XDrawString16 for NSTwoByteGlyphPacking
|
||||
XDrawString(xdpy, draw, xgcntxt, xp.x, xp.y, cstr, length);
|
||||
}
|
||||
|
||||
- (void) draw: (const char*) s lenght: (int) len
|
||||
onDisplay: (Display*) xdpy drawable: (Drawable) draw
|
||||
with: (GC) xgcntxt at: (XPoint) xp
|
||||
{
|
||||
// This font must already be active!
|
||||
XDrawString(xdpy, draw, xgcntxt, xp.x, xp.y, s, len);
|
||||
}
|
||||
|
||||
- (float) widthOfString: (NSString*)string
|
||||
{
|
||||
NSData *d = [string dataUsingEncoding: mostCompatibleStringEncoding
|
||||
allowLossyConversion: YES];
|
||||
int length = [d length];
|
||||
const char *cstr = (const char*)[d bytes];
|
||||
|
||||
// FIXME: Use XTextWidth16 for NSTwoByteGlyphPacking
|
||||
return XTextWidth(font_info, cstr, length);
|
||||
}
|
||||
|
||||
- (float) widthOf: (const char*) s lenght: (int) len
|
||||
{
|
||||
return XTextWidth(font_info, s, len);
|
||||
}
|
||||
|
||||
- (void) setActiveFor: (Display*) xdpy gc: (GC) xgcntxt
|
||||
{
|
||||
XGCValues gcv;
|
||||
|
||||
// Select this font, although it might already be current.
|
||||
gcv.font = font_info->fid;
|
||||
XChangeGC(xdpy, xgcntxt, GCFont, &gcv);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation XGFontInfo (Private)
|
||||
|
||||
- (BOOL) setupAttributes
|
||||
{
|
||||
Display *xdpy = [XGServer currentXDisplay];
|
||||
NSString *weightString;
|
||||
NSString *reg;
|
||||
long height;
|
||||
NSString *xfontname;
|
||||
|
||||
if (!xdpy)
|
||||
return NO;
|
||||
|
||||
if (!XA_PIXEL_SIZE)
|
||||
XGInitAtoms(xdpy);
|
||||
|
||||
// Retrieve the XLFD matching the given fontName. DPS->X.
|
||||
xfontname = XGXFontName(fontName, matrix[0]);
|
||||
|
||||
// Load X font and get font info structure.
|
||||
if ((xfontname == nil) ||
|
||||
(font_info = XLoadQueryFont(xdpy, [xfontname cString])) == NULL)
|
||||
{
|
||||
NSLog(@"Selected font: %@ at %f (%@) is not available.\n"
|
||||
@"Using system fixed font instead", fontName, matrix[0], xfontname);
|
||||
|
||||
// Try default font
|
||||
if ((font_info = XLoadQueryFont(xdpy, "9x15")) == NULL)
|
||||
{
|
||||
NSLog(@"Unable to open fixed font");
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
else
|
||||
NSDebugLog(@"Loaded font: %@", xfontname);
|
||||
|
||||
// Fill the afmDitionary and ivars
|
||||
[fontDictionary setObject: fontName forKey: NSAFMFontName];
|
||||
ASSIGN(familyName, XGFontFamily(xdpy, font_info));
|
||||
[fontDictionary setObject: familyName forKey: NSAFMFamilyName];
|
||||
isFixedPitch = XGFontIsFixedPitch(xdpy, font_info);
|
||||
isBaseFont = NO;
|
||||
ascender = font_info->max_bounds.ascent;
|
||||
[fontDictionary setObject: [NSNumber numberWithFloat: ascender]
|
||||
forKey: NSAFMAscender];
|
||||
descender = -(font_info->max_bounds.descent);
|
||||
[fontDictionary setObject: [NSNumber numberWithFloat: descender]
|
||||
forKey: NSAFMDescender];
|
||||
fontBBox = NSMakeRect(
|
||||
(float)(0 + font_info->min_bounds.lbearing),
|
||||
(float)(0 - font_info->max_bounds.ascent),
|
||||
(float)(font_info->max_bounds.rbearing - font_info->min_bounds.lbearing),
|
||||
(float)(font_info->max_bounds.ascent + font_info->max_bounds.descent));
|
||||
maximumAdvancement = NSMakeSize(font_info->max_bounds.width,
|
||||
(font_info->max_bounds.ascent +font_info->max_bounds.descent));
|
||||
minimumAdvancement = NSMakeSize(0,0);
|
||||
weight = XGWeightOfFont(xdpy, font_info);
|
||||
traits = XGTraitsOfFont(xdpy, font_info);
|
||||
|
||||
weightString = [GSFontInfo stringForWeight: weight];
|
||||
|
||||
if (weightString != nil)
|
||||
{
|
||||
[fontDictionary setObject: weightString forKey: NSAFMWeight];
|
||||
}
|
||||
|
||||
reg = XGFontPropString(xdpy, font_info, XA_CHARSET_REGISTRY);
|
||||
if (reg != nil)
|
||||
{
|
||||
NSString *enc = XGFontPropString(xdpy, font_info, XA_CHARSET_ENCODING);
|
||||
|
||||
if (enc != nil)
|
||||
{
|
||||
mostCompatibleStringEncoding = [GSFontInfo encodingForRegistry: reg
|
||||
encoding: enc];
|
||||
encodingScheme = [NSString stringWithFormat: @"%@-%@",
|
||||
reg, enc];
|
||||
NSDebugLog(@"Found encoding %d for %@",
|
||||
mostCompatibleStringEncoding, encodingScheme);
|
||||
RETAIN(encodingScheme);
|
||||
[fontDictionary setObject: encodingScheme
|
||||
forKey: NSAFMEncodingScheme];
|
||||
}
|
||||
}
|
||||
|
||||
height = XGFontPropULong(xdpy, font_info, XA_X_HEIGHT);
|
||||
if (height != 0)
|
||||
{
|
||||
xHeight = (float)height;
|
||||
[fontDictionary setObject: [NSNumber numberWithFloat: xHeight]
|
||||
forKey: NSAFMXHeight];
|
||||
}
|
||||
|
||||
height = XGFontPropULong(xdpy, font_info, XA_CAP_HEIGHT);
|
||||
if (height != 0)
|
||||
{
|
||||
capHeight = (float)height;
|
||||
[fontDictionary setObject: [NSNumber numberWithFloat: capHeight]
|
||||
forKey: NSAFMCapHeight];
|
||||
}
|
||||
|
||||
// FIXME: italicAngle, underlinePosition, underlineThickness are not set.
|
||||
// Should use XA_ITALIC_ANGLE, XA_UNDERLINE_POSITION, XA_UNDERLINE_THICKNESS
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (XCharStruct *)xCharStructForGlyph: (NSGlyph) glyph
|
||||
{
|
||||
XCharStruct *pc = NULL;
|
||||
|
||||
if (font_info->per_char)
|
||||
{
|
||||
unsigned index;
|
||||
unsigned min1 = font_info->min_byte1;
|
||||
unsigned max1 = font_info->max_byte1;
|
||||
unsigned min2 = font_info->min_char_or_byte2;
|
||||
unsigned max2 = font_info->max_char_or_byte2;
|
||||
|
||||
// glyph is an unicode char value
|
||||
// if the font has non-standard encoding we need to remap it.
|
||||
if ((mostCompatibleStringEncoding != NSASCIIStringEncoding) &&
|
||||
(mostCompatibleStringEncoding != NSISOLatin1StringEncoding) &&
|
||||
(mostCompatibleStringEncoding != NSUnicodeStringEncoding))
|
||||
{
|
||||
// FIXME: This only works for 8-Bit characters
|
||||
index = encode_unitochar(glyph, mostCompatibleStringEncoding);
|
||||
}
|
||||
else
|
||||
index = glyph;
|
||||
|
||||
if (min1 == 0 && max1 == 0)
|
||||
{
|
||||
if (glyph >= min2 && glyph <= max2)
|
||||
pc = &(font_info->per_char[index - min2]);
|
||||
}
|
||||
else
|
||||
{
|
||||
unsigned b1 = index >> 8;
|
||||
unsigned b2 = index & 255;
|
||||
|
||||
if (b1 >= min1 && b1 <= max1 && b2 >= min2 && b2 <= max2)
|
||||
pc = &(font_info->per_char[(b1 - min1) * (max2 - min2 + 1) +
|
||||
b2 - min2]);
|
||||
}
|
||||
}
|
||||
|
||||
return pc;
|
||||
}
|
||||
|
||||
@end
|
197
Source/xlib/XGFontManager.m
Normal file
197
Source/xlib/XGFontManager.m
Normal file
|
@ -0,0 +1,197 @@
|
|||
/*
|
||||
XGFontManager.m
|
||||
|
||||
NSFontManager helper for GNUstep GUI X/GPS Backend
|
||||
|
||||
Copyright (C) 1996 Free Software Foundation, Inc.
|
||||
|
||||
Author: Ovidiu Predescu <ovidiu@bx.logicnet.ro>
|
||||
Date: February 1997
|
||||
A completely rewritten version of the original source of Scott Christley.
|
||||
Modified: Fred Kiefer <FredKiefer@gmx.de>
|
||||
Date: Febuary 2000
|
||||
Added some X calls and changed the overall structure
|
||||
|
||||
This file is part of the GNUstep GUI X/GPS Library.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <AppKit/GSFontInfo.h>
|
||||
#include <Foundation/NSArchiver.h>
|
||||
#include <Foundation/NSFileManager.h>
|
||||
#include <Foundation/NSPathUtilities.h>
|
||||
#include <Foundation/NSProcessInfo.h>
|
||||
#include <Foundation/NSTask.h>
|
||||
#include <Foundation/NSValue.h>
|
||||
#include "xlib/XGContext.h"
|
||||
#include "xlib/XGPrivate.h"
|
||||
#include "x11/XGServer.h"
|
||||
|
||||
#define stringify_it(X) #X
|
||||
|
||||
static NSMutableDictionary* creationDictionary;
|
||||
|
||||
// Fills in the size into an creation string to make it an X font name
|
||||
NSString *XGXFontName(NSString *fontName, float size)
|
||||
{
|
||||
NSString *creationName = [creationDictionary objectForKey: fontName];
|
||||
|
||||
if (creationName != nil)
|
||||
return [NSString stringWithFormat: creationName, (int)size];
|
||||
else
|
||||
return nil;
|
||||
}
|
||||
|
||||
@implementation XGFontEnumerator
|
||||
|
||||
static NSDictionary *cache;
|
||||
|
||||
static NSString*
|
||||
cache_name()
|
||||
{
|
||||
static NSString *cacheName = nil;
|
||||
|
||||
if (cacheName == nil)
|
||||
{
|
||||
NSFileManager *mgr;
|
||||
BOOL flag;
|
||||
Display *dpy = [XGServer currentXDisplay];
|
||||
char *display_name = DisplayString(dpy);
|
||||
NSString *file_name;
|
||||
NSArray *paths;
|
||||
NSString *path = nil;
|
||||
|
||||
file_name = [NSString stringWithCString: XDisplayName(display_name)];
|
||||
|
||||
paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory,
|
||||
NSUserDomainMask, YES);
|
||||
if ((paths != nil) && ([paths count] > 0))
|
||||
{
|
||||
path = [paths objectAtIndex: 0];
|
||||
}
|
||||
/*
|
||||
* If standard search paths are not set up, try a default location.
|
||||
*/
|
||||
if (path == nil)
|
||||
{
|
||||
path = [[NSHomeDirectory() stringByAppendingPathComponent:
|
||||
@"GNUstep"] stringByAppendingPathComponent: @"Library"];
|
||||
}
|
||||
|
||||
mgr = [NSFileManager defaultManager];
|
||||
if ([mgr fileExistsAtPath: path isDirectory: &flag] == NO || flag == NO)
|
||||
{
|
||||
NSLog(@"Library directory '%@' not available!", path);
|
||||
return NO;
|
||||
}
|
||||
path = [path stringByAppendingPathComponent: @"Fonts"];
|
||||
if ([mgr fileExistsAtPath: path] == NO)
|
||||
{
|
||||
[mgr createDirectoryAtPath: path attributes: nil];
|
||||
}
|
||||
if ([mgr fileExistsAtPath: path isDirectory: &flag] == NO || flag == NO)
|
||||
{
|
||||
NSLog(@"Fonts directory '%@' not available!", path);
|
||||
return NO;
|
||||
}
|
||||
path = [path stringByAppendingPathComponent: @"Cache"];
|
||||
if ([mgr fileExistsAtPath: path] == NO)
|
||||
{
|
||||
[mgr createDirectoryAtPath: path attributes: nil];
|
||||
}
|
||||
if ([mgr fileExistsAtPath: path isDirectory: &flag] == NO || flag == NO)
|
||||
{
|
||||
NSLog(@"Fonts directory '%@' not available!", path);
|
||||
return NO;
|
||||
}
|
||||
cacheName = [path stringByAppendingPathComponent: file_name];
|
||||
RETAIN(cacheName);
|
||||
}
|
||||
|
||||
return cacheName;
|
||||
}
|
||||
|
||||
static BOOL
|
||||
load_cache(NSString *cacheName, BOOL async)
|
||||
{
|
||||
NSNumber *v;
|
||||
id o;
|
||||
|
||||
o = [NSUnarchiver unarchiveObjectWithFile: cacheName];
|
||||
if ((o == nil)
|
||||
|| ((v = [o objectForKey: @"Version"]) == nil)
|
||||
|| ([v intValue] != 2))
|
||||
{
|
||||
NSString *file_name = [cacheName lastPathComponent];
|
||||
NSDictionary *env = [[NSProcessInfo processInfo] environment];
|
||||
NSString *path;
|
||||
NSTask *task;
|
||||
|
||||
if (async == NO)
|
||||
{
|
||||
NSLog(@"No font cache available - building new one - this may "
|
||||
@"take several seconds (or minutes on a slow machine with "
|
||||
@"lots of fonts)");
|
||||
}
|
||||
if (!env || !(path = [env objectForKey: @"GNUSTEP_SYSTEM_ROOT"]))
|
||||
{
|
||||
path = [NSString stringWithCString:
|
||||
stringify_it(GNUSTEP_INSTALL_PREFIX)];
|
||||
}
|
||||
path = [path stringByAppendingPathComponent: @"Tools"];
|
||||
path = [path stringByAppendingPathComponent: @"font_cacher"];
|
||||
task = [NSTask launchedTaskWithLaunchPath: path
|
||||
arguments: [NSArray arrayWithObject: file_name]];
|
||||
if (task == nil || async == YES)
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
[task waitUntilExit];
|
||||
o = [NSUnarchiver unarchiveObjectWithFile: cacheName];
|
||||
if (o == nil)
|
||||
{
|
||||
NSLog(@"Error - font cache doesn't exist");
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Ensure archive is written in latest format.
|
||||
[NSArchiver archiveRootObject: o toFile: cacheName];
|
||||
}
|
||||
|
||||
ASSIGN(cache, o);
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void) enumerateFontsAndFamilies
|
||||
{
|
||||
if (cache == nil)
|
||||
{
|
||||
if (load_cache(cache_name(), NO))
|
||||
{
|
||||
allFontNames = [[cache objectForKey: @"AllFontNames"] allObjects];
|
||||
allFontFamilies = [cache objectForKey: @"AllFontFamilies"];
|
||||
// This dictionary stores the XLFD for each font
|
||||
creationDictionary = [cache objectForKey: @"CreationDictionary"];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
1856
Source/xlib/XGGState.m
Normal file
1856
Source/xlib/XGGState.m
Normal file
File diff suppressed because it is too large
Load diff
130
Source/xlib/XGGeometry.m
Normal file
130
Source/xlib/XGGeometry.m
Normal file
|
@ -0,0 +1,130 @@
|
|||
/* XGGeometry - Utility functions that calculate in device space
|
||||
|
||||
Copyright (C) 2002 Free Software Foundation, Inc.
|
||||
|
||||
Written by: Willem Oudshoorn <woudshoo@xs4all.nl>
|
||||
|
||||
|
||||
This file is part of the GNU Objective C User Interface Library.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include <Foundation/NSDebug.h>
|
||||
#include "xlib/XGGeometry.h"
|
||||
#include "x11/XGServer.h"
|
||||
|
||||
/**
|
||||
* Returns the area that is accessible in the underlying drawable
|
||||
* of win.
|
||||
*
|
||||
* Accessible means that we can use XPutPixel and XGetPixel
|
||||
* on all the points in the result.
|
||||
* If the window uses a backingstore this will be the size
|
||||
* of the underlying drawable, but if the window does not
|
||||
* use backing store and the window is partly outside the screen
|
||||
* it will be the part of the window that falls inside the screen.
|
||||
*
|
||||
* NOTE:
|
||||
* Unfortunately, the gswindow_device_t does not contain a reference
|
||||
* to the XDisplay it is displayed on and we need it.
|
||||
*/
|
||||
XRectangle
|
||||
accessibleRectForWindow (gswindow_device_t* win)
|
||||
{
|
||||
Display* xdpy = [XGServer currentXDisplay];
|
||||
Window root;
|
||||
Window ignoreWindow;
|
||||
int x, y, w, h;
|
||||
int ignoreInt;
|
||||
XRectangle winRect;
|
||||
|
||||
if (!XGetGeometry (xdpy, GET_XDRAWABLE (win),
|
||||
&root,
|
||||
&x, &y,
|
||||
&w, &h,
|
||||
&ignoreInt,
|
||||
&ignoreInt))
|
||||
{
|
||||
NSDebugLLog (@"XGGeometry", @"invalide Drawable in gswindow_device");
|
||||
return XGMakeRect (0, 0, 0, 0);
|
||||
}
|
||||
|
||||
winRect = XGMakeRect (0, 0, w, h);
|
||||
|
||||
if (win->buffer)
|
||||
{
|
||||
return winRect;
|
||||
}
|
||||
|
||||
// we do not have backing store, so clip it to the screen.
|
||||
if (!XGetGeometry (xdpy, root,
|
||||
&root,
|
||||
&ignoreInt, &ignoreInt,
|
||||
&w, &h,
|
||||
&ignoreInt, &ignoreInt))
|
||||
{
|
||||
NSDebugLLog (@"XGGeometry", @"could not determine size of root");
|
||||
return XGMakeRect (0, 0, 0, 0);
|
||||
}
|
||||
|
||||
if (!XTranslateCoordinates (xdpy,
|
||||
root,
|
||||
GET_XDRAWABLE (win),
|
||||
0, 0,
|
||||
&x, &y,
|
||||
&ignoreWindow))
|
||||
{
|
||||
NSDebugLLog (@"XGGeometry", @"could not determine position of device");
|
||||
return XGMakeRect (0, 0, 0, 0);
|
||||
}
|
||||
|
||||
return XGIntersectionRect (winRect, XGMakeRect (x, y, w, h));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* POST CONDITIONS
|
||||
* winA and winB are unmodified
|
||||
* rectA and rectB have the same size
|
||||
* rectA is an accessible rectangle in winA
|
||||
* rectB is an accessible rectangle in winB
|
||||
* rectA is a subrectangle of the argument rectA
|
||||
* rectB is a subrectangle of the argument rectB
|
||||
* the size of RectA and rectB are maximal with respect to the conditions above.
|
||||
*
|
||||
* USAGE
|
||||
* typical usage will be in copy operations between one gswindow_device to
|
||||
* another gswindow_device. This because the result will be the maximal
|
||||
* region that we are able to copy without generating X-protocol errors
|
||||
* or segfaults.
|
||||
*/
|
||||
void
|
||||
clipXRectsForCopying (gswindow_device_t* winA, XRectangle* rectA,
|
||||
gswindow_device_t* winB, XRectangle* rectB)
|
||||
{
|
||||
// First make A smaller.
|
||||
*rectA = XGIntersectionRect (*rectA, accessibleRectForWindow (winA));
|
||||
// update size of B with the size of A
|
||||
rectB->width = MIN (rectA->width, rectB->width);
|
||||
rectB->height = MIN (rectA->height, rectB->height);
|
||||
// now make B smaller
|
||||
*rectB = XGIntersectionRect (*rectB, accessibleRectForWindow (winB));
|
||||
// and update size of A with size of B
|
||||
rectA->width = rectB->width;
|
||||
rectA->height = rectB->height;
|
||||
}
|
486
Source/xlib/XftFontInfo.m
Normal file
486
Source/xlib/XftFontInfo.m
Normal file
|
@ -0,0 +1,486 @@
|
|||
/*
|
||||
XftFontInfo
|
||||
|
||||
NSFont helper for GNUstep GUI X/GPS Backend
|
||||
|
||||
Copyright (C) 1996 Free Software Foundation, Inc.
|
||||
|
||||
Author: Fred Kiefer <fredkiefer@gmx.de>
|
||||
Date: July 2001
|
||||
|
||||
This file is part of the GNUstep GUI X/GPS Backend.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; see the file COPYING.LIB.
|
||||
If not, write to the Free Software Foundation,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "xlib/XGContext.h"
|
||||
#include "xlib/XGPrivate.h"
|
||||
#include "xlib/XGGState.h"
|
||||
#include "x11/XGServer.h"
|
||||
#include <Foundation/NSData.h>
|
||||
#include <Foundation/NSDebug.h>
|
||||
#include <Foundation/NSValue.h>
|
||||
// For the encoding functions
|
||||
#include <base/Unicode.h>
|
||||
|
||||
#include "xlib/XftFontInfo.h"
|
||||
|
||||
/*
|
||||
* class global dictionary of existing fonts
|
||||
*/
|
||||
static NSMutableDictionary *_globalFontDictionary = nil;
|
||||
|
||||
@interface XftFontInfo (Private)
|
||||
|
||||
- (BOOL) setupAttributes;
|
||||
- (XGlyphInfo *)xGlyphInfo: (NSGlyph) glyph;
|
||||
|
||||
@end
|
||||
|
||||
@implementation XftFontInfo
|
||||
|
||||
- initWithFontName: (NSString*)name matrix: (const float *)fmatrix
|
||||
{
|
||||
[super init];
|
||||
ASSIGN(fontName, name);
|
||||
memcpy(matrix, fmatrix, sizeof(matrix));
|
||||
|
||||
if (![self setupAttributes])
|
||||
{
|
||||
RELEASE(self);
|
||||
return nil;
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
if (font_info != NULL)
|
||||
XftFontClose([XGServer currentXDisplay], (XftFont *)font_info);
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (float) widthOfString: (NSString*)string
|
||||
{
|
||||
XGlyphInfo extents;
|
||||
int len = [string length];
|
||||
XftChar16 str[len];
|
||||
|
||||
[string getCharacters: (unichar*)str];
|
||||
XftTextExtents16 ([XGServer currentXDisplay],
|
||||
font_info,
|
||||
str,
|
||||
len,
|
||||
&extents);
|
||||
|
||||
return extents.width;
|
||||
}
|
||||
|
||||
- (NSMultibyteGlyphPacking)glyphPacking
|
||||
{
|
||||
return NSTwoByteGlyphPacking;
|
||||
}
|
||||
|
||||
- (NSSize) advancementForGlyph: (NSGlyph)glyph
|
||||
{
|
||||
XGlyphInfo *pc = [self xGlyphInfo: glyph];
|
||||
|
||||
// if per_char is NULL assume max bounds
|
||||
if (!pc)
|
||||
return NSMakeSize((float)(font_info)->max_advance_width, 0);
|
||||
|
||||
return NSMakeSize((float)pc->xOff, (float)pc->yOff);
|
||||
}
|
||||
|
||||
- (NSRect) boundingRectForGlyph: (NSGlyph)glyph
|
||||
{
|
||||
XGlyphInfo *pc = [self xGlyphInfo: glyph];
|
||||
|
||||
// if per_char is NULL assume max bounds
|
||||
if (!pc)
|
||||
return NSMakeRect(0.0, 0.0,
|
||||
(float)font_info->max_advance_width,
|
||||
(float)(font_info->ascent + font_info->descent));
|
||||
|
||||
return NSMakeRect((float)pc->x, (float)-pc->y,
|
||||
(float)(pc->width),
|
||||
(float)(pc->height));
|
||||
}
|
||||
|
||||
- (BOOL) glyphIsEncoded: (NSGlyph)glyph
|
||||
{
|
||||
return XftGlyphExists([XGServer currentXDisplay],
|
||||
(XftFont *)font_info, glyph);
|
||||
}
|
||||
|
||||
- (NSGlyph) glyphWithName: (NSString*)glyphName
|
||||
{
|
||||
// FIXME: There is a mismatch between PS names and X names, that we should
|
||||
// try to correct here
|
||||
KeySym k = XStringToKeysym([glyphName cString]);
|
||||
|
||||
if (k == NoSymbol)
|
||||
return 0;
|
||||
else
|
||||
return (NSGlyph)k;
|
||||
}
|
||||
|
||||
- (NSPoint) positionOfGlyph: (NSGlyph)curGlyph
|
||||
precededByGlyph: (NSGlyph)prevGlyph
|
||||
isNominal: (BOOL*)nominal
|
||||
{
|
||||
if (nominal)
|
||||
*nominal = YES;
|
||||
|
||||
if (curGlyph == NSControlGlyph || prevGlyph == NSControlGlyph)
|
||||
return NSZeroPoint;
|
||||
|
||||
// if (curGlyph == NSNullGlyph)
|
||||
{
|
||||
NSSize advance = [self advancementForGlyph: prevGlyph];
|
||||
return NSMakePoint(advance.width, advance.height);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
- (float) pointSize
|
||||
{
|
||||
Display *xdpy = [XGServer currentXDisplay];
|
||||
|
||||
return XGFontPointSize(xdpy, font_info);
|
||||
}
|
||||
*/
|
||||
|
||||
- (void) drawString: (NSString*)string
|
||||
onDisplay: (Display*) xdpy drawable: (Drawable) draw
|
||||
with: (GC) xgcntxt at: (XPoint) xp
|
||||
{
|
||||
NSData *d = [string dataUsingEncoding: mostCompatibleStringEncoding
|
||||
allowLossyConversion: YES];
|
||||
int length = [d length];
|
||||
const char *cstr = (const char*)[d bytes];
|
||||
XftDraw *xftdraw;
|
||||
XftColor xftcolor;
|
||||
XColor dummyc;
|
||||
XGCValues values;
|
||||
XGGState *state = [(XGContext *)GSCurrentContext() currentGState];
|
||||
Region xregion = [state xClipRegion];
|
||||
int defaultScreen = DefaultScreen(xdpy);
|
||||
Colormap colmap = DefaultColormap(xdpy, defaultScreen);
|
||||
|
||||
/* ready to draw */
|
||||
xftdraw = XftDrawCreate(xdpy, draw,
|
||||
DefaultVisual(xdpy, defaultScreen),
|
||||
colmap);
|
||||
if(xftdraw == NULL)
|
||||
return;
|
||||
|
||||
/* sort out the drawing colour */
|
||||
XGetGCValues(xdpy, xgcntxt,
|
||||
GCForeground | GCBackground,
|
||||
&values);
|
||||
|
||||
dummyc.pixel = values.foreground;
|
||||
XQueryColor(xdpy, colmap, &dummyc);
|
||||
xftcolor.color.red = dummyc.red;
|
||||
xftcolor.color.green = dummyc.green;
|
||||
xftcolor.color.blue = dummyc.blue;
|
||||
xftcolor.color.alpha = 0xffff;
|
||||
xftcolor.pixel = values.foreground;
|
||||
|
||||
// set up clipping
|
||||
if(xregion != None)
|
||||
{
|
||||
XftDrawSetClip(xftdraw, xregion);
|
||||
XDestroyRegion(xregion);
|
||||
}
|
||||
|
||||
/* do it */
|
||||
XftDrawString16(xftdraw, &xftcolor, font_info,
|
||||
xp.x, xp.y, (XftChar16*)cstr, length);
|
||||
|
||||
/* tidy up */
|
||||
XftDrawDestroy(xftdraw);
|
||||
}
|
||||
|
||||
- (void) draw: (const char*) s lenght: (int) len
|
||||
onDisplay: (Display*) xdpy drawable: (Drawable) draw
|
||||
with: (GC) xgcntxt at: (XPoint) xp
|
||||
{
|
||||
int length = strlen(s);
|
||||
XftDraw *xftdraw;
|
||||
XftColor xftcolor;
|
||||
XColor dummyc;
|
||||
XGCValues values;
|
||||
XGGState *state = [(XGContext *)GSCurrentContext() currentGState];
|
||||
Region xregion = [state xClipRegion];
|
||||
int defaultScreen = DefaultScreen(xdpy);
|
||||
Colormap colmap = DefaultColormap(xdpy, defaultScreen);
|
||||
|
||||
/* ready to draw */
|
||||
xftdraw = XftDrawCreate(xdpy, draw,
|
||||
DefaultVisual(xdpy, defaultScreen),
|
||||
colmap);
|
||||
if(xftdraw == NULL)
|
||||
return;
|
||||
|
||||
/* sort out the drawing colour */
|
||||
XGetGCValues(xdpy, xgcntxt,
|
||||
GCForeground | GCBackground,
|
||||
&values);
|
||||
|
||||
dummyc.pixel = values.foreground;
|
||||
XQueryColor(xdpy, colmap, &dummyc);
|
||||
xftcolor.color.red = dummyc.red;
|
||||
xftcolor.color.green = dummyc.green;
|
||||
xftcolor.color.blue = dummyc.blue;
|
||||
xftcolor.color.alpha = 0xffff;
|
||||
xftcolor.pixel = values.foreground;
|
||||
|
||||
// set up clipping
|
||||
if(xregion != None)
|
||||
{
|
||||
XftDrawSetClip(xftdraw, xregion);
|
||||
XDestroyRegion(xregion);
|
||||
}
|
||||
|
||||
/* do it */
|
||||
if (NSUTF8StringEncoding == mostCompatibleStringEncoding)
|
||||
{
|
||||
XftDrawStringUtf8(xftdraw, &xftcolor, font_info,
|
||||
xp.x, xp.y, (XftChar8 *)s, length);
|
||||
}
|
||||
else
|
||||
{
|
||||
XftDrawString8(xftdraw, &xftcolor, font_info,
|
||||
xp.x, xp.y, (XftChar8*)s, length);
|
||||
}
|
||||
|
||||
/* tidy up */
|
||||
XftDrawDestroy(xftdraw);
|
||||
}
|
||||
|
||||
- (float) widthOf: (const char*) s lenght: (int) len
|
||||
{
|
||||
XGlyphInfo extents;
|
||||
|
||||
if (mostCompatibleStringEncoding == NSUTF8StringEncoding)
|
||||
XftTextExtentsUtf8([XGServer currentXDisplay],
|
||||
font_info,
|
||||
(XftChar8 *)s,
|
||||
len,
|
||||
&extents);
|
||||
else
|
||||
XftTextExtents8([XGServer currentXDisplay],
|
||||
font_info,
|
||||
(XftChar8*)s,
|
||||
len,
|
||||
&extents);
|
||||
|
||||
return extents.width;
|
||||
}
|
||||
|
||||
- (void) setActiveFor: (Display*) xdpy gc: (GC) xgcntxt
|
||||
{
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation XftFontInfo (Private)
|
||||
|
||||
- (BOOL) setupAttributes
|
||||
{
|
||||
Display *xdpy = [XGServer currentXDisplay];
|
||||
int defaultScreen = DefaultScreen(xdpy);
|
||||
NSString *weightString;
|
||||
NSString *reg;
|
||||
long height;
|
||||
XftPattern *pattern;
|
||||
XftResult result;
|
||||
NSString *xfontname;
|
||||
|
||||
char *xftTypeString;
|
||||
int xftTypeInt;
|
||||
NSArray *encoding;
|
||||
|
||||
if (!xdpy)
|
||||
return NO;
|
||||
|
||||
// Retrieve the XLFD matching the given fontName. DPS->X.
|
||||
xfontname = XGXFontName(fontName, matrix[0]);
|
||||
|
||||
// Load Xft font and get font info structure.
|
||||
if ((xfontname == nil) ||
|
||||
(font_info = XftFontOpenXlfd(xdpy, defaultScreen, [xfontname cString])) == NULL)
|
||||
{
|
||||
NSLog(@"Selected font: %@ (%@) is not available.\n"
|
||||
@"Using system default font instead", fontName, xfontname);
|
||||
|
||||
if ((font_info = XftFontOpen(xdpy, defaultScreen, 0)) == NULL)
|
||||
{
|
||||
NSLog(@"Unable to open fixed font");
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
else
|
||||
NSDebugLog(@"Loaded font: %@", xfontname);
|
||||
|
||||
// Fill the afmDitionary and ivars
|
||||
[fontDictionary setObject: fontName forKey: NSAFMFontName];
|
||||
|
||||
pattern = font_info->pattern;
|
||||
result = XftPatternGetString(pattern, XFT_FAMILY, 0, &xftTypeString);
|
||||
if (result != XftResultTypeMismatch)
|
||||
{
|
||||
ASSIGN(familyName,
|
||||
[NSString stringWithCString: (const char*)xftTypeString]);
|
||||
[fontDictionary setObject: familyName forKey: NSAFMFamilyName];
|
||||
}
|
||||
result = XftPatternGetInteger(pattern, XFT_SPACING, 0, &xftTypeInt);
|
||||
if (result != XftResultTypeMismatch)
|
||||
{
|
||||
isFixedPitch = (weight != 0);
|
||||
}
|
||||
|
||||
isBaseFont = NO;
|
||||
ascender = font_info->ascent;
|
||||
[fontDictionary setObject: [NSNumber numberWithFloat: ascender]
|
||||
forKey: NSAFMAscender];
|
||||
descender = -(font_info->descent);
|
||||
[fontDictionary setObject: [NSNumber numberWithFloat: descender]
|
||||
forKey: NSAFMDescender];
|
||||
fontBBox = NSMakeRect(
|
||||
(float)(0),
|
||||
(float)(0 - font_info->ascent),
|
||||
(float)(font_info->max_advance_width),
|
||||
(float)(font_info->ascent + font_info->descent));
|
||||
maximumAdvancement = NSMakeSize(font_info->max_advance_width,
|
||||
(font_info->ascent + font_info->descent));
|
||||
minimumAdvancement = NSMakeSize(0,0);
|
||||
|
||||
result = XftPatternGetInteger(pattern, XFT_WEIGHT, 0, &xftTypeInt);
|
||||
if (result != XftResultTypeMismatch)
|
||||
{
|
||||
switch (xftTypeInt)
|
||||
{
|
||||
case 0:
|
||||
weight = 3;
|
||||
weightString = @"light";
|
||||
break;
|
||||
case 100:
|
||||
weight = 6;
|
||||
weightString = @"medium";
|
||||
break;
|
||||
case 180:
|
||||
weight = 7;
|
||||
weightString = @"demibold";
|
||||
break;
|
||||
case 200:
|
||||
weight = 9;
|
||||
weightString = @"bold";
|
||||
break;
|
||||
case 210:
|
||||
weight = 12;
|
||||
weightString = @"black";
|
||||
break;
|
||||
default:
|
||||
// Don't know
|
||||
weight = 6;;
|
||||
}
|
||||
if (weightString != nil)
|
||||
{
|
||||
[fontDictionary setObject: weightString forKey: NSAFMWeight];
|
||||
}
|
||||
}
|
||||
|
||||
if (weight >= 9)
|
||||
traits |= NSBoldFontMask;
|
||||
else
|
||||
traits |= NSUnboldFontMask;
|
||||
|
||||
if (isFixedPitch)
|
||||
traits |= NSFixedPitchFontMask;
|
||||
|
||||
result = XftPatternGetInteger(pattern, XFT_SLANT, 0, &xftTypeInt);
|
||||
if (result != XftResultTypeMismatch)
|
||||
{
|
||||
if (xftTypeInt != 0)
|
||||
traits |= NSItalicFontMask;
|
||||
else
|
||||
traits |= NSUnitalicFontMask;
|
||||
}
|
||||
|
||||
XftPatternGetString (pattern, XFT_ENCODING, 0, &xftTypeString);
|
||||
encodingScheme = [NSString stringWithCString: xftTypeString];
|
||||
encoding = [encodingScheme componentsSeparatedByString: @"-"];
|
||||
reg = [encoding objectAtIndex: 0];
|
||||
if (reg != nil)
|
||||
{
|
||||
NSString *enc = [encoding lastObject];
|
||||
|
||||
if (enc != nil)
|
||||
{
|
||||
mostCompatibleStringEncoding = [GSFontInfo encodingForRegistry: reg
|
||||
encoding: enc];
|
||||
if (mostCompatibleStringEncoding == NSUnicodeStringEncoding)
|
||||
mostCompatibleStringEncoding = NSUTF8StringEncoding;
|
||||
|
||||
encodingScheme = [NSString stringWithFormat: @"%@-%@",
|
||||
reg, enc];
|
||||
//NSLog(@"Found encoding %d for %@", mostCompatibleStringEncoding, encodingScheme);
|
||||
RETAIN(encodingScheme);
|
||||
[fontDictionary setObject: encodingScheme
|
||||
forKey: NSAFMEncodingScheme];
|
||||
}
|
||||
}
|
||||
/*
|
||||
height = XGFontPropULong(xdpy, font_info, XA_X_HEIGHT);
|
||||
if (height != 0)
|
||||
{
|
||||
xHeight = (float)height;
|
||||
[fontDictionary setObject: [NSNumber numberWithFloat: xHeight]
|
||||
forKey: NSAFMXHeight];
|
||||
}
|
||||
|
||||
height = XGFontPropULong(xdpy, font_info, XA_CAP_HEIGHT);
|
||||
if (height != 0)
|
||||
{
|
||||
capHeight = (float)height;
|
||||
[fontDictionary setObject: [NSNumber numberWithFloat: capHeight]
|
||||
forKey: NSAFMCapHeight];
|
||||
}
|
||||
*/
|
||||
// FIXME: italicAngle, underlinePosition, underlineThickness are not set.
|
||||
// Should use XA_ITALIC_ANGLE, XA_UNDERLINE_POSITION, XA_UNDERLINE_THICKNESS
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (XGlyphInfo *)xGlyphInfo: (NSGlyph) glyph
|
||||
{
|
||||
static XGlyphInfo glyphInfo;
|
||||
|
||||
XftTextExtents32 ([XGServer currentXDisplay],
|
||||
(XftFont *)font_info,
|
||||
&glyph,
|
||||
1,
|
||||
&glyphInfo);
|
||||
|
||||
return &glyphInfo;
|
||||
}
|
||||
|
||||
@end
|
15
Source/xlib/linking.m
Normal file
15
Source/xlib/linking.m
Normal file
|
@ -0,0 +1,15 @@
|
|||
|
||||
#include "xlib/XGContext.h"
|
||||
|
||||
//extern void __objc_xgps_gsbackend_linking (void);
|
||||
|
||||
extern void __objc_xgcontextwindow_linking (void);
|
||||
extern void __objc_xgcontextevent_linking (void);
|
||||
|
||||
|
||||
void __objc_xgps_linking(void)
|
||||
{
|
||||
//__objc_xgps_gsbackend_linking();
|
||||
__objc_xgcontextwindow_linking();
|
||||
__objc_xgcontextevent_linking();
|
||||
}
|
262
Source/xlib/xrtools.c
Normal file
262
Source/xlib/xrtools.c
Normal file
|
@ -0,0 +1,262 @@
|
|||
/* xrtools - Color conversion routines and other low-level X support
|
||||
|
||||
Copyright (C) 1998 Free Software Foundation, Inc.
|
||||
|
||||
Written by: Adam Fedor <fedor@gnu.org>
|
||||
Date: Oct 1998
|
||||
|
||||
This file is part of the GNU Objective C User Interface Library.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
|
||||
*/
|
||||
#include "config.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include <X11/Xatom.h>
|
||||
#include <X11/Intrinsic.h>
|
||||
#include "xlib/xrtools.h"
|
||||
|
||||
/* Internal conversion of colors to pixels values */
|
||||
u_long
|
||||
xrGrayToPixel(RContext* context, float gray)
|
||||
{
|
||||
XColor cc;
|
||||
RColor rcolor;
|
||||
rcolor.red = 255. * gray;
|
||||
rcolor.green = 255. * gray;
|
||||
rcolor.blue = 255. * gray;
|
||||
rcolor.alpha = 0;
|
||||
RGetClosestXColor(context, &rcolor, &cc);
|
||||
return cc.pixel;
|
||||
}
|
||||
|
||||
u_long
|
||||
xrRGBToPixel(RContext* context, float red, float green, float blue)
|
||||
{
|
||||
XColor cc;
|
||||
RColor rcolor;
|
||||
rcolor.red = 255. * red;
|
||||
rcolor.green = 255. * green;
|
||||
rcolor.blue = 255. * blue;
|
||||
rcolor.alpha = 0;
|
||||
RGetClosestXColor(context, &rcolor, &cc);
|
||||
return cc.pixel;
|
||||
}
|
||||
|
||||
u_long
|
||||
xrHSBToPixel(RContext* context, float h, float s, float v)
|
||||
{
|
||||
int i;
|
||||
float f, p, q, t;
|
||||
float red, green, blue;
|
||||
|
||||
if (s == 0)
|
||||
return xrRGBToPixel(context, v, v, v);
|
||||
|
||||
h = h * 6;
|
||||
i = (int)h;
|
||||
f = h - i;
|
||||
p = v * (1.0 - s);
|
||||
q = v * (1.0 - s * f);
|
||||
t = v * (1.0 - s * (1 - f));
|
||||
|
||||
switch (i)
|
||||
{
|
||||
case 0:
|
||||
red = v;
|
||||
green = t;
|
||||
blue = p;
|
||||
break;
|
||||
case 1:
|
||||
red = q;
|
||||
green = v;
|
||||
blue = p;
|
||||
break;
|
||||
case 2:
|
||||
red = p;
|
||||
green = v;
|
||||
blue = t;
|
||||
break;
|
||||
case 3:
|
||||
red = p;
|
||||
green = q;
|
||||
blue = v;
|
||||
break;
|
||||
case 4:
|
||||
red = t;
|
||||
green = p;
|
||||
blue = v;
|
||||
break;
|
||||
case 5:
|
||||
red = v;
|
||||
green = p;
|
||||
blue = q;
|
||||
break;
|
||||
}
|
||||
return xrRGBToPixel(context, red, green, blue);
|
||||
}
|
||||
|
||||
/* Not implemented. FIXME */
|
||||
u_long
|
||||
xrCMYKToPixel(RContext* context, float c, float m, float y, float k)
|
||||
{
|
||||
float red, green, blue;
|
||||
double white = 1 - k;
|
||||
|
||||
if (k == 0)
|
||||
{
|
||||
red = 1 - c;
|
||||
green = 1 - m;
|
||||
blue = 1 - y;
|
||||
}
|
||||
else if (k == 1)
|
||||
{
|
||||
red = 0;
|
||||
green = 0;
|
||||
blue = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
red = (c > white ? 0 : white - c);
|
||||
green = (m > white ? 0 : white - m);
|
||||
blue = (y > white ? 0 : white - y);
|
||||
}
|
||||
return xrRGBToPixel(context, red, green, blue);
|
||||
}
|
||||
|
||||
u_long
|
||||
xrColorToPixel(RContext* context, xr_device_color_t color)
|
||||
{
|
||||
u_long pix;
|
||||
switch(color.space)
|
||||
{
|
||||
case gray_colorspace:
|
||||
pix = xrGrayToPixel(context, color.field[0]);
|
||||
break;
|
||||
case rgb_colorspace:
|
||||
pix = xrRGBToPixel(context, color.field[0],
|
||||
color.field[1], color.field[2]);
|
||||
break;
|
||||
case hsb_colorspace:
|
||||
pix = xrHSBToPixel(context, color.field[0],
|
||||
color.field[1], color.field[2]);
|
||||
break;
|
||||
case cmyk_colorspace:
|
||||
pix = xrCMYKToPixel(context, color.field[0], color.field[1],
|
||||
color.field[2], color.field[3]);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return pix;
|
||||
}
|
||||
|
||||
xr_device_color_t
|
||||
xrConvertToGray(xr_device_color_t color)
|
||||
{
|
||||
xr_device_color_t new;
|
||||
|
||||
new.space = gray_colorspace;
|
||||
switch(color.space)
|
||||
{
|
||||
case gray_colorspace:
|
||||
new = color;
|
||||
break;
|
||||
case hsb_colorspace:
|
||||
case cmyk_colorspace:
|
||||
color = xrConvertToRGB(color);
|
||||
/* NO BREAK */
|
||||
case rgb_colorspace:
|
||||
new.field[0] =
|
||||
((0.3*color.field[0]) + (0.59*color.field[1]) + (0.11*color.field[2]));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return new;
|
||||
}
|
||||
|
||||
xr_device_color_t
|
||||
xrConvertToRGB(xr_device_color_t color)
|
||||
{
|
||||
xr_device_color_t new;
|
||||
|
||||
new.space = rgb_colorspace;
|
||||
switch(color.space)
|
||||
{
|
||||
case gray_colorspace:
|
||||
new.field[0] = color.field[0];
|
||||
new.field[1] = color.field[0];
|
||||
new.field[2] = color.field[0];
|
||||
break;
|
||||
case rgb_colorspace:
|
||||
new = color;
|
||||
break;
|
||||
case hsb_colorspace:
|
||||
case cmyk_colorspace:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return new;
|
||||
}
|
||||
|
||||
xr_device_color_t
|
||||
xrConvertToHSB(xr_device_color_t color)
|
||||
{
|
||||
xr_device_color_t new;
|
||||
|
||||
new.space = hsb_colorspace;
|
||||
switch(color.space)
|
||||
{
|
||||
case gray_colorspace:
|
||||
break;
|
||||
case rgb_colorspace:
|
||||
break;
|
||||
case hsb_colorspace:
|
||||
new = color;
|
||||
break;
|
||||
case cmyk_colorspace:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return new;
|
||||
}
|
||||
|
||||
xr_device_color_t
|
||||
xrConvertToCMYK(xr_device_color_t color)
|
||||
{
|
||||
xr_device_color_t new;
|
||||
|
||||
new.space = gray_colorspace;
|
||||
switch(color.space)
|
||||
{
|
||||
case gray_colorspace:
|
||||
break;
|
||||
case rgb_colorspace:
|
||||
break;
|
||||
case hsb_colorspace:
|
||||
break;
|
||||
case cmyk_colorspace:
|
||||
new = color;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return new;
|
||||
}
|
5
Tools/.cvsignore
Normal file
5
Tools/.cvsignore
Normal file
|
@ -0,0 +1,5 @@
|
|||
shared_debug_obj
|
||||
shared_obj
|
||||
xdnd.c
|
||||
xdnd.h
|
||||
XGCommonFont.m
|
57
Tools/GNUmakefile
Normal file
57
Tools/GNUmakefile
Normal file
|
@ -0,0 +1,57 @@
|
|||
#
|
||||
# Tools level makefile for GNUstep Backend Library
|
||||
#
|
||||
# Copyright (C) 1997,1999 Free Software Foundation, Inc.
|
||||
#
|
||||
# Author: Scott Christley <scottc@net-community.com>
|
||||
#
|
||||
# This file is part of the GNUstep GUI Library.
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Library General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This library is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# Library General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Library General Public
|
||||
# License along with this library; see the file COPYING.LIB.
|
||||
# If not, write to the Free Software Foundation,
|
||||
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
GNUSTEP_INSTALLATION_DIR = $(GNUSTEP_SYSTEM_ROOT)
|
||||
|
||||
GNUSTEP_MAKEFILES = $(GNUSTEP_SYSTEM_ROOT)/Makefiles
|
||||
|
||||
GNUSTEP_LOCAL_ADDITIONAL_MAKEFILES=../back.make
|
||||
include $(GNUSTEP_MAKEFILES)/common.make
|
||||
|
||||
include ../Version
|
||||
include ../config.make
|
||||
|
||||
# The applications to be compiled
|
||||
TOOL_NAME = gpbs
|
||||
|
||||
# The source files to be compiled
|
||||
gpbs_OBJC_FILES = gpbs.m
|
||||
font_cacher_OBJC_FILES = font_cacher.m
|
||||
|
||||
ifneq ($(BUILD_X11),)
|
||||
TOOL_NAME += font_cacher
|
||||
gpbs_OBJC_FILES += xpbs.m
|
||||
ifeq ($(BACKEND_BUNDLE),yes)
|
||||
font_cacher_OBJC_FILES += XGCommonFont.m
|
||||
gpbs_C_FILES += xdnd.c
|
||||
endif
|
||||
endif
|
||||
|
||||
-include GNUmakefile.preamble
|
||||
|
||||
-include GNUmakefile.local
|
||||
|
||||
include $(GNUSTEP_MAKEFILES)/tool.make
|
||||
|
||||
-include GNUmakefile.postamble
|
51
Tools/GNUmakefile.postamble
Normal file
51
Tools/GNUmakefile.postamble
Normal file
|
@ -0,0 +1,51 @@
|
|||
#
|
||||
# Makefile.postamble
|
||||
#
|
||||
# Project specific makefile rules
|
||||
#
|
||||
# Uncomment the targets you want.
|
||||
# The double colons (::) are important, do not make them single colons
|
||||
# otherwise the normal makefile rules will not be performed.
|
||||
#
|
||||
|
||||
# Things to do before compiling
|
||||
before-all::
|
||||
-$(RM) XGCommonFont.m
|
||||
$(LN_S) ../Source/xlib/XGCommonFont.m .
|
||||
-$(RM) xdnd.c
|
||||
$(LN_S) ../Source/x11/xdnd.c .
|
||||
|
||||
# Things to do after compiling
|
||||
# after-all::
|
||||
|
||||
# Things to do before installing
|
||||
# before-install::
|
||||
|
||||
# Things to do after installing
|
||||
# after-install::
|
||||
|
||||
# Things to do before uninstalling
|
||||
# before-uninstall::
|
||||
|
||||
# Things to do after uninstalling
|
||||
# after-uninstall::
|
||||
|
||||
# Things to do before cleaning
|
||||
# before-clean::
|
||||
|
||||
# Things to do after cleaning
|
||||
after-clean::
|
||||
-$(RM) XGCommonFont.m
|
||||
-$(RM) xdnd.c
|
||||
|
||||
# Things to do before distcleaning
|
||||
# before-distclean::
|
||||
|
||||
# Things to do after distcleaning
|
||||
# after-distclean::
|
||||
|
||||
# Things to do before checking
|
||||
# before-check::
|
||||
|
||||
# Things to do after checking
|
||||
# after-check::
|
50
Tools/GNUmakefile.preamble
Normal file
50
Tools/GNUmakefile.preamble
Normal file
|
@ -0,0 +1,50 @@
|
|||
#
|
||||
# Makefile.preamble
|
||||
#
|
||||
# Project specific makefile variables, and additional
|
||||
#
|
||||
# Do not put any Makefile rules in this file, instead they should
|
||||
# be put into Makefile.postamble.
|
||||
#
|
||||
|
||||
#
|
||||
# Flags dealing with compiling and linking
|
||||
#
|
||||
|
||||
# Additional flags to pass to the preprocessor
|
||||
#ADDITIONAL_CPPFLAGS +=
|
||||
|
||||
# Additional flags to pass to the Objective-C compiler
|
||||
#ADDITIONAL_OBJCFLAGS +=
|
||||
|
||||
# Additional flags to pass to the C compiler
|
||||
#ADDITIONAL_CFLAGS +=
|
||||
|
||||
# Additional include directories the compiler should search
|
||||
ADDITIONAL_INCLUDE_DIRS += -I../Headers -I../Source/$(GNUSTEP_TARGET_DIR)
|
||||
|
||||
|
||||
# Additional LDFLAGS to pass to the linker
|
||||
# ADDITIONAL_LDFLAGS +=
|
||||
|
||||
# Additional library directories the linker should search
|
||||
ADDITIONAL_LIB_DIRS += -L../Source/$(GNUSTEP_OBJ_DIR)
|
||||
|
||||
# Additional libraries when linking applications
|
||||
#ADDITIONAL_GUI_LIBS +=
|
||||
|
||||
#
|
||||
# Flags dealing with installing and uninstalling
|
||||
#
|
||||
|
||||
# Additional directories to be created during installation
|
||||
ADDITIONAL_INSTALL_DIRS +=
|
||||
|
||||
# Flags for when the backend is compiled as a bundle
|
||||
ifneq ($(BACKEND_BUNDLE),)
|
||||
ADDITIONAL_TOOL_LIBS += $(GUI_LIBS) $(GRAPHIC_LIBS) $(SYSTEM_LIBS)
|
||||
ADDITIONAL_INCLUDE_DIRS += $(GRAPHIC_CFLAGS)
|
||||
ADDITIONAL_LIB_DIRS += $(GRAPHIC_LFLAGS)
|
||||
else
|
||||
ADDITIONAL_TOOL_LIBS += -lgnustep-gui -lgnustep-back $(SYSTEM_LIBS)
|
||||
endif
|
553
Tools/font_cacher.m
Normal file
553
Tools/font_cacher.m
Normal file
|
@ -0,0 +1,553 @@
|
|||
/*
|
||||
Font cacher for GNUstep GUI X/GPS Backend
|
||||
|
||||
Copyright (C) 2000 Free Software Foundation, Inc.
|
||||
|
||||
Author: Fred Kiefer <FredKiefer@gmx.de> and Richard Frith-Macdonald
|
||||
Date: Febuary 2000
|
||||
|
||||
This file is part of the GNUstep GUI X/GPS Library.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <Foundation/Foundation.h>
|
||||
#include <X11/Xatom.h>
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xutil.h>
|
||||
#include <gnustep/xgps/XGContextPrivate.h>
|
||||
|
||||
#define stringify_it(X) #X
|
||||
#define makever(X) stringify_it(X)
|
||||
|
||||
@interface XFontCacher : NSObject
|
||||
{
|
||||
NSMutableSet *allFontNames;
|
||||
NSMutableDictionary *allFontFamilies;
|
||||
NSMutableDictionary *creationDictionary;
|
||||
NSMutableDictionary *xFontDictionary;
|
||||
NSMutableSet *knownFonts;
|
||||
Display *dpy;
|
||||
}
|
||||
|
||||
- (NSString*) faceNameFromParts: (NSArray*) parts;
|
||||
- (NSString*) creationNameFromParts: (NSArray*) parts;
|
||||
- (NSString*) getPathFor: (NSString*) display;
|
||||
- (BOOL) fontLoop;
|
||||
- (BOOL) processPattern: (const char *) pattern;
|
||||
- (void) processFont: (char*) name;
|
||||
- (void) sortResults;
|
||||
- (void) writeCacheTo: (NSString*)path;
|
||||
@end
|
||||
|
||||
@implementation XFontCacher
|
||||
|
||||
- (id) init
|
||||
{
|
||||
allFontNames = RETAIN([NSMutableSet setWithCapacity: 1000]);
|
||||
allFontFamilies = RETAIN([NSMutableDictionary dictionaryWithCapacity: 1000]);
|
||||
creationDictionary = RETAIN([NSMutableDictionary dictionaryWithCapacity: 1000]);
|
||||
xFontDictionary = RETAIN([NSMutableDictionary dictionaryWithCapacity: 1000]);
|
||||
knownFonts = RETAIN([NSMutableSet setWithCapacity: 1000]);
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
RELEASE(allFontNames);
|
||||
RELEASE(allFontFamilies);
|
||||
RELEASE(creationDictionary);
|
||||
RELEASE(xFontDictionary);
|
||||
RELEASE(knownFonts);
|
||||
|
||||
if (dpy)
|
||||
XCloseDisplay(dpy);
|
||||
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
/*
|
||||
* Find a suitable type face name for a full X font name, which
|
||||
* has already been split into parts seperated by -
|
||||
* -sony-fixed-medium-r-normal--16-150-75-75-c-80-iso8859-1
|
||||
* becomes Normal
|
||||
*/
|
||||
- (NSString*) faceNameFromParts: (NSArray*) parts
|
||||
{
|
||||
NSString *faceName;
|
||||
NSString *face = [[parts objectAtIndex: 3] capitalizedString];
|
||||
NSString *slant = [[parts objectAtIndex: 4] capitalizedString];
|
||||
NSString *weight = [[parts objectAtIndex: 5] capitalizedString];
|
||||
NSString *add = [[parts objectAtIndex: 6] capitalizedString];
|
||||
|
||||
if ([face length] == 0 || [face isEqualToString: @"Medium"])
|
||||
faceName = @"";
|
||||
else
|
||||
faceName = face;
|
||||
|
||||
if ([slant isEqualToString: @"I"])
|
||||
faceName = [NSString stringWithFormat: @"%@%@", faceName, @"Italic"];
|
||||
else if ([slant isEqualToString: @"O"])
|
||||
faceName = [NSString stringWithFormat: @"%@%@", faceName, @"Oblique"];
|
||||
|
||||
if ([weight length] != 0 && ![weight isEqualToString: @"Normal"])
|
||||
{
|
||||
if ([faceName length] != 0)
|
||||
faceName = [NSString stringWithFormat: @"%@-%@", faceName, weight];
|
||||
else
|
||||
faceName = weight;
|
||||
}
|
||||
|
||||
if ([add length] != 0)
|
||||
{
|
||||
if ([faceName length] != 0)
|
||||
faceName = [NSString stringWithFormat: @"%@-%@", faceName, add];
|
||||
else
|
||||
faceName = add;
|
||||
}
|
||||
|
||||
if ([faceName length] == 0)
|
||||
faceName = @"Normal";
|
||||
|
||||
return faceName;
|
||||
}
|
||||
|
||||
/*
|
||||
* Build up an X font creation string
|
||||
* -sony-fixed-medium-r-normal--16-150-75-75-c-80-iso8859-1
|
||||
* becomes
|
||||
* -*-fixed-medium-r-normal--%d-*-*-*-c-*-iso8859-1
|
||||
*/
|
||||
- (NSString*) creationNameFromParts: (NSArray*) parts
|
||||
{
|
||||
NSString *creationName;
|
||||
|
||||
creationName = [NSString stringWithFormat:
|
||||
@"-%@-%@-%@-%@-%@-%@-%@-%@-%@-%@-%@-%@-%@-%@",
|
||||
@"*",
|
||||
[parts objectAtIndex: 2],
|
||||
[parts objectAtIndex: 3],
|
||||
[parts objectAtIndex: 4],
|
||||
[parts objectAtIndex: 5],
|
||||
[parts objectAtIndex: 6],
|
||||
@"%d",//[parts objectAtIndex: 7],
|
||||
@"*", // place holder for integer size (points *10)
|
||||
@"*",//[parts objectAtIndex: 9],
|
||||
@"*",//[parts objectAtIndex: 10],
|
||||
[parts objectAtIndex: 11],
|
||||
@"*",//[parts objectAtIndex: 12],
|
||||
[parts objectAtIndex: 13],
|
||||
[parts objectAtIndex: 14]];
|
||||
|
||||
return creationName;
|
||||
}
|
||||
|
||||
- (NSString*) getPathFor: (NSString*) display
|
||||
{
|
||||
NSArray *paths;
|
||||
NSFileManager *mgr;
|
||||
NSString *path;
|
||||
const char *display_name;
|
||||
BOOL flag;
|
||||
|
||||
if (display != nil)
|
||||
display_name = [display cString];
|
||||
else
|
||||
{
|
||||
display = [NSString stringWithCString: XDisplayName(0)];
|
||||
display_name = NULL;
|
||||
}
|
||||
|
||||
dpy = XOpenDisplay(display_name);
|
||||
if (dpy == 0)
|
||||
{
|
||||
NSLog(@"Unable to open X display - no font information available");
|
||||
return nil;
|
||||
}
|
||||
|
||||
paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory,
|
||||
NSUserDomainMask, YES);
|
||||
if ((paths != nil) && ([paths count] > 0))
|
||||
{
|
||||
path = [paths objectAtIndex: 0];
|
||||
}
|
||||
else
|
||||
{
|
||||
NSLog(@" No valid path for cached information exists. You ");
|
||||
NSLog(@" should create ~/GNUstep/Library by hand");
|
||||
return nil;
|
||||
}
|
||||
|
||||
mgr = [NSFileManager defaultManager];
|
||||
if ([mgr fileExistsAtPath: path isDirectory: &flag] == NO || flag == NO)
|
||||
{
|
||||
NSLog(@"Library directory '%@' not available!", path);
|
||||
return nil;
|
||||
}
|
||||
path = [path stringByAppendingPathComponent: @"Fonts"];
|
||||
if ([mgr fileExistsAtPath: path] == NO)
|
||||
{
|
||||
[mgr createDirectoryAtPath: path attributes: nil];
|
||||
}
|
||||
if ([mgr fileExistsAtPath: path isDirectory: &flag] == NO || flag == NO)
|
||||
{
|
||||
NSLog(@"Fonts directory '%@' not available!", path);
|
||||
return nil;
|
||||
}
|
||||
path = [path stringByAppendingPathComponent: @"Cache"];
|
||||
if ([mgr fileExistsAtPath: path] == NO)
|
||||
{
|
||||
[mgr createDirectoryAtPath: path attributes: nil];
|
||||
}
|
||||
if ([mgr fileExistsAtPath: path isDirectory: &flag] == NO || flag == NO)
|
||||
{
|
||||
NSLog(@"Fonts directory '%@' not available!", path);
|
||||
return nil;
|
||||
}
|
||||
|
||||
return [path stringByAppendingPathComponent: display];
|
||||
}
|
||||
|
||||
- (BOOL) fontLoop
|
||||
{
|
||||
NSUserDefaults *defs;
|
||||
const char *pattern = "*";
|
||||
BOOL result;
|
||||
|
||||
defs = [NSUserDefaults standardUserDefaults];
|
||||
if (defs == nil)
|
||||
NSLog(@"Unable to access defaults database!");
|
||||
else
|
||||
{
|
||||
NSString *font_mask;
|
||||
|
||||
font_mask = [defs stringForKey: @"GSFontMask"];
|
||||
if ((font_mask != nil) && [font_mask length])
|
||||
// only fonts matching the supplied mask will be cached
|
||||
pattern = [font_mask lossyCString];
|
||||
}
|
||||
|
||||
// In a next step we allow multiple font masks
|
||||
result = [self processPattern: pattern];
|
||||
|
||||
// No longer needed
|
||||
DESTROY(knownFonts);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
- (BOOL) processPattern: (const char *) pattern
|
||||
{
|
||||
NSAutoreleasePool *loopPool;
|
||||
int nnames = 10000;
|
||||
int available = nnames+1;
|
||||
int i;
|
||||
char **fonts;
|
||||
|
||||
/* Get list of all fonts */
|
||||
for (;;)
|
||||
{
|
||||
fonts = XListFonts(dpy, pattern, nnames, &available);
|
||||
if (fonts == NULL || available < nnames)
|
||||
break;
|
||||
/* There are more fonts then we expected, so just start
|
||||
again and request more */
|
||||
XFreeFontNames(fonts);
|
||||
nnames = available * 2;
|
||||
}
|
||||
|
||||
if (fonts == NULL)
|
||||
{
|
||||
NSLog(@"No X fonts found for pattern %s", pattern);
|
||||
return NO;
|
||||
}
|
||||
|
||||
NSDebugFLog(@"Fonts loaded, now the loop. Available: %d", available);
|
||||
|
||||
loopPool = [NSAutoreleasePool new];
|
||||
|
||||
for (i = 0; i < available; i++)
|
||||
{
|
||||
char *name = fonts[i];
|
||||
|
||||
NS_DURING
|
||||
[self processFont: name];
|
||||
NS_HANDLER
|
||||
NSLog(@"Problem during processing of font %s", name);
|
||||
NS_ENDHANDLER
|
||||
|
||||
if (i && i % 500 == 0)
|
||||
{
|
||||
NSDebugLog(@"Finished %d", i);
|
||||
RELEASE (loopPool);
|
||||
loopPool = [NSAutoreleasePool new];
|
||||
}
|
||||
}
|
||||
RELEASE (loopPool);
|
||||
XFreeFontNames(fonts);
|
||||
NSDebugLog(@"Finished loop");
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void) processFont: (char*) name
|
||||
{
|
||||
NSString *alias = [[NSString stringWithCString: name] lowercaseString];
|
||||
NSString *fontName;
|
||||
|
||||
/*
|
||||
* First time we find this font. A font may be found more than
|
||||
* once, when the XFontPath has the same directory twice.
|
||||
* Somehow this is the case on my machine.
|
||||
*/
|
||||
if ([xFontDictionary objectForKey: alias] == nil)
|
||||
{
|
||||
XFontStruct *info = XLoadQueryFont(dpy, name);
|
||||
NSString *family;
|
||||
NSString *baseName;
|
||||
NSString *face;
|
||||
NSString *creationName;
|
||||
NSArray *parts;
|
||||
|
||||
if (info == 0)
|
||||
{
|
||||
NSDebugLog(@"No information for font %s", name);
|
||||
return;
|
||||
}
|
||||
|
||||
fontName = XGFontName(dpy, info);
|
||||
if (fontName == nil)
|
||||
{
|
||||
NSDebugLog(@"No font Name in info for font %s", name);
|
||||
XFreeFont(dpy, info);
|
||||
return;
|
||||
}
|
||||
|
||||
if ([alias isEqualToString: fontName] == NO)
|
||||
{
|
||||
// We have got an alias name, store it
|
||||
[xFontDictionary setObject: fontName forKey: alias];
|
||||
}
|
||||
|
||||
// Use the normal function to keep the names consistent
|
||||
family = XGFontFamily(dpy, info);
|
||||
|
||||
parts = [fontName componentsSeparatedByString: @"-"];
|
||||
if ([parts count] == 15)
|
||||
{
|
||||
face = [self faceNameFromParts: parts];
|
||||
if ([face length] == 0 || [face isEqualToString: @"Normal"])
|
||||
{
|
||||
baseName = family;
|
||||
}
|
||||
else
|
||||
baseName = [NSString stringWithFormat: @"%@-%@", family, face];
|
||||
|
||||
creationName = [self creationNameFromParts: parts];
|
||||
}
|
||||
else
|
||||
{
|
||||
baseName = [fontName capitalizedString];
|
||||
face = @"Normal";
|
||||
creationName = fontName;
|
||||
}
|
||||
|
||||
// Store the alias to baseName
|
||||
[xFontDictionary setObject: baseName forKey: fontName];
|
||||
// it might already have been found with another size
|
||||
if ([knownFonts member: baseName] == nil)
|
||||
{
|
||||
int weight;
|
||||
NSFontTraitMask traits;
|
||||
NSMutableArray *fontDefs;
|
||||
NSMutableArray *fontDef;
|
||||
|
||||
// the first time we find that base font.
|
||||
|
||||
// Store the font name
|
||||
[knownFonts addObject: baseName];
|
||||
[allFontNames addObject: baseName];
|
||||
[creationDictionary setObject: creationName forKey: baseName];
|
||||
|
||||
weight = XGWeightOfFont(dpy, info);
|
||||
traits = XGTraitsOfFont(dpy, info);
|
||||
|
||||
// Store the family name and information
|
||||
fontDefs = [allFontFamilies objectForKey: family];
|
||||
if (fontDefs == nil)
|
||||
{
|
||||
fontDefs = [NSMutableArray array];
|
||||
[allFontFamilies setObject: fontDefs forKey: family];
|
||||
}
|
||||
// Fill the structure for the font
|
||||
fontDef = [NSMutableArray arrayWithCapacity: 4];
|
||||
[fontDef addObject: baseName];
|
||||
[fontDef addObject: face];
|
||||
[fontDef addObject: [NSNumber numberWithInt: weight]];
|
||||
[fontDef addObject: [NSNumber numberWithUnsignedInt: traits]];
|
||||
// Add to the family information
|
||||
[fontDefs addObject: fontDef];
|
||||
}
|
||||
// Release the font
|
||||
XFreeFont(dpy, info);
|
||||
}
|
||||
}
|
||||
|
||||
static int fontDefSorter(NSArray *el1, NSArray *el2, void *context)
|
||||
{
|
||||
// This is not exactly the order the OpenStep specification states.
|
||||
NSFontTraitMask t1 = [[el1 objectAtIndex: 3] unsignedIntValue];
|
||||
NSFontTraitMask t2 = [[el2 objectAtIndex: 3] unsignedIntValue];
|
||||
int w1 = [[el1 objectAtIndex: 2] intValue];
|
||||
int w2 = [[el2 objectAtIndex: 2] intValue];
|
||||
|
||||
if (t1 < t2)
|
||||
return NSOrderedAscending;
|
||||
else if (t2 < t1)
|
||||
return NSOrderedDescending;
|
||||
else if (w1 < w2)
|
||||
return NSOrderedAscending;
|
||||
else if(w2 < w1)
|
||||
return NSOrderedDescending;
|
||||
|
||||
return NSOrderedSame;
|
||||
}
|
||||
|
||||
- (void) sortResults
|
||||
{
|
||||
NSEnumerator *enumerator;
|
||||
id key;
|
||||
|
||||
// Now sort the fonts of each family
|
||||
enumerator = [allFontFamilies keyEnumerator];
|
||||
while ((key = [enumerator nextObject]))
|
||||
{
|
||||
NSMutableArray *fontDefs = [allFontFamilies objectForKey: key];
|
||||
|
||||
[fontDefs sortUsingFunction: fontDefSorter context: nil];
|
||||
}
|
||||
|
||||
|
||||
// define a creation string for alias names
|
||||
enumerator = [xFontDictionary keyEnumerator];
|
||||
while ((key = [enumerator nextObject]))
|
||||
{
|
||||
id name = key;
|
||||
id creationName;
|
||||
|
||||
while ((name != nil)
|
||||
&& (creationName = [creationDictionary objectForKey: name]) == nil)
|
||||
{
|
||||
name = [xFontDictionary objectForKey: name];
|
||||
}
|
||||
|
||||
if (creationName != nil)
|
||||
{
|
||||
[creationDictionary setObject: creationName forKey: key];
|
||||
}
|
||||
}
|
||||
// No longer needed
|
||||
DESTROY(xFontDictionary);
|
||||
}
|
||||
|
||||
- (void) writeCacheTo: (NSString*)path
|
||||
{
|
||||
NSData *data;
|
||||
NSMutableDictionary *cache = [NSMutableDictionary dictionaryWithCapacity: 4];
|
||||
|
||||
[cache setObject: [NSNumber numberWithInt: 2] forKey: @"Version"];
|
||||
[cache setObject: allFontNames forKey: @"AllFontNames"];
|
||||
[cache setObject: allFontFamilies forKey: @"AllFontFamilies"];
|
||||
[cache setObject: creationDictionary forKey: @"CreationDictionary"];
|
||||
data = [NSArchiver archivedDataWithRootObject: cache];
|
||||
[data writeToFile: path atomically: YES];
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv, char **env)
|
||||
{
|
||||
NSArray *args;
|
||||
NSArray *paths;
|
||||
NSString *path;
|
||||
NSString *file_name;
|
||||
XFontCacher *cacher;
|
||||
CREATE_AUTORELEASE_POOL(pool);
|
||||
|
||||
#ifdef GS_PASS_ARGUMENTS
|
||||
[NSProcessInfo initializeWithArguments: argv count: argc environment: env];
|
||||
#endif
|
||||
|
||||
args = [[NSProcessInfo processInfo] arguments];
|
||||
if ([args containsObject: @"--help"])
|
||||
{
|
||||
paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory,
|
||||
NSUserDomainMask, YES);
|
||||
if ((paths != nil) && ([paths count] > 0))
|
||||
path = [paths objectAtIndex: 0];
|
||||
else
|
||||
path = nil;
|
||||
|
||||
NSLog(@"This tool caches system font information\n");
|
||||
if (path != nil)
|
||||
NSLog(@" Information is cached in %@/Fonts/Cache/<XDisplayName>", path);
|
||||
else
|
||||
{
|
||||
NSLog(@" No valid path for cached information exists. You ");
|
||||
NSLog(@" should create ~/GNUstep/Library by hand");
|
||||
}
|
||||
RELEASE(pool);
|
||||
return 0;
|
||||
}
|
||||
if ([args containsObject: @"--version"])
|
||||
{
|
||||
NSLog(@"%@ version %s", [[args objectAtIndex: 0] lastPathComponent],
|
||||
makever(GNUSTEP_VERSION));
|
||||
RELEASE(pool);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ([args count] > 1)
|
||||
file_name = [args objectAtIndex: 1];
|
||||
else
|
||||
file_name = nil;
|
||||
|
||||
cacher = [[XFontCacher alloc] init];
|
||||
path = [cacher getPathFor: file_name];
|
||||
if (path == nil)
|
||||
{
|
||||
RELEASE(pool);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (![cacher fontLoop])
|
||||
{
|
||||
RELEASE(pool);
|
||||
return 2;
|
||||
}
|
||||
|
||||
[cacher sortResults];
|
||||
NS_DURING
|
||||
[cacher writeCacheTo: path];
|
||||
NS_HANDLER
|
||||
NSLog(@"Problem during writing of font cache");
|
||||
NS_ENDHANDLER
|
||||
|
||||
RELEASE(cacher);
|
||||
RELEASE(pool);
|
||||
return 0;
|
||||
}
|
||||
|
1178
Tools/gpbs.m
Normal file
1178
Tools/gpbs.m
Normal file
File diff suppressed because it is too large
Load diff
1215
Tools/xpbs.m
Normal file
1215
Tools/xpbs.m
Normal file
File diff suppressed because it is too large
Load diff
13
Version
Normal file
13
Version
Normal file
|
@ -0,0 +1,13 @@
|
|||
# This file is included in various Makefile's to get version information.
|
||||
# Copyright (C) 2002 Free Software Foundation
|
||||
|
||||
# The version number of this release.
|
||||
GNUSTEP_BACK_MAJOR_VERSION=0
|
||||
GNUSTEP_BACK_MINOR_VERSION=7
|
||||
GNUSTEP_BACK_SUBMINOR_VERSION=5
|
||||
GNUSTEP_BACK_VERSION=${GNUSTEP_BACK_MAJOR_VERSION}.${GNUSTEP_BACK_MINOR_VERSION}.${GNUSTEP_BACK_SUBMINOR_VERSION}
|
||||
VERSION=${GNUSTEP_BACK_VERSION}
|
||||
|
||||
GNUSTEP_BACK_FTP_MACHINE=ftp.gnustep.org
|
||||
GNUSTEP_BACK_FTP_DIRECTORY=pub/gnustep/core
|
||||
|
16
acconfig.h
Normal file
16
acconfig.h
Normal file
|
@ -0,0 +1,16 @@
|
|||
/* Macros that may be defined by the aclocal.m4 extentions to `configure'
|
||||
for GNUstep XGPS Library. */
|
||||
|
||||
#undef XSHM
|
||||
|
||||
#undef WITH_WRASTER
|
||||
|
||||
#undef HAVE_XFT
|
||||
|
||||
#undef USE_XIM
|
||||
|
||||
#undef BUILD_XLIB
|
||||
#undef BUILD_XDPS
|
||||
#undef BUILD_X11
|
||||
#undef BUILD_WIN32
|
||||
#undef BUILD_WINLIB
|
44
back.make.in
Normal file
44
back.make.in
Normal file
|
@ -0,0 +1,44 @@
|
|||
# -*-makefile-*-
|
||||
# back.make
|
||||
#
|
||||
# Makefile flags and configs to build with the back library.
|
||||
#
|
||||
# Copyright (C) 2001 Free Software Foundation, Inc.
|
||||
#
|
||||
# Author: Nicola Pero <n.pero@mi.flashnet.it>
|
||||
# Based on code originally in the gnustep make package
|
||||
#
|
||||
# This file is part of the GNUstep Back Library.
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public
|
||||
# License along with this library; see the file COPYING.LIB.
|
||||
# If not, write to the Free Software Foundation,
|
||||
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
ifeq ($(BACK_MAKE_LOADED),)
|
||||
BACK_MAKE_LOADED=yes
|
||||
|
||||
ifeq ($(BACKEND_BUNDLE),)
|
||||
GRAPHIC_LIBS=@GRAPHIC_LIBS@
|
||||
GRAPHIC_CFLAGS=@GRAPHIC_CFLAGS@
|
||||
GRAPHIC_LFLAGS=@GRAPHIC_LFLAGS@
|
||||
X_PRE_LIBS=@X_PRE_LIBS@
|
||||
|
||||
BACKEND_LDFLAGS =
|
||||
BACKEND_LIBS = -lgnustep-back
|
||||
BACKEND_DEFINE = -DBACKEND_LIBRARY=1
|
||||
|
||||
SYSTEM_INCLUDES = $(CONFIG_SYSTEM_INCL) $(GRAPHIC_CFLAGS)
|
||||
SYSTEM_LDFLAGS =
|
||||
SYSTEM_LIB_DIR = $(GRAPHIC_LFLAGS)
|
||||
SYSTEM_LIBS = $(GRAPHIC_LIBS)
|
||||
endif
|
||||
|
||||
endif # BACK_MAKE_LOADED
|
||||
|
||||
|
28
config.h
Normal file
28
config.h
Normal file
|
@ -0,0 +1,28 @@
|
|||
/* config.h. Generated automatically by configure. */
|
||||
/* config.h.in. Generated automatically from configure.in by autoheader. */
|
||||
|
||||
/* Define if the X Window System is missing or not being used. */
|
||||
/* #undef X_DISPLAY_MISSING */
|
||||
|
||||
#define XSHM 1
|
||||
|
||||
#define WITH_WRASTER 1
|
||||
|
||||
#define HAVE_XFT 1
|
||||
|
||||
/* #undef USE_XIM */
|
||||
|
||||
/* #undef BUILD_XLIB */
|
||||
#define BUILD_XDPS 1
|
||||
#define BUILD_X11 1
|
||||
/* #undef BUILD_WIN32 */
|
||||
/* #undef BUILD_WINLIB */
|
||||
|
||||
/* Define if you have the <DPS/dpsNXargs.h> header file. */
|
||||
#define HAVE_DPS_DPSNXARGS_H 1
|
||||
|
||||
/* Define if you have the <DPS/dpsclient.h> header file. */
|
||||
#define HAVE_DPS_DPSCLIENT_H 1
|
||||
|
||||
/* Define if you have the <wraster.h> header file. */
|
||||
/* #undef HAVE_WRASTER_H */
|
27
config.h.in
Normal file
27
config.h.in
Normal file
|
@ -0,0 +1,27 @@
|
|||
/* config.h.in. Generated automatically from configure.in by autoheader. */
|
||||
|
||||
/* Define if the X Window System is missing or not being used. */
|
||||
#undef X_DISPLAY_MISSING
|
||||
|
||||
#undef XSHM
|
||||
|
||||
#undef WITH_WRASTER
|
||||
|
||||
#undef HAVE_XFT
|
||||
|
||||
#undef USE_XIM
|
||||
|
||||
#undef BUILD_XLIB
|
||||
#undef BUILD_XDPS
|
||||
#undef BUILD_X11
|
||||
#undef BUILD_WIN32
|
||||
#undef BUILD_WINLIB
|
||||
|
||||
/* Define if you have the <DPS/dpsNXargs.h> header file. */
|
||||
#undef HAVE_DPS_DPSNXARGS_H
|
||||
|
||||
/* Define if you have the <DPS/dpsclient.h> header file. */
|
||||
#undef HAVE_DPS_DPSCLIENT_H
|
||||
|
||||
/* Define if you have the <wraster.h> header file. */
|
||||
#undef HAVE_WRASTER_H
|
17
config.make.in
Normal file
17
config.make.in
Normal file
|
@ -0,0 +1,17 @@
|
|||
# -*-makefile-*-
|
||||
# Extra make variables for backend library
|
||||
#
|
||||
|
||||
WITH_WRASTER=@WITH_WRASTER@
|
||||
WITH_XFT=@WITH_XFT@
|
||||
|
||||
GRAPHIC_LIBS=@GRAPHIC_LIBS@
|
||||
GRAPHIC_CFLAGS=@GRAPHIC_CFLAGS@
|
||||
GRAPHIC_LFLAGS=@GRAPHIC_LFLAGS@
|
||||
X_PRE_LIBS=@X_PRE_LIBS@
|
||||
|
||||
BUILD_XLIB=@BUILD_XLIB@
|
||||
BUILD_XDPS=@BUILD_XDPS@
|
||||
BUILD_X11=@BUILD_X11@
|
||||
BUILD_WIN32=@BUILD_WIN32@
|
||||
BUILD_WINLIB=@BUILD_WINLIB@
|
414
configure.in
Normal file
414
configure.in
Normal file
|
@ -0,0 +1,414 @@
|
|||
# configure.in for GNUstep GUI Backend
|
||||
# Process this file with autoconf to produce a configure script.
|
||||
#
|
||||
# Copyright (C) 1996-2002 Free Software Foundation, Inc.
|
||||
#
|
||||
# Author: Adam Fedor <fedor@gnu.org>
|
||||
#
|
||||
# This file is part of the GNUstep Backend.
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Library General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This library is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# Library General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Library General Public
|
||||
# License along with this library; see the file COPYING.LIB.
|
||||
# If not, write to the Free Software Foundation,
|
||||
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
#
|
||||
|
||||
AC_INIT(back.make.in)
|
||||
|
||||
if test -z "$GNUSTEP_SYSTEM_ROOT"; then
|
||||
AC_MSG_ERROR(You must run the GNUstep.sh script before configuring)
|
||||
fi
|
||||
|
||||
#--------------------------------------------------------------------
|
||||
# Use config.guess, config.sub and install-sh provided by gnustep-make
|
||||
#--------------------------------------------------------------------
|
||||
AC_CONFIG_AUX_DIR($GNUSTEP_SYSTEM_ROOT/Makefiles)
|
||||
|
||||
AC_CONFIG_HEADER(config.h)
|
||||
|
||||
#--------------------------------------------------------------------
|
||||
# Determine the host, build, and target systems
|
||||
#--------------------------------------------------------------------
|
||||
AC_CANONICAL_SYSTEM
|
||||
|
||||
#--------------------------------------------------------------------
|
||||
# The following is so that headers and custom libraries
|
||||
# in the GNUstep root are used before the standard ones
|
||||
#--------------------------------------------------------------------
|
||||
# Set location of GNUstep dirs for later use
|
||||
GNUSTEP_HDIR=$GNUSTEP_SYSTEM_ROOT/Headers
|
||||
if test "$GNUSTEP_FLATTENED" = yes; then
|
||||
GNUSTEP_LDIR=$GNUSTEP_SYSTEM_ROOT/Libraries
|
||||
else
|
||||
clean_target_os=`$GNUSTEP_SYSTEM_ROOT/Makefiles/clean_os.sh $target_os`
|
||||
clean_target_cpu=`$GNUSTEP_SYSTEM_ROOT/Makefiles/clean_cpu.sh $target_cpu`
|
||||
obj_dir=$clean_target_cpu/$clean_target_os
|
||||
GNUSTEP_LDIR=$GNUSTEP_SYSTEM_ROOT/Libraries/$obj_dir
|
||||
fi
|
||||
CPPFLAGS="$CPPFLAGS -I$GNUSTEP_HDIR"
|
||||
LDFLAGS="$LDFLAGS -L$GNUSTEP_LDIR/$LIBRARY_COMBO -L$GNUSTEP_LDIR"
|
||||
|
||||
AC_PROG_CC
|
||||
|
||||
#--------------------------------------------------------------------
|
||||
# Look for WindowMaker's wraster library
|
||||
#--------------------------------------------------------------------
|
||||
AC_ARG_WITH(wraster,
|
||||
[ --with-wraster=PREFIX get-wraster-flags directory prefix])
|
||||
if test "x$with_wraster" = "x"; then
|
||||
wprefix=""
|
||||
else
|
||||
wprefix=${with_wraster}/
|
||||
fi
|
||||
|
||||
GRAPHIC_LIBS=`${wprefix}get-wraster-flags --libs`
|
||||
GRAPHIC_CFLAGS=`${wprefix}get-wraster-flags --cflags`
|
||||
GRAPHIC_LFLAGS=`${wprefix}get-wraster-flags --ldflags`
|
||||
|
||||
AC_DEFUN(AC_CHECK_WRASTER,
|
||||
[dnl
|
||||
AC_MSG_CHECKING(for current libwraster support)
|
||||
AC_CACHE_VAL(gs_cv_have_wraster,
|
||||
[wraster_check_save_header=${CPPFLAGS}
|
||||
wraster_check_save_libs=${LIBS}
|
||||
CPPFLAGS="$1 $2 ${CPPFLAGS}"
|
||||
LIBS="$3 $LIBS"
|
||||
|
||||
# Check for RFillImage which is only in version 2.0 or libwraster
|
||||
AC_CHECK_LIB(wraster, RFillImage, gs_cv_have_wraster=yes, gs_cv_have_wraster=no)
|
||||
if test "$gs_cv_have_wraster" = yes; then
|
||||
AC_CHECK_HEADERS(wraster.h, gs_cv_have_wraster=yes, gs_cv_have_wraster=no)
|
||||
fi
|
||||
CPPFLAGS="${wraster_check_save_header}"
|
||||
LIBS="${wraster_check_save_libs}"
|
||||
])
|
||||
AC_MSG_RESULT($gs_cv_have_wraster)
|
||||
])
|
||||
|
||||
AC_CHECK_WRASTER(${GRAPHIC_CFLAGS}, ${GRAPHIC_LFLAGS}, ${GRAPHIC_LIBS})
|
||||
if test $gs_cv_have_wraster = no; then
|
||||
GRAPHIC_LIBS=
|
||||
GRAPHIC_CFLAGS=
|
||||
GRAPHIC_LFLAGS=
|
||||
fi
|
||||
|
||||
#--------------------------------------------------------------------
|
||||
# Find for X windows
|
||||
#--------------------------------------------------------------------
|
||||
# If the user specifically set x_include/x_libs, then assume we're
|
||||
# using a special X system and discard any previous GRAPHIC_flags
|
||||
set_x_paths=no
|
||||
if test $gs_cv_have_wraster = no -o $x_includes != NONE; then
|
||||
set_x_paths=yes
|
||||
fi
|
||||
AC_PATH_XTRA
|
||||
|
||||
if test $set_x_paths = yes; then
|
||||
GRAPHIC_CFLAGS="$X_CFLAGS"
|
||||
GRAPHIC_LFLAGS="$X_LIBS"
|
||||
GRAPHIC_LIBS="$X_EXTRA_LIBS"
|
||||
|
||||
lib_save_header=${CPPFLAGS}
|
||||
lib_save_libs=${LIBS}
|
||||
CPPFLAGS="${GRAPHIC_CFLAGS} ${GRAPHIC_LFLAGS} ${CPPFLAGS}"
|
||||
LIBS="${GRAPHIC_LIBS} ${LIBS}"
|
||||
AC_CHECK_LIB(Xext, main, have_xext=1, have_xext=0)
|
||||
if test $have_xext = 1; then
|
||||
GRAPHIC_LIBS="-lX11 -lXext ${GRAPHIC_LIBS}"
|
||||
else
|
||||
GRAPHIC_LIBS="-lX11 ${GRAPHIC_LIBS}"
|
||||
fi
|
||||
LIBS="${GRAPHIC_LIBS} ${LIBS}"
|
||||
AC_CHECK_LIB(Xmu, main, have_xmu=1, have_xmu=0)
|
||||
CPPFLAGS="${lib_save_header}"
|
||||
LIBS="${lib_save_libs}"
|
||||
if test $have_xmu = 1; then
|
||||
GRAPHIC_LIBS="-lXmu ${GRAPHIC_LIBS}"
|
||||
fi
|
||||
fi
|
||||
if test -r $x_includes/X11/DPS; then
|
||||
GRAPHIC_CFLAGS="-I$x_includes/X11 $GRAPHIC_CFLAGS"
|
||||
fi
|
||||
AC_SUBST(X_PRE_LIBS)
|
||||
|
||||
#--------------------------------------------------------------------
|
||||
# Find for DPS
|
||||
#--------------------------------------------------------------------
|
||||
AC_ARG_WITH(dps_library,
|
||||
[ --with-dps-library=DIR DPS library file are in DIR], ,
|
||||
with_dps_library=)
|
||||
AC_ARG_WITH(dps_include,
|
||||
[ --with-dps-include=DIR DPS include files are in DIR], ,
|
||||
with_dps_include=)
|
||||
|
||||
# Add the target header file directory as an include path so that the
|
||||
# check for dpsNXargs.h below looks at the appropriate target includes
|
||||
ORIG_CPPFLAGS=${CPPFLAGS}
|
||||
if test -n "$with_dps_include"; then
|
||||
GRAPHIC_CFLAGS="-I$with_dps_include $GRAPHIC_CFLAGS"
|
||||
fi
|
||||
if test -n "$with_dps_library"; then
|
||||
GRAPHIC_LFLAGS="-L$with_dps_library $GRAPHIC_LFLAGS"
|
||||
fi
|
||||
CPPFLAGS="${CPPFLAGS} ${GRAPHIC_CFLAGS}"
|
||||
|
||||
AC_HAVE_HEADERS(DPS/dpsclient.h DPS/dpsNXargs.h)
|
||||
|
||||
# Restore back to the original
|
||||
CPPFLAGS=${ORIG_CPPFLAGS}
|
||||
|
||||
AC_SUBST(DPS_DEFINE)
|
||||
|
||||
#--------------------------------------------------------------------
|
||||
# XIM support
|
||||
#--------------------------------------------------------------------
|
||||
AC_ARG_ENABLE(xim,
|
||||
[ --enable-xim Enable XIM support],,
|
||||
enable_xim=no)
|
||||
if test "x$enable_xim" = "xyes"; then
|
||||
AC_DEFINE(USE_XIM)
|
||||
fi
|
||||
|
||||
#--------------------------------------------------------------------
|
||||
# Extended font support
|
||||
#--------------------------------------------------------------------
|
||||
WITH_XFT=no
|
||||
save_header=${CPPFLAGS}
|
||||
save_libs=${LIBS}
|
||||
CPPFLAGS="${GRAPHIC_CFLAGS} ${GRAPHIC_LFLAGS} ${CPPFLAGS}"
|
||||
LIBS="${GRAPHIC_LIBS} ${LIBS}"
|
||||
AC_CHECK_LIB(Xft, XftFontOpen, have_xft=yes, have_xft=no)
|
||||
AC_CHECK_HEADER(X11/Xft/Xft.h)
|
||||
if test "$have_xft" = yes -a "$ac_cv_header_X11_Xft_Xft_h" = yes; then
|
||||
GRAPHIC_LIBS="-lXft ${GRAPHIC_LIBS}"
|
||||
WITH_XFT=yes
|
||||
AC_DEFINE(HAVE_XFT)
|
||||
fi
|
||||
CPPFLAGS="${save_header}"
|
||||
LIBS="${save_libs}"
|
||||
AC_SUBST(WITH_XFT)
|
||||
|
||||
#--------------------------------------------------------------------
|
||||
# XIM support
|
||||
#--------------------------------------------------------------------
|
||||
AC_ARG_ENABLE(xim,
|
||||
[ --disable-xim Disable XIM support],,
|
||||
enable_xim=yes)
|
||||
if test "x$enable_xim" = "xyes"; then
|
||||
AC_DEFINE(USE_XIM)
|
||||
fi
|
||||
|
||||
#--------------------------------------------------------------------
|
||||
# Find for JPEG
|
||||
#--------------------------------------------------------------------
|
||||
AC_ARG_WITH(jpeg_library,
|
||||
[ --with-jpeg-library=DIR JPEG library file are in DIR], ,
|
||||
with_jpeg_library=/usr/local/lib)
|
||||
AC_ARG_WITH(jpeg_include,
|
||||
[ --with-jpeg-include=DIR JPEG include files are in DIR], ,
|
||||
with_jpeg_include=/usr/local/include)
|
||||
|
||||
AC_DEFUN(AC_CHECK_JPEGLIB,
|
||||
[jpeg_check_lib_save_header=${CPPFLAGS}
|
||||
CPPFLAGS="-L$1 -I$2 ${CPPFLAGS}"
|
||||
|
||||
AC_CHECK_LIB(jpeg, jpeg_destroy_decompress,
|
||||
jpeg_ok=yes,
|
||||
jpeg_ok=no)
|
||||
if test "$jpeg_ok" = yes; then
|
||||
AC_MSG_CHECKING([for jpeglib.h])
|
||||
AC_TRY_CPP([#include <stdio.h>
|
||||
#undef PACKAGE
|
||||
#undef VERSION
|
||||
#undef HAVE_STDLIB_H
|
||||
#include <jpeglib.h>],
|
||||
jpeg_ok=yes,
|
||||
jpeg_ok=no)
|
||||
AC_MSG_RESULT($jpeg_ok)
|
||||
|
||||
if test "$jpeg_ok" = yes; then
|
||||
GRAPHIC_LFLAGS="-L$1 $GRAPHIC_LFLAGS"
|
||||
GRAPHIC_CFLAGS="-I$1 $GRAPHIC_CFLAGS"
|
||||
fi
|
||||
fi
|
||||
CPPFLAGS="${jpeg_check_lib_save_header}"])
|
||||
|
||||
if test $gs_cv_have_wraster = no -o $set_x_paths = yes; then
|
||||
AC_CHECK_JPEGLIB(${with_jpeg_library}, ${with_jpeg_include})
|
||||
fi
|
||||
|
||||
#--------------------------------------------------------------------
|
||||
# Find for TIFF
|
||||
#--------------------------------------------------------------------
|
||||
AC_ARG_WITH(tiff_library,
|
||||
[ --with-tiff-library=DIR TIFF library file are in DIR], ,
|
||||
with_tiff_library=/usr/local/lib)
|
||||
AC_ARG_WITH(tiff_include,
|
||||
[ --with-tiff-include=DIR TIFF include files are in DIR], ,
|
||||
with_tiff_include=/usr/local/include)
|
||||
|
||||
AC_DEFUN(AC_CHECK_TIFFLIB,
|
||||
[tiff_check_lib_save_header=${CPPFLAGS}
|
||||
tiff_check_lib_save_libs=${LIBS}
|
||||
CPPFLAGS="-L$1 ${JPEG_LIB} -I$2 ${JPEG_INCLUDE} ${CPPFLAGS}"
|
||||
AC_CHECK_LIB(z, main, HAVE_LIBZ=1, HAVE_LIBZ=0)
|
||||
|
||||
AC_MSG_CHECKING(for -ltiff without -ljpeg nor -lz)
|
||||
LIBS="-ltiff -lm $LIBS"
|
||||
AC_TRY_LINK([char TIFFReadScanline();], [TIFFReadScanline()],
|
||||
jpeg_notneeded=yes,
|
||||
jpeg_notneeded=no)
|
||||
AC_MSG_RESULT($jpeg_notneeded)
|
||||
LIBS=${tiff_check_lib_save_libs}
|
||||
JPEG=
|
||||
if test "$jpeg_notneeded" = no; then
|
||||
JPEG=-ljpeg
|
||||
fi
|
||||
|
||||
if test $HAVE_LIBZ = 1; then
|
||||
AC_MSG_CHECKING(for -ltiff without -lz)
|
||||
LIBS="-ltiff $JPEG -lm $LIBS"
|
||||
AC_TRY_LINK([char TIFFReadScanline();], [TIFFReadScanline()],
|
||||
libz_notneeded=yes,
|
||||
libz_notneeded=no)
|
||||
AC_MSG_RESULT($libz_notneeded)
|
||||
LIBS=${tiff_check_lib_save_libs}
|
||||
if test "$libz_notneeded" = no; then
|
||||
JPEG="$JPEG -lz"
|
||||
fi
|
||||
fi
|
||||
|
||||
AC_CHECK_LIB(tiff, TIFFReadScanline,
|
||||
tiff_ok=yes,
|
||||
tiff_ok=no
|
||||
AC_MSG_WARN(Cannot find libtiff)
|
||||
echo "* The GUI library reqiures the TIFF library"
|
||||
echo "* Use --with-tiff-library to specify the tiff library"
|
||||
echo "* directory if it is not in the usual place(s)"
|
||||
echo "* You may also have to specify --with-jpeg-library if the jpeg"
|
||||
echo "* Library is needed by tiff"
|
||||
if test "x$CONFIGURING_CORE_LIBRARIES" != x; then
|
||||
AC_MSG_ERROR(You must have proper libraries installed to compile core)
|
||||
fi,
|
||||
$JPEG -lm)
|
||||
if test "$tiff_ok" = yes; then
|
||||
AC_CHECK_HEADER(tiffio.h,
|
||||
tiff_ok=yes,
|
||||
tiff_ok=no)
|
||||
if test "$tiff_ok" = yes; then
|
||||
GRAPHIC_LFLAGS="-L$1 $GRAPHIC_LFLAGS"
|
||||
GRAPHIC_CFLAGS="-I$1 $GRAPHIC_CFLAGS"
|
||||
GRAPHIC_LIBS="-ltiff $JPEG $GRAPHIC_LIBS"
|
||||
else
|
||||
AC_MSG_WARN(Cannot find libtiff header tiffio)
|
||||
echo "* The GUI library requres the TIFF library"
|
||||
echo "* Use --with-tiff-include to specify the tiff header directory"
|
||||
echo "* if it is not in the usual place(s)"
|
||||
if test "x$CONFIGURING_CORE_LIBRARIES" != x; then
|
||||
AC_MSG_ERROR(You must have proper libraries installed to compile core)
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
CPPFLAGS="${tiff_check_lib_save_header}"])
|
||||
|
||||
if test $gs_cv_have_wraster = no -o $set_x_paths = yes; then
|
||||
AC_CHECK_TIFFLIB(${with_tiff_library}, ${with_tiff_include})
|
||||
fi
|
||||
|
||||
save_CPPFLAGS=${CPPFLAGS}
|
||||
CPPFLAGS="$CPPFLAGS $GRAPHIC_CFLAGS"
|
||||
AC_CHECK_HEADER(X11/extensions/XShm.h, AC_DEFINE(XSHM))
|
||||
CPPFLAGS="$save_CPPFLAGS"
|
||||
|
||||
WITH_WRASTER=no
|
||||
if test $gs_cv_have_wraster = yes -a $set_x_paths = no; then
|
||||
AC_DEFINE(WITH_WRASTER)
|
||||
WITH_WRASTER=yes
|
||||
fi
|
||||
AC_SUBST(WITH_WRASTER)
|
||||
AC_SUBST(GRAPHIC_LIBS)
|
||||
AC_SUBST(GRAPHIC_CFLAGS)
|
||||
AC_SUBST(GRAPHIC_LFLAGS)
|
||||
|
||||
#--------------------------------------------------------------------
|
||||
# Which projects should we build?
|
||||
#--------------------------------------------------------------------
|
||||
exlib=no
|
||||
exdps=no
|
||||
ex11=no
|
||||
ewin32=no
|
||||
ewinlib=no
|
||||
if test $gs_cv_have_wraster = yes -o $x_includes != NONE; then
|
||||
exlib=yes
|
||||
ex11=yes
|
||||
fi
|
||||
|
||||
AC_ARG_ENABLE(xlib,
|
||||
[ --enable-xlib Build xlib graphics context],,
|
||||
enable_xlib=$exlib)
|
||||
AC_ARG_ENABLE(xdps,
|
||||
[ --enable-xdps Build xdps graphics context],,
|
||||
enable_xdps=$exdps)
|
||||
AC_ARG_ENABLE(x11,
|
||||
[ --enable-x11 Build x11 server],,
|
||||
enable_x11=$ex11)
|
||||
AC_ARG_ENABLE(win32,
|
||||
[ --enable-win32 Build win32 server],,
|
||||
enable_xwin32=$exwin32)
|
||||
AC_ARG_ENABLE(winlib,
|
||||
[ --enable-winlib Build win32 graphics context],,
|
||||
enable_xwinlib=$exwinlib)
|
||||
|
||||
AC_MSG_CHECKING(Backend Server)
|
||||
if test "x$enable_win32" = "xyes"; then
|
||||
BUILD_WIN32=yes
|
||||
AC_SUBST(BUILD_WIN32)
|
||||
AC_DEFINE(BUILD_WIN32)
|
||||
AC_MSG_RESULT(win32)
|
||||
# Only one server allowed
|
||||
enable_x11=no
|
||||
fi
|
||||
if test "x$enable_x11" = "xyes"; then
|
||||
BUILD_X11=yes
|
||||
AC_SUBST(BUILD_X11)
|
||||
AC_DEFINE(BUILD_X11)
|
||||
AC_MSG_RESULT(x11)
|
||||
fi
|
||||
|
||||
AC_MSG_CHECKING(Backend Graphics)
|
||||
if test "x$enable_winlib" = "xyes"; then
|
||||
BUILD_WINLIB=yes
|
||||
AC_SUBST(BUILD_WINLIB)
|
||||
AC_DEFINE(BUILD_WINLIB)
|
||||
AC_MSG_RESULT(win32)
|
||||
enable_xdps=no
|
||||
enable_xlib=no
|
||||
fi
|
||||
if test "x$enable_xdps" = "xyes"; then
|
||||
BUILD_XDPS=yes
|
||||
AC_SUBST(BUILD_XDPS)
|
||||
AC_DEFINE(BUILD_XDPS)
|
||||
AC_MSG_RESULT(xdps)
|
||||
GRAPHIC_LIBS="-ldpstk -ldps -lpsres -lXt $X_PRE_LIBS $GRAPHIC_LIBS"
|
||||
enable_xlib=no
|
||||
fi
|
||||
if test "x$enable_xlib" = "xyes"; then
|
||||
BUILD_XLIB=yes
|
||||
AC_SUBST(BUILD_XLIB)
|
||||
AC_DEFINE(BUILD_XLIB)
|
||||
AC_MSG_RESULT(xlib)
|
||||
fi
|
||||
|
||||
AC_OUTPUT(back.make config.make)
|
||||
|
||||
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue