get Font types on computer
This code takes every font from the computer it is run on, and places it into a combo box. (not using printer.fonts but using screen.fonts)
AI
AI Summary: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.
Source Code
''for loop adds all font types in computer to combo box
fType.Clear ''clears combo box
For i = 0 To Screen.FontCount - 1 ''counts # of fonts
fType.AddItem Screen.Fonts(i) ''adds font to combo box
Next i
<style>
.aSnap {
font-family: Lucida Console, monospace;
font-size: 85%;
}
.aList {
font-size: 85%;
border: 1px solid #000000;
}
.lHeader {
font-weight: bold;
border-bottom: 1px solid #000000;
background-color: #cccccc;
}
.lText-1 {
background-color: #eeeeee;
}
.lText-2 {
background-color: #dddddd;
}
.aCode {
background-color: #eeeeee;
border: 1px solid #aaaaaa;
padding: 5px;
font-size: 85%;
margin-left: 50px;
margin-top: 0px;
margin-bottom: 10px;
width: 600px;
line-height: 100%;
font-family: Lucida Console, monospace;
}
.cTitle {
font-style: italic;
font-size: 85%;
margin-left: 75px;
margin-top: 2px;
}
.cPHP { color: #000077; }
.cFunction { color: #dd0000; }
.cVariable { color: #005599; }
.cConstant { color: #666666; }
.cComment { color: #009900; }
.cText { color: #999900; }
.cReserved { color: #000099; }
.cOwnFunction { color: #770000; }
.cOutput {
margin: 0px;
border: 1px solid #000000;
padding: 3px;
background-color: #ddddff;
font-size: 85%;
}
.coTitle {
font-style: italic;
color: #0000ff;
padding-left: 10px;
}
.aBody {
font-family: sans-serif;
font-size: 90%;
}
.aHead1 {
background-color: #ccccff;
border: 1px solid #000000;
font-family: serif;
font-size: 150%;
padding-left: 15px;
margin-top: 15px;
}
.aHead2 {
background-color: #ccccff;
border: 1px solid #000000;
font-size: 110%;
padding-left: 10px;
margin-top: 5px;
}
.aSection {
padding: 3px;
padding-left: 10px;
padding-bottom: 5px;
line-height: 125%;
border-left: 1px solid #cccccc;
margin-bottom: 8px;
}
.aSubSection {
padding: 3px;
padding-left: 10px;
padding-bottom: 5px;
border-left: 1px solid #cccccc;
margin-bottom: 8px;
}
</style>
<div class="aBody">
<hr>
I'm truly sorry to do this, but I have to link (even though it's against the rules) to this article at my own server:<br />
http://birk-jensen.dk/psc/xmlrpc.htm
<br /><br /> The reason for this, is that PSC destroyes my HTML formatting, and my indenting in the code examples. (i've uploaded the article as well)
<hr>
<div class="aHead1">Index</div>
<div class="aSection">
1) Introduction
<div style="padding-left: 10px; padding-bottom: 5px;">
1.1) The boring introduction<br />
1.2) What is XML-RPC?<br />
1.3) Installing XML-RPC to PHP
</div>
2) The server<br />
3) The Client<br />
4) Theory
<div style="padding-left: 10px; padding-bottom: 5px;">
4.1) Request<br />
4.2) Response
</div>
5) Conclusion
<div style="font-size: 75%; margin-top: 5px;">
a. Sources
b. Understanding this article
</div>
</div>
<div class="aHead1">1. Introduction</div>
<div class="aSection">
As the headline below suggests it's a boring introduction, so be warned.
<div class="aHead2">1.1 The boring introduction</div>
<div class="aSubSection">
This has absolutely nothing with XML-RPC to do, but hey I write it anyway and you're to curious to stop reading it now, HA.<br />
Well this is my first article using this new layout (and in the PHP section, got a couple of articles at the VB section with an old layout). But the main thing I write this, is for you to skip the whole article - just the start of it! no no! wait comeback). At the end there is a section called <em>b. Understanding this article</em>, actually I used a couple of minutes writing this so I appreciate you use a couple of seconds reading it. It's just about the article layout, and what's what. No on the other hand it'll just bore you and scare you away, never mind forget what I said, just read on.
</div>
So you've decided to learn XML-RPC<sup>[1]</sup>, or did the name just sound "freaky" and raised a little interest? If it did I suggest you read on, if you already know what XML-RPC is, then just skip the next chapter:
<div class="aHead2">1.2 What is XML-RPC?</div>
<div class="aSubSection">
you'ree one of those people huh! Well I'll just run it through quickly and simple, so you can get on with the coding.<br />
XML-RPC is a way to make web services, it packs the requests and responses in XML both the client and the server can understand.<br />
<em>Oh what, what now, you don't know what a web service is either?</em><br />
Okay, well a web service is a function of some sort placed on the net (it could be a function to convert a string into all upper case letters, which we are going to make in the examples below). The smart thing is that, a web service can be programmed in any kind of language, and any other language can you it. Many big sites have a web service, for example Amazon has a web service that allows you to search books and information. Google has one as well!.<br />
Another smart thing about XML-RPC (and to my knowledge all other web services), is that they can be run from a web server. Not only is this smart, because like many other things in programming you don't need to install some high-end fancy server. But you don't have to worry about firewalls and other kinds of protection (okay sometimes you run into a psychotic network administrator, who blocks everything but his own <sup>illegal</sup> Russian p*rn download, but hey what's the chance right?!).
</div>
<div class="aHead2">1.3 Installing XML-RPC to PHP</div>
<div class="aSubSection">
If you've installed an extension before, this should be no problem at all, just install the XML-RPC extension. But if this is your first time, I guess I'll have to do my best guiding you through it:<br />
Windows users: http://www.php.net/manual/en/install.windows.extensions.php<br />
Unix users: http://www.php.net/manual/en/install.unix.php<br />
OS X users: http://www.php.net/manual/en/install.macosx.php<br />
For you guys(and gals) who compile PHP, just compile it with: <em>--with-xmlrpc</em>.<br /><br />
What? you didn't realy think I was going to explain this to you?
</div>
Anyway, in this article I'll try to guide you through how you make a web service (the server) and how you call a web service (the client).
</div>
<div class="aHead1">2. The Server</div>
<div class="aSection">
For obviusly reasons we start making the server (<em>Comon, we need the server first, so the client have something to connect to, geesh</em>), which contains the function our client will be calling later on.<br />
I've decided to comment the code, this way I don't have to explain it to you after you've read it. And you can by copying the code later on remember what it all does (if you catch my drift, because I lost the meaning of the last sentence my self):
<div class="cTitle">xml_server.php</div>
<pre class="aCode"><span class="cPHP"><?php</span>
<span class="cComment">/*****
* We start witht the functions we wan't to be web services.
* Each of them must have 3 arguments:
* 1<sup>st</sup>: This is the method name, which the client requests.
* 2<sup>nd</sup>: This one is the arguments, which the client sends with the request.
* 3<sup>rd</sup>: This data is specified by the server it self.
*****/</span>
<span class="cReserved">function</span> <span class="cOwnFunction">xmlEcho</span>(<span class="cVariable">$method</span>, <span class="cVariable">$args</span>, <span class="cVariable">$appData</span>)
{
<span class="cReserved">return</span> <span class="cText">'Come again: '</span>. <span class="cVariable">$args</span>[0];
}
<span class="cComment">// Just for the fun of it, let's make 2 function:</span>
<span class="cReserved">function</span> <span class="cOwnFunction">xmlAllToUpper</span>(<span class="cVariable">$method</span>, <span class="cVariable">$args</span>, <span class="cVariable">$appData</span>)
{
<span class="cReserved">for</span> (<span class="cVariable">$i</span> = 0; <span class="cVariable">$i</span> < <span class="cFunction">count</span>(<span class="cVariable">$args</span>); <span class="cVariable">$i</span>++) {
<span class="cVariable">$args</span>[<span class="cVariable">$i</span>] = <span class="cFunction">strToUpper</span>(<span class="cVariable">$args</span>[<span class="cVariable">$i</span>]);
}
<span class="cReserved">return</span> <span class="cVariable">$args</span>;
}
<span class="cComment">/*****
* Next up we'll assign the XML-RPC server handle to a variable.
* I've chosen this "sneaky" name: $xmlServer * But you can think of this
* as any other handle, for example, when you're working with a database,
* you have the connection handle, it's the same thing.
*****/</span>
<span class="cVariable">$xmlServer</span> = <span class="cFunction">xmlrpc_server_create</span>();
<span class="cComment">/*****
* Now that's done it's time to tell the server which functions the
* client can request. This is done with the xmlrpc_server_register_method
* function (why can't they come up with some short names!). This function
* requires 3 arguments:
* 1<sup>st</sup>: The server handle, we just specified above.
* 2<sup>nd</sup>: The function name, which the client calls.
* 3<sup>rd</sup>: The function name, to run.
*
* This means that your function dosn't have to be named the same as the
* function the client calls.
*****/</span>
<span class="cFunction">xmlrpc_server_register_method</span>(<span class="cVariable">$server</span>, <span class="cText">'echo'</span>, <span class="cText">'xmlEcho'</span>);
<span class="cFunction">xmlrpc_server_register_method</span>(<span class="cVariable">$server</span>, <span class="cText">'goLarge'</span>, <span class="cText">'xmlAllToUpper'</span>);
<span class="cComment">/*****
* We need to get what ever request the client send us.
* This is done with the $HTTP_RAW_POST_DATA variable. Nothing more
* to say about that, so I'll just give you yet another dumb ass
* comment ... That was it.
*****/</span>
<span class="cVariable">$xmlRequest</span> = <span class="cVariable">$HTTP_RAW_POST_DATA</span>;
<span class="cComment">/*****
* We have all we need now, for the server to call the function, the
* client requested.
* To call this function, we use this (again rediculesly long) function:
* xmlrpc_server_call_method, which as always take 3 arguments:
* 1<sup>st</sup>: The server handle.
* 2<sup>nd</sup>: The client request we just got above.
* 3<sup>rd</sup>: What ever data you (as the server) want to send, this
* will be passed into the $appData variable.
*****/</span>
<span class="cVariable">$xmlResponse</span> = xmlrpc_server_call_method(<span class="cVariable">$xmlServer</span>, <span class="cVariable">$xmlRequest</span>, <span class="cConstant">NULL</span>);
<span class="cComment">// Prepare the header contents so it sends XML</span>
<span class="cFunction">header</span>(<span class="cText">'Content-Type: text/xml'</span>);
<span class="cFunction">echo</span> <span class="cVariable">$xmlResponse</span>;
<span class="cFunction">xmlrpc_server_destroy</span>(<span class="cVariable">$xmlServer</span>);
<span style="color: #000077;" class="cPHP">?></span></pre>
All done with the server part. If you haven't figured out exactly how the server works yet, then let me give you a little insight. In short terms, it's just a php file, that is called by the client, through a normal URL. It then processes the contents which the client send, and return a result.
</div>
<div class="aHead1">3. The Client</div>
<div class="aSection">
Well you made it so far, so why not make the client to test your server as well. Even though we made the server first, I must admit you'll probably be using the client a "wee" bit more. Of course it's fun to mess around with the server, but how often do you make anything others want to us right?<br /> anyway, as you might notice, the client code contains a little socket<sup>[2]</sup> programming. If you've never worked with sockets before, don't be to glad running around screaming like a teenage girl at a (oh what the duce, do they hear now a days) Beatles concert, thinking you're going to learn anything here ... because you're not. I've decided not to go into depth with any of the socket commands, just assume you people already know them.
<div class="cTitle">xml_client.php</div>
<pre class="aCode"><span style="color: #000077;" class="cPHP"><?php</span>
<span class="cComment">/*****
* First off we'll be making a function, to send our request to the
* server.
* This is where the feared socket programming makes it appearence,
* take a notice at the default value for port, some people have
* (for reasons only god may know).
*****/</span>
<span class="cReserved">function</span> <span class="cOwnFunction">sendRequest</span>(<span class="cVariable">$host</span>, <span class="cVariable">$url</span>, <span class="cVariable">$request</span>, <span class="cVariable">$port</span> = 80)
{
<span class="cComment">// First off we open a connection to the server.</span>
<span class="cReserved">if</span> ( !<span class="cVariable">$sock</span> = <span class="cFunction">fsockopen</span>(<span class="cVariable">$host</span>, <span class="cVariable">$port</span>, <span class="cVariable">$errNo</span>, <span class="cVariable">$errString</span>) ) {
<span class="cFunction">echo</span> <span class="cText">'Error: '</span>. <span class="cVariable">$errNo</span> . <span class="cText">' - '</span>. <span class="cVariable">$errString</span>;
<span class="cFunction">return</span> <span class="cConstant">FALSE</span>;
}
<span class="cComment">/*****
* We prepare the HTTP header, in our request.
* Notice we set the Content-Type to text/xml (just notice...).
*****/</span>
<span class="cVariable">$httpQuery</span> = <span class="cText">"POST "</span>. <span class="cVariable">$url</span> .<span class="cText">" HTTP/1.0\n"</span>;
<span class="cVariable">$httpQuery</span> .= <span class="cText">"User-Agent: xmlrpc\n"</span>;
<span class="cVariable">$httpQuery</span> .= <span class="cText">"Host: "</span>. <span class="cVariable">$host</span> .<span class="cText">"\n"</span>;
<span class="cVariable">$httpQuery</span> .= <span class="cText">"Content-Type: text/xml\n"</span>;
<span class="cVariable">$httpQuery</span> .= <span class="cText">"Content-Length: "</span>. <span class="cFunction">strlen</span>(<span class="cVariable">$request</span>) .<span class="cText">"\n\n"</span>;
<span class="cVariable">$httpQuery</span> .= <span class="cVariable">$request</span> .<span class="cText">"\n"</span>;
<span class="cComment">// Here we send the request to the server</span>
<span class="cReserved">if</span> ( !<span class="cFunction">fwrite</span>(<span class="cVariable">$sock</span>, <span class="cVariable">$httpQuery</span>, <span class="cFunction">strlen</span>(<span class="cVariable">$httpQuery</span>)) ) {
<span class="cFunction">echo</span> <span class="cText">'Error while trying to send request'</span>;
<span class="cFunction">return</span> <span class="cConstant">FALSE</span>;
}
<span class="cComment">// We get the response from the server</span>
<span class="cReserved">while</span> ( !<span class="cFunction">feof</span>(<span class="cVariable">$sock</span>) ) {
<span class="cVariable">$xmlResponse</span> .= <span class="cFunction">fgets</span>(<span class="cVariable">$sock</span>);
}
<span class="cComment">// Closing the connection</span>
<span class="cFunction">fclose</span>(<span class="cVariable">$sock</span>);
<span class="cComment">// We strip the response from it's HTTP header</span>
<span class="cVariable">$xmlResponse</span> = <span class="cFunction">substr</span>(<span class="cVariable">$xmlResponse</span>, <span class="cFunction">strpos</span>(<span class="cVariable">$xmlResponse</span>, <span class="cText">"\r\n\r\n"</span>) +4);
<span class="cComment">/*****
* To decode the XML into PHP, we use the (finaly a short function)
* xmlrpc_decode function. And that should've done the trick.
* We now have what ever the server function made in our $xmlRespnse
* variable.
*****/</span>
<span class="cVariable">$xmlResponse</span> = <span class="cFunction">xmlrpc_decode</span>(<span class="cVariable">$xmlResponse</span>);
<span class="cComment">// Returns the result.</span>
<span class="cFunction">return</span> <span class="cVariable">$response</span>;
}
<span class="cComment">/*****
* The first thing we do, is encoding our request into an XML-RPC
* string. This is done with the xmlrpc_encode_request function, which
* accepts 2 arguments:
* 1<sup>st</sup>: Name of the function we wish to call from the server.
* 2<sup>nd</sup>: The argument we want to parse into this function. If we
* wish to parse more than 1 argument, we put them into an array.
*****/</span>
<span class="cVariable">$xmlRequest</span> = <span class="cVariable">xmlrpc_encode_request</span>(<span class="cText">'echo'</span>, <span class="cText">'All hail Philip the almighty... Obey!'</span>);
<span class="cComment">/*****
* Now we call the sendRequest function, with our XML request. Remember
* to change the host if you're not on a local computer or what ever you use.
* And remember to change the path, if you've not saved the server directly in
* the root (which I suspect you havent). If you hav it in the "articles/php"
* subdirectory, you use "/articles/php/xml_server.php"
*****/</span>
<span class="cVariable">$xmlResponse</span> = <span class="cOwnFunction">sendRequest</span>(<span class="cText">'127.0.0.1'</span>, <span class="cText">'/xmlrpc_server.php'</span>, <span class="cVariable">$xmlRequest</span>);
<span class="cComment">// And at last, we print out the response!</span>
<span class="cFunction">var_dump</span>(<span class="cVariable">$xmlResponse</span>);
<span class="cPHP">?></span>
<div class="cOutput"><span class="coTitle">Output:</span>
string(49) "Come again: All hail Philip the almighty... Obey!"</div></pre>
Hey, now wasn't that funny! Ya I bet it was ... Anyway let's take one last example just to try out all of our functions. This time we parse more than one argument with the request, so you get the idea:
<div class="cTitle">EXAMPLE:</div>
<pre class="aCode"><span class="cPHP"><?php</span>
<span class="cVariable">$xmlRequest</span> = <span class="cVariable">xmlrpc_encode_request</span>(<span class="cText">'goLarge'</span>, <span class="cFunction">array</span>(1234, <span class="cText">'little'</span>, <span class="cText">'1 small step'</span>)</span>);
<span class="cVariable">$xmlResponse</span> = <span class="cOwnFunction">sendRequest</span>(<span class="cText">'127.0.0.1'</span>, <span class="cText">'/xmlrpc_server.php'</span>, <span class="cVariable">$xmlRequest</span>);
<span class="cFunction">var_dump</span>(<span class="cVariable">$xmlResponse</span>);
<span class="cPHP">?></span>
<div class="cOutput"><span class="coTitle">Output:</span>
array(3) {
[0]=>
string(4) "1234"
[1]=>
string(6) "LITTLE"
[2]=>
string(12) "1 SMALL STEP"
}</div></pre>
Well I don't realy know how to explain this any better, so I guess all the practical stuff ends here.
</div>
<div class="aHead1">4. Theory</div>
<div class="aSection">
I've chosen to place this section at the end of the article. This is because you don't actually need to know this to use XML-RPC, so if you're fine with just using it, or if you don't plan on using XML-RPC in the future just stop reading now. And let me just tell you, that I quickly go through this, if you want more detailed information try the XML-RPC Specification<sup>[3]</sup>, that explains a bit more.
<div class="aHead2">4.1 Request</div>
<div class="aSubSection">
I'll start by pasting in our own request to the server (the echo request we made in the example above), but notice it's without the HTTP header we send with:
<pre class="aCode"><?xml version="1.0" encoding="iso-8859-1"?>
<methodCall>
<methodName>echo</methodName>
<params>
<param>
<value>
<string>All hail Philip the almighty... Obey!</string>
</value>
</param>
</params>
</methodCall></pre>
If you've worked a little with XML before, you get it right away. If you haven't, then look at it just a little bit, and try to see if you can figure it out, it's not that hard you know ... <em>ahh! yes not that hard right!</em>. And for the rest of you, I'll run it through.<br />
The <span class="aSnap"><?xml version="1.0" encoding="iso-8859-1"?></span> line just tells us, that this is an XML document.<br />
Try to think of it like a normal file tree. The next line is <span class="aSnap"><methodCall></span>, which begins a node, this node ends at the last line <span class="aSnap"></methodCall></span>. Next up <span class="aSnap"><methodName>Echo</methodName></span> is the name of the function we where calling, and as you see it's the <em>echo</em> function being called. Then we have the arguments comming (here they call them parameters, don't ask me about the difference I do not know!), <span class="aSnap"><params></span> followed by yet another <span class="aSnap"><param></span>, note that any <span class="aSnap"><params></span> can hold as many <span class="aSnap"><param></span> they wan't. When we call our <span class="aSnap">goLarge</span> function the array is split up into 3 <span class="aSnap"><param></span>. Finaly we have our argument in the <span class="aSnap"><value></span> node. Our argument is in yet another node, this defining what type it is, this time our type is a string so <span class="aSnap"><string>All hail Philip the almighty... Obey!</string></span> is used. The XML-RPC support 5 different types, the below table is stolen from the XML-RPC Specs:
<table cellspacing="0" cellpadding="1" border="0" class="aList" align="center">
<tr>
<td class="lHeader" width="150">Tag</td>
<td class="lHeader" width="290">Type</td>
<td class="lHeader">Example</td>
</tr>
<tr class="lText-1">
<td><i4> or <int></td>
<td>four-byte signed integer</td>
<td>-12</td>
</tr>
<tr class="lText-2">
<td><boolean></td>
<td>0(false) or 1(true)</td>
<td>1</td>
</tr>
<tr class="lText-1">
<td><string></td>
<td>string</td>
<td>hello world</td>
</tr>
<tr class="lText-2">
<td><double></td>
<td>double-precision signed floating point number</td>
<td>-12.214</td>
</tr>
<tr class="lText-1">
<td><dateTime.iso8601></td>
<td>date/time</td>
<td>19980717T14:08:55</td>
</tr>
<tr class="lText-2">
<td><base64></td>
<td>base64-encoded binary</td>
<td>eW91IGNhbid0IHJlYWQgdGhpcyE=</td>
</tr>
</table>
As i said above, I wouldn't go through it all, but XML-RPC also supports arrays and structures, but you have to read about them in the XML-RPC Specs.
</div>
<div class="aHead2">4.2 Response</div>
<div class="aSubSection">
Again I've stripped the HTML header from the server response:
<pre class="aCode"><?xml version="1.0" encoding="iso-8859-1"?>
<methodResponse>
<params>
<param>
<value>
<string>Come again: All hail Philip the almighty... Obey!</string>
</value>
</param>
</params>
</methodResponse></pre>
To be honest, I can't realy figure of anything to say here abuot this one. I mean, nothing's changed there's nothing new.<br />
Now sometimes an error happens, you maybe suply to many arguments, or you might misspell a function so the server can't find it. When this happen the server will return a fault code. I've (besides stolen the idea of showing this fault code here from the XML-RPC Specs) chosen to give you an example on a fault code:
<pre class="aCode"><?xml version="1.0" encoding="iso-8859-1"?>
<methodResponse>
<fault>
<value>
<struct>
<member>
<name>faultString</name>
<value>
<string>server error. method not found.
echos</string>
</value>
</member>
<member>
<name>faultCode</name>
<value>
<int>-32601</int>
</value>
</member>
</struct>
</value>
</fault>
</methodResponse></pre>
Again, it's not that difficult to figure out how this all works. But if you want more information about the <span class="aSnap"><struct></span> you'll need to consult the XML-RPC Specs.
</div>
</div>
<div class="aHead1">5. Conclusion</div>
<div class="aSection">
Finaly!<br />
To be honest I don't really know what to make of all this, except that it works like a charm. If you compare the XML-RPC protocol to some of the other web service protocols you can find "out there", you'll find that the difference is small. Some are a little bit more advanced, some are more compact, others are exactly the same and some are useless.<br />
Finding the right web service, is all about what you like to work with, my personal favorit is XML-RPC (hence this article). So my suggestion is try some of the other big web services, and find the one you're most comfortable with, and then stick with it!
</div>
<div class="aHead1">a. Sources</div>
<div class="aSection">
[1] http://www.xmlrpc.com/<br />
[2] http://dk.php.net/manual/en/function.fsockopen.php<br />
[3] http://www.xmlrpc.com/spec
</div>
<div class="aHead1">b. Understanding this article</div>
<div class="aSection">Well the only purpose of this section, is to clearify a little something about this article. And it will just be done in no particular order:<br /><br />
- I've colored the codes my self, so if there are some color errors, please just leave some feedback, and I'll fix it. If yuo have any complaints about the colors I've used for the different syntax, then I don't want to hear about it, copy the code into your own favorit PHP editor.<br />
- If you find anything offending, then again don't say a word or I'll get you, and I'll get you good :p<br />
- Well that was about it, understanding this article. Now remember please leave some feadback (and if you want to vote away), nothing says "sweeeeet" like good feedback.
</div>
<em>- Philip Birk-Jensen, Januar 2005</em>
</div>
Original Comments (3)
Recovered from Wayback Machine