[prev in list] [next in list] [prev in thread] [next in thread] 

List:       fop-user
Subject:    Getting a list of font names without the memory hit...
From:       Bernard Giannetti <thebernmeister () hotmail ! com>
Date:       2013-07-30 10:23:04
Message-ID: BLU175-W4AF524A199C83B898CACBDC560 () phx ! gbl
[Download RAW message or body]

Hi,
I'm making a call to org.apache.fop.tools.fontlist.FontListGenerator.listFonts( ... ) \
to get a list of font names for my desktop application.  To get the font names, I \
take the keys from the returned fontFamilies SortedMap; the actual data is junked. I \
hadn't realised just how much memory is used by listfont( ... ) - on some platforms \
such as Windows 7, in excess of 250 MB.  In this case I'm hitting out of memory \
errors. I was wondering if there's a simpler way (uses less memory) to get just the \
font names (first family names)?  As I said, I don't make use of the metrics and \
other font details...just the first family name for each font.  Digging down into  \
listfont( ... ), I was wondering if it's safe to take the firstFamilyName and place \
it into a list say and then drop the following lines for the containers/sort? \
Iterator iter = fontInfo.getFontTriplets().entrySet().iterator();while \
(iter.hasNext()) {    Map.Entry entry = (Map.Entry)iter.next();    FontTriplet \
triplet = (FontTriplet)entry.getKey();    String key = (String)entry.getValue();    \
FontSpec container;    if (keyBag.contains(key)) {        keyBag.remove(key);  \
FontMetrics metrics = (FontMetrics)fonts.get(key);  container = new FontSpec(key, \
metrics);        container.addFamilyNames(metrics.getFamilyNames());        \
keys.put(key, container);        String firstFamilyName = \
(String)container.getFamilyNames().first();        List containers = \
(List)fontFamilies.get(firstFamilyName);        if (containers == null) {            \
containers = new java.util.ArrayList();            fontFamilies.put(firstFamilyName, \
containers);        }        containers.add(container);        \
Collections.sort(containers);    } else {        container = (FontSpec)keys.get(key); \
}    container.addTriplet(triplet);} I'm guessing a lot of memory is chewed up in the \
containers/sort section...but really I can't be sure as I don't fully follow what's \
going on! Ideally I'd just up the amount of memory supplied to the desktop \
application, but I don't have that option and besides, it just delays the problem of \
running out of memory.

Thanks in advance,Bernard. 		 	   		  


[Attachment #3 (text/html)]

<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 12pt;
font-family:Calibri
}
--></style></head>
<body class='hmmessage'><div dir='ltr'><font face="Arial" \
size="2">Hi,</font><div><font face="Arial" size="2"><br></font></div><div><font \
size="2"><font face="Arial">I'm making a call to&nbsp;</font><font face="Courier \
New">org.apache.fop.tools.fontlist.FontListGenerator.listFonts( ... )</font><span \
style="font-family: Arial;"> to get a list of font names for my desktop application. \
&nbsp;</span><span style="font-family: Arial;">To get the font names, I take the keys \
from the returned </span><font face="Courier New">fontFamilies SortedMap</font><font \
face="Arial">; the actual data is junked.</font></font></div><div><span \
style="font-family: Arial;"><font size="2"><br></font></span></div><div><font \
size="2"><span style="font-family: Arial;">I hadn't realised just how much memory is \
used by&nbsp;</span><span style="font-family: 'Courier New';">listfont( ... \
)</span><span style="font-family: Arial;">&nbsp;- on some platforms such as Windows \
7, in excess of 250 MB. &nbsp;In this case I'm hitting out of memory \
errors.</span></font></div><div><font size="2"><span style="font-family: \
Arial;"><br></span></font></div><div><font size="2"><span style="font-family: \
Arial;">I was wondering if there's a simpler way (uses less memory) to get just the \
font names (first family names)? &nbsp;As I said, I don't make use of the metrics and \
other font details...just the first family name for each font. \
&nbsp;</span></font><font size="2">Digging down into&nbsp;<span style="font-family: \
Arial;">&nbsp;</span><span style="font-family: 'Courier New';">listfont( ... \
),&nbsp;</span>I was wondering if it's safe to take the&nbsp;</font><span \
style="font-family: 'Courier New'; font-size: 10pt;">firstFamilyName</span><span \
style="font-size: 10pt;">&nbsp;and place it into a list say and then drop the \
following lines for the&nbsp;</span><span style="font-family: 'Courier New'; \
font-size: 10pt;">containers/sort</span><span style="font-size: \
10pt;">?</span></div><div><font size="2"><br></font></div><div><div><font \
face="Courier New" size="2">Iterator iter = \
fontInfo.getFontTriplets().entrySet().iterator();</font></div><div><font \
face="Courier New" size="2">while (iter.hasNext()) {</font></div><div><font \
size="2"><span style="font-family: 'Courier New';">&nbsp; &nbsp;</span><span \
style="font-family: 'Courier New';">&nbsp;</span><font face="Courier New">Map.Entry \
entry = (Map.Entry)iter.next();</font></font></div><div><font size="2"><span \
style="font-family: 'Courier New';">&nbsp; &nbsp;</span><span style="font-family: \
'Courier New';">&nbsp;</span><font face="Courier New">FontTriplet triplet = \
(FontTriplet)entry.getKey();</font></font></div><div><font size="2"><span \
style="font-family: 'Courier New';">&nbsp; &nbsp;</span><span style="font-family: \
'Courier New';">&nbsp;</span><font face="Courier New">String key = \
(String)entry.getValue();</font></font></div><div><font size="2"><span \
style="font-family: 'Courier New';">&nbsp; &nbsp;</span><span style="font-family: \
'Courier New';">&nbsp;</span><font face="Courier New">FontSpec \
container;</font></font></div><div><font size="2"><span style="font-family: 'Courier \
New';">&nbsp; &nbsp;</span><span style="font-family: 'Courier \
New';">&nbsp;</span><font face="Courier New">if (keyBag.contains(key)) \
{</font></font></div><div><font size="2"><span style="font-family: 'Courier \
New';">&nbsp; &nbsp;</span><span style="font-family: 'Courier \
New';">&nbsp;</span><font face="Courier New">&nbsp; &nbsp; \
keyBag.remove(key);</font></font></div><div><font face="Courier New" \
size="2"><br></font></div><div><font size="2"><span style="font-family: 'Courier \
New';">&nbsp; &nbsp;</span><span style="font-family: 'Courier \
New';">&nbsp;</span><font face="Courier New">&nbsp; &nbsp; FontMetrics metrics = \
(FontMetrics)fonts.get(key);</font></font></div><div><font face="Courier New" \
size="2"><br></font></div><div><font size="2"><span style="font-family: 'Courier \
New';">&nbsp; &nbsp;</span><span style="font-family: 'Courier \
New';">&nbsp;</span><span style="font-family: 'Courier New';">&nbsp; \
&nbsp;</span><span style="font-family: 'Courier New';">&nbsp;</span><font \
face="Courier New">container = new FontSpec(key, \
metrics);</font></font></div><div><font size="2"><span style="font-family: 'Courier \
New';">&nbsp; &nbsp;</span><span style="font-family: 'Courier \
New';">&nbsp;</span><span style="font-family: 'Courier New';">&nbsp; \
&nbsp;</span><span style="font-family: 'Courier New';">&nbsp;</span><font \
face="Courier New">container.addFamilyNames(metrics.getFamilyNames());</font></font></div><div><font \
size="2"><span style="font-family: 'Courier New';">&nbsp; &nbsp;</span><span \
style="font-family: 'Courier New';">&nbsp;</span><span style="font-family: 'Courier \
New';">&nbsp; &nbsp;</span><span style="font-family: 'Courier \
New';">&nbsp;</span><font face="Courier New">keys.put(key, \
container);</font></font></div><div><font size="2"><span style="font-family: 'Courier \
New';">&nbsp; &nbsp;</span><span style="font-family: 'Courier \
New';">&nbsp;</span><span style="font-family: 'Courier New';">&nbsp; \
&nbsp;</span><span style="font-family: 'Courier New';">&nbsp;</span><font \
face="Courier New">String firstFamilyName = \
(String)container.getFamilyNames().first();</font></font></div><div><font \
size="2"><span style="font-family: 'Courier New';">&nbsp; &nbsp;</span><span \
style="font-family: 'Courier New';">&nbsp;</span><span style="font-family: 'Courier \
New';">&nbsp; &nbsp;</span><span style="font-family: 'Courier \
New';">&nbsp;</span><font face="Courier New">List containers = \
(List)fontFamilies.get(firstFamilyName);</font></font></div><div><font size="2"><span \
style="font-family: 'Courier New';">&nbsp; &nbsp;</span><span style="font-family: \
'Courier New';">&nbsp;</span><span style="font-family: 'Courier New';">&nbsp; \
&nbsp;</span><span style="font-family: 'Courier New';">&nbsp;</span><font \
face="Courier New">if (containers == null) {</font></font></div><div><font \
size="2"><span style="font-family: 'Courier New';">&nbsp; &nbsp;</span><span \
style="font-family: 'Courier New';">&nbsp;</span><span style="font-family: 'Courier \
New';">&nbsp; &nbsp;</span><span style="font-family: 'Courier \
New';">&nbsp;</span><span style="font-family: 'Courier New';">&nbsp; \
&nbsp;</span><span style="font-family: 'Courier New';">&nbsp;</span><span \
style="font-family: 'Courier New';">containers = new \
java.util.ArrayList();</span></font></div><div><font size="2"><span \
style="font-family: 'Courier New';">&nbsp; &nbsp;</span><span style="font-family: \
'Courier New';">&nbsp;</span><span style="font-family: 'Courier New';">&nbsp; \
&nbsp;</span><span style="font-family: 'Courier New';">&nbsp;</span><span \
style="font-family: 'Courier New';">&nbsp; &nbsp;</span><span style="font-family: \
'Courier New';">&nbsp;</span><span style="font-family: 'Courier \
New';">fontFamilies.put(firstFamilyName, containers);</span></font></div><div><font \
size="2"><span style="font-family: 'Courier New';">&nbsp; &nbsp;</span><span \
style="font-family: 'Courier New';">&nbsp;</span><span style="font-family: 'Courier \
New';">&nbsp; &nbsp;</span><span style="font-family: 'Courier \
New';">&nbsp;</span><font face="Courier New">}</font></font></div><div><font \
size="2"><span style="font-family: 'Courier New';">&nbsp; &nbsp;</span><span \
style="font-family: 'Courier New';">&nbsp;</span><span style="font-family: 'Courier \
New';">&nbsp; &nbsp;</span><span style="font-family: 'Courier \
New';">&nbsp;</span><font face="Courier \
New">containers.add(container);</font></font></div><div><font size="2"><span \
style="font-family: 'Courier New';">&nbsp; &nbsp;</span><span style="font-family: \
'Courier New';">&nbsp;</span><span style="font-family: 'Courier New';">&nbsp; \
&nbsp;</span><span style="font-family: 'Courier New';">&nbsp;</span><font \
face="Courier New">Collections.sort(containers);</font></font></div><div><font \
size="2"><span style="font-family: 'Courier New';">&nbsp; &nbsp;</span><span \
style="font-family: 'Courier New';">&nbsp;</span><span style="font-family: 'Courier \
New';">} else {</span></font></div><div><font size="2"><span style="font-family: \
'Courier New';">&nbsp; &nbsp;</span><span style="font-family: 'Courier \
New';">&nbsp;</span><span style="font-family: 'Courier New';">&nbsp; \
&nbsp;</span><span style="font-family: 'Courier New';">&nbsp;</span><font \
face="Courier New">container = (FontSpec)keys.get(key);</font></font></div><div><font \
size="2"><span style="font-family: 'Courier New';">&nbsp; &nbsp;</span><span \
style="font-family: 'Courier New';">&nbsp;</span><font face="Courier \
New">}</font></font></div><div><font size="2"><span style="font-family: 'Courier \
New';">&nbsp; &nbsp;</span><span style="font-family: 'Courier \
New';">&nbsp;</span><font face="Courier \
New">container.addTriplet(triplet);</font></font></div><div><font face="Courier New" \
size="2">}</font></div></div><div><font size="2"><br></font></div><div><font \
size="2">I'm guessing a lot of memory is chewed up in the containers/sort \
section...but really I can't be sure as I don't fully follow what's going \
on!</font></div><div><font size="2"><br></font></div><div><font size="2">Ideally I'd \
just up the amount of memory supplied to the desktop application, but I don't have \
that option and besides, it just delays the problem of running out of \
memory.</font></div><div><font size="2"><br></font></div><div><br></div><div><div \
style="line-height:21px;"><div><font face="Arial" size="2" \
style="line-height:normal;">Thanks in advance,</font></div><div><font face="Arial" \
size="2" style="line-height:normal;"><br \
style="line-height:18px;"></font></div><div><font face="Arial" size="2" \
                style="line-height: normal;">Bernard.</font></div></div><style><!--
.ExternalClass .ecxshape {
}
--></style><style><!--
.ExternalClass p.ecxMsoNormal, .ExternalClass li.ecxMsoNormal, .ExternalClass \
div.ecxMsoNormal { font-size:12.0pt;
font-family:"Times New Roman","serif";
color:black;
}

.ExternalClass a:link, .ExternalClass span.ecxMsoHyperlink {
color:blue;
text-decoration:underline;
}

.ExternalClass span.ecxMsoHyperlinkFollowed {
color:purple;
text-decoration:underline;
}

.ExternalClass p {
font-size:12.0pt;
font-family:"Times New Roman","serif";
color:black;
}

.ExternalClass p.ecxMsoAcetate, .ExternalClass li.ecxMsoAcetate, .ExternalClass \
div.ecxMsoAcetate { font-size:8.0pt;
font-family:"Tahoma","sans-serif";
color:black;
}

.ExternalClass span.ecxTextedebullesCar {
font-family:"Tahoma","sans-serif";
}

.ExternalClass p.ecxmsonormal, .ExternalClass li.ecxmsonormal, .ExternalClass \
div.ecxmsonormal { font-size:12.0pt;
font-family:"Times New Roman","serif";
color:black;
}

.ExternalClass p.ecxmsoacetate, .ExternalClass li.ecxmsoacetate, .ExternalClass \
div.ecxmsoacetate { font-size:12.0pt;
font-family:"Times New Roman","serif";
color:black;
}

.ExternalClass p.ecxmsolistparagraph, .ExternalClass li.ecxmsolistparagraph, \
.ExternalClass div.ecxmsolistparagraph { font-size:12.0pt;
font-family:"Times New Roman","serif";
color:black;
}

.ExternalClass p.ecxmsochpdefault, .ExternalClass li.ecxmsochpdefault, .ExternalClass \
div.ecxmsochpdefault { font-size:12.0pt;
font-family:"Times New Roman","serif";
color:black;
}

.ExternalClass p.ecxmsonormal1, .ExternalClass li.ecxmsonormal1, .ExternalClass \
div.ecxmsonormal1 { font-size:12.0pt;
font-family:"Times New Roman","serif";
color:black;
}

.ExternalClass p.ecxmsoacetate1, .ExternalClass li.ecxmsoacetate1, .ExternalClass \
div.ecxmsoacetate1 { font-size:12.0pt;
font-family:"Times New Roman","serif";
color:black;
}

.ExternalClass p.ecxmsochpdefault1, .ExternalClass li.ecxmsochpdefault1, \
.ExternalClass div.ecxmsochpdefault1 { font-size:12.0pt;
font-family:"Times New Roman","serif";
color:black;
}

.ExternalClass p.ecxmsonormal2, .ExternalClass li.ecxmsonormal2, .ExternalClass \
div.ecxmsonormal2 { font-size:12.0pt;
font-family:"Times New Roman","serif";
color:black;
}

.ExternalClass p.ecxmsoacetate2, .ExternalClass li.ecxmsoacetate2, .ExternalClass \
div.ecxmsoacetate2 { font-size:12.0pt;
font-family:"Times New Roman","serif";
color:black;
}

.ExternalClass p.ecxmsolistparagraph1, .ExternalClass li.ecxmsolistparagraph1, \
.ExternalClass div.ecxmsolistparagraph1 { font-size:12.0pt;
font-family:"Times New Roman","serif";
color:black;
}

.ExternalClass p.ecxmsochpdefault2, .ExternalClass li.ecxmsochpdefault2, \
.ExternalClass div.ecxmsochpdefault2 { font-size:12.0pt;
font-family:"Times New Roman","serif";
color:black;
}

.ExternalClass p.ecxmsonormal11, .ExternalClass li.ecxmsonormal11, .ExternalClass \
div.ecxmsonormal11 { font-size:11.0pt;
font-family:"Calibri","sans-serif";
color:black;
}

.ExternalClass p.ecxmsoacetate11, .ExternalClass li.ecxmsoacetate11, .ExternalClass \
div.ecxmsoacetate11 { font-size:8.0pt;
font-family:"Tahoma","sans-serif";
color:black;
}

.ExternalClass p.ecxmsochpdefault11, .ExternalClass li.ecxmsochpdefault11, \
.ExternalClass div.ecxmsochpdefault11 { font-size:12.0pt;
font-family:"Calibri","sans-serif";
color:black;
}

.ExternalClass span.ecxmsohyperlink {
}

.ExternalClass span.ecxmsohyperlinkfollowed {
}

.ExternalClass span.ecxmsohyperlink1 {
}

.ExternalClass span.ecxmsohyperlinkfollowed1 {
}

.ExternalClass span.ecxemailstyle171 {
}

.ExternalClass span.ecxtextedebullescar1 {
}

.ExternalClass span.ecxemailstyle32 {
}

.ExternalClass span.ecxtextedebullescar {
}

.ExternalClass span.ecxmsohyperlink2 {
color:blue;
text-decoration:underline;
}

.ExternalClass span.ecxmsohyperlinkfollowed2 {
color:purple;
text-decoration:underline;
}

.ExternalClass span.ecxmsohyperlink11 {
color:blue;
text-decoration:underline;
}

.ExternalClass span.ecxmsohyperlinkfollowed11 {
color:purple;
text-decoration:underline;
}

.ExternalClass span.ecxemailstyle1711 {
font-family:"Calibri","sans-serif";
color:windowtext;
}

.ExternalClass span.ecxtextedebullescar11 {
font-family:"Tahoma","sans-serif";
}

.ExternalClass span.ecxemailstyle321 {
font-family:"Calibri","sans-serif";
color:#1F497D;
}

.ExternalClass span.ecxtextedebullescar2 {
font-family:"Tahoma","sans-serif";
}

.ExternalClass span.ecxEmailStyle50 {
font-family:"Calibri","sans-serif";
color:#1F497D;
}

.ExternalClass span.ecxEmailStyle51 {
font-family:"Calibri","sans-serif";
color:#1F497D;
}

.ExternalClass .ecxMsoChpDefault {
font-size:10.0pt;
}

.ExternalClass div.ecxWordSection1 {
}

--></style></div> 		 	   		  </div></body>
</html>



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic