Font.subStringWidth returns 0 inadequately
i'm developing with MIDP 1.0 for a # Nokia 7210 (serie 40).
the function Font.substringWidth(string, off, len) return 0 in some case when len !=0 and off is in the good range.
how come ?
resolved
Similar Messages
-
How do I change the font and return address when mass printing envelops from contacts?
I am trying to print envelopes for holiday cards from my contacts book. I want to change the return address name ( from Jane Doe to the Doe Family) in a nice font that is appropriate for the holiday season rather than the board room. It is certainly not in the print details menu.
You can select to zoom the full page or only the text: View > Zoom > Zoom Text Only<br />
Firefox 3 can remember the zoom level site specific.
See:
* http://kb.mozillazine.org/Zoom_text_of_web_pages
* http://kb.mozillazine.org/browser.zoom.siteSpecific
* http://kb.mozillazine.org/browser.zoom.full -
To change the font of a selected row in a Jtable
Hello,
Is it possible to change the font of a selected row in a jtable?
i.e. if all the table is set to a bold font, how would you change the font of the row selected to a normal (not bold) font?
thank you.String will be left justified
Integer will be right justified
Date will be a simple date without the time.
As it will with this renderer.Only if your custom renderer duplicates the code
found in each of the above renderers. This is a waste
of time to duplicate code. The idea is to reuse code
not duplicate and debug again.
No, no, no there will be NO duplicated code.
A single renderer class can handle all types ofdata.
Sure you can fit a square peg into a round hole if
you work hard enough. Why does the JDK come with
separate renderers for Date, Integer, Double, Icon,
Boolean? So that, by default the rendering for common classes is done correctly.
Because its a better design then having code
with a bunch of "instanceof" checks and nested
if...else code.This is only required for customization BEYOND what the default renderers provide
>
And you would only have to use instanceof checkswhen you required custom
rendering for a particular classAgreed, but as soon as you do require custom
renderering you need to customize your renderer.
which you would also have to do with theprepareRenderer calls too
Not true. The code is the same whether you treat
every cell as a String or whether you use a custom
renderer for every cell. Here is the code to make the
text of the selected line(s) bold:
public Component prepareRenderer(TableCellRenderer
renderer, int row, int column)
Component c = super.prepareRenderer(renderer, row,
, column);
if (isRowSelected(row))
c.setFont( c.getFont().deriveFont(Font.BOLD) );
return c;
}It will work for any renderer used by the table since
the prepareRenderer(...) method returns a Component.
There is no need to do any kind of "instanceof"
checking. It doesn't matter whether the cell is
renderered with the "Object" renderer or the
"Integer" renderer.
If the user wants to treat all columns as Strings or
treat individual columns as String, Integer, Data...,
then they only need to override the getColumnClass()
method. There is no change to the prepareRenderer()
code.
Have you actually tried the code to see how simple it
is?
I've posted my code. Why don't you post your solution
that will allow the user to bold the text of a Date,
Integer, and String data in separate column and then
let the poster decide.Well, I don't see a compilable, runnable demo anywhere in this thread. So here's one
import javax.swing.*;
import javax.swing.table.*;
import java.awt.*;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.Vector;
public class TableRendererDemo extends JFrame{
String[] headers = {"String","Integer","Float","Boolean","Date"};
private JTable table;
public TableRendererDemo() {
buildGUI();
private void buildGUI() {
JPanel mainPanel = (JPanel) getContentPane();
mainPanel.setLayout(new BorderLayout());
Vector headerVector = new Vector(Arrays.asList(headers));
Vector data = createDataVector();
DefaultTableModel tableModel = new DefaultTableModel(data, headerVector){
public Class getColumnClass(int columnIndex) {
return getValueAt(0,columnIndex).getClass();
table = new JTable(tableModel);
// table.setDefaultRenderer(Object.class, new MyTableCellRenderer());
table.setDefaultRenderer(String.class, new MyTableCellRenderer());
table.setDefaultRenderer(Integer.class, new MyTableCellRenderer());
table.setDefaultRenderer(Float.class, new MyTableCellRenderer());
table.setDefaultRenderer(Date.class, new MyTableCellRenderer());
JScrollPane jsp = new JScrollPane(table);
mainPanel.add(jsp, BorderLayout.CENTER);
pack();
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
private Vector createDataVector(){
Vector dataVector = new Vector();
for ( int i = 0 ; i < 10; i++){
Vector rowVector = new Vector();
rowVector.add(new String("String "+i));
rowVector.add(new Integer(i));
rowVector.add(new Float(1.23));
rowVector.add( (i % 2 == 0 ? Boolean.TRUE : Boolean.FALSE));
rowVector.add(new Date());
dataVector.add(rowVector);
return dataVector;
public static void main(String[] args) {
Runnable runnable = new Runnable() {
public void run() {
TableRendererDemo tableRendererDemo = new TableRendererDemo();
tableRendererDemo.setVisible(true);
SwingUtilities.invokeLater(runnable);
class MyTableCellRenderer extends DefaultTableCellRenderer{
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
if ( isSelected){
setFont(getFont().deriveFont(Font.BOLD));
else{
setFont(getFont().deriveFont(Font.PLAIN));
if ( value instanceof Date){
SimpleDateFormat formatter =(SimpleDateFormat) SimpleDateFormat.getDateInstance(DateFormat.MEDIUM);
setText(formatter.format((Date)value));
if(value instanceof Number){
setText(((Number)value).toString());
return this;
}Hardly a "bunch of instanceof or nested loops. I only used the Date instanceof to allow date format to be specified/ modified. If it was left out the Date column would be "18 Apr 2005" ( DateFormat.MEDIUM, which is default).
Cheers
DB -
Font selection view control in Web Gallery
LR4.1 RC2
I wanted to be able to change the font type from the UI panel using a font select popup.
This control really only seems to exist in the inbuilt edit modes (eg: id plate and watermark) so I have tried a workround which seems to work OK so far. Maybe it will help someone else out working with webengines.
Mac/OSX only at this stage - good source file in Windows may be font.inf but would require a bit of parsing or get a folder listing somehow.
Basically I read in the contents of the fonts.list file - which appears in the OSX fonts folders - and then massage the contents to get a raw list of the fonts.
This raw list is then read into a lua table and consumed by the UI popup control.
Should there be an obvious way that I haven't seen then just give me time to find a banana to eat ... anyway here goes -
Changing the font type for the cell index numbers.
Grid cells use cellIndex to give the photo number and in my webengine the css class is .itemNumber
Data Model references - Note: %s is important for select to work - if %q is used select will work but font won't change ( %q adds quotes to the string ).
["appearance.itemNumber.font"] = function() return string.format( "%s", nonCSS.itemNumberFontSize .. "px " .. nonCSS.itemNumber.font ) end,
["nonCSS.itemNumberFontSize"] = 60,
["nonCSS.itemNumber.font"] = "inherit",
fontlistpath = LrPathUtils.child('/Library/Fonts','') -- OSX Default fonts
Code just prior to LR UI Views -
deffonts = templatepath .. "/pgresources/" .. 'osxdeffont.txt' -- templatepath is the root path of the webengine - this is the tweaked OSX fonts.list file
function readFontsFile( deffonts )
local fileLines = io.lines( deffonts )
ff3 = {}
for line in io.lines(deffonts) do
Filter lines here ...
eg: -
line = string.sub(line, 17) -- remove 1st 16 chrs (/Library/Fonts//Osaka.ttf)
line = string.gsub(line, "(.ttf)", "")
local kline = line
local vline = line
table.insert(ff3, { title = kline ,value = vline })
end
end
LR UI View for font select -
f:popup_row {
title = "Font family :",
bindingValue = "nonCSS.itemNumber.font",
items = ff3,
bindingEnabled = "appearance.itemNumber.display", -- control should be disabled if display checkbox false
tooltip = "Choose wisely Dave!",
Using this method is not perfect but gives a good selection of fonts - I found that to improve the success rate the default font file was copied into the webengine
resources folder and tweaked. eg: the default file gives Brush Script.ttf but I needed Brush Script MT to work, similarly with Arial Rounded Bold which needed changing
to Arial Rounded MT Bold
Basically to find the correct descriptions you could do far worse than to use the ones in the edit selections used by the ID Plate/watermarking features.
Well there you go ...
As an aside I did try an undocumented control which on double click popped up a system font selection dialog (the whole nine yards) but couldn't get it to link to the css class so I didn't persist - not a good idea to use undocumented controls but can be fun to play with.
f:font_picker {
font = "Copperplate", -- showed font as highlighted when picker opened.
width = 80,
value = "Arial", -- appeared on control (title ??) - this value only changed according to the font selected after double-clicking on another hidden control (f:image_well)
bindingValue = "nonCSS.itemNumber.font", -- linkage didn't work
Again, unless I missed it, it would be really good to have the font_picker documented and working for the web gallery views. Fonts seem to be a murky area -
probably accounts for the hassles I am getting with the watermarking feature as well.
Update :
If the font doesn't work try using the PostScript name as a value which invariably works.
eg: Handwriting - Dakota will not work but Handwriting-Dakota will.
Arial Bold will not work but Arial-BoldMT will.I don't think that there is any option to set the default view in the web album. If anyone has found an option to do this, then I will like to know as well.
Quite a lot of the settings in web album seams to be "hard coded" and only a few settings are available for users to control.
Karsten -
Font problem in Applet (Urgent)
Hi all,
i m using a font to render the japneese character in an applet.and i m doing some text manipulations with that.and the font is TrueType font.Now if the client has that font file it renders with the japneese text.it is fine.but when the client system doesnt have the font file installed it still gives the font object(i think it is default font object supported by the JRE) which is not of TrueType.so my text manipulations behaving wrongly which i dont want to happen.If i able to find the font object returned is of TrueType or not then i can resolve this issue.
So anybody can help me,is there any method (or anyother way to achieve it) to find whether the created font object is of TrueType or not.i have seen the Font class and its related api ,i couldnt found such method.SO can anyone help in this regard.it will be greatfull.
thanx
prakashHowever, if you upload the font onto your server, there is a way
that you can use that font file, rather than relying on your user's fonts. but can any one tell me about the way to use the font file from the server , rather than relaying on the user's fonts??
Rana. -
Font changed in photo captions
hi
excuse me if this has been covered ad nauseum, but you'll probably sense pretty quickly i'm new to this.
i was adding captions to a batch of photos, and i copied and pasted a bunch of ids from a web page.
iphoto seems to have adopted the font from the web-sourced ids — a 12 or 14-point black face font — as its default setting. every new picture not has that font in the 'description' box.
how can i get the old nice, white face back?
thanksI've not been able to reproduce your problem. Backup and launch iPhoto with the Command+Option keys depressed to rebuild the library. Select the last three options.
Click to view full size
Launch iPhoto and check the Info/description field again to see if the font has returned to the default Helvetica Neue.
OT -
Extend VTextField to dynamically underline font
Rather than use the Hyperlink bean (because it's pretty slow to load), I have taken the concepts in the ModCursor demo and built a simple class that extends VTextField, providing for the traditional webpage look of a hyperlink: the hand cursor, rollover bolding, etc...
I have left the font coloring and underlining to the text item properties; set when the developer builds the form.
Problem with leaving the underlining in the text item properties is that if the item is part of a multi-record block and the records don't fill the space allocated for them (the block can show up to 10, but perhaps only 5 records are loaded), then the "empty" records have little tiny dots where the underline of the empty text fields are.
I thought it would be simple to just add the underline in the implementation class, but it's not proving to be so simple. I've tried adding a TextAttribute whenever the font is set, but that doesn't "take".
Here's my code, anyone have any ideas on how to add the underline in the PJC?
I ripped out all the comments to reduce the size; I can comment about any part of it as necessary.
import java.awt.Font;
import java.awt.font.*;
import java.text.*;
import java.util.*;
import oracle.forms.ui.VTextField;
import oracle.forms.properties.ID;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.Cursor;
public class Hotlink
extends VTextField
private Cursor stdCursor;
private int stdStyle;
public Hotlink()
super();
try
jbInit();
catch (Exception e)
e.printStackTrace();
private void jbInit() throws Exception
stdCursor = this.getCursor();
this.addMouseListener(new MouseAdapter()
public void mouseEntered(MouseEvent me)
if(getTextLength() > 0)
stdStyle = getFont().getStyle();
setFont(getFont().deriveFont(Font.BOLD));
setCursor(new Cursor(Cursor.HAND_CURSOR));
public void mouseExited(MouseEvent me)
if(getTextLength() > 0)
setFont(getFont().deriveFont(stdStyle));
setCursor(stdCursor);
public void setFont(Font font)
if(this.getTextLength() > 0)
Map attrs = font.getAttributes();
attrs.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
font = new Font(attrs);
super.setFont(font);
}Alright, no replies, but I figured out one way to do it.
It's kinda cheesy, but it works alright.
I saw that the Hyperlink bean actually drew a line to underline the text, so that's what I did.
I overloaded the paint method, and only draw a line if there is text in the item.
Actually, I only apply the moseover effects if there's text, too.
Anyway, for those seeking the same answers as I was, here's my code, stripped of comments because of size considerations:
import java.awt.Graphics;
import java.awt.FontMetrics;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.FontMetrics;
import oracle.forms.ui.VTextField;
import oracle.forms.properties.ID;
import oracle.forms.handler.IHandler;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.Cursor;
public class BoldLink
extends VTextField
private Cursor stdCursor;
private Font stdFont;
public BoldLink()
super();
public void init(IHandler h)
super.init(h);
stdCursor = this.getCursor();
this.addMouseListener(new MouseAdapter()
public void mouseEntered(MouseEvent me)
if(getTextLength() > 0)
setFont(stdFont.deriveFont(Font.BOLD));
setCursor(new Cursor(Cursor.HAND_CURSOR));
public void mouseExited(MouseEvent me)
if(getTextLength() > 0)
setFont(stdFont);
setCursor(stdCursor);
public void paint(Graphics g)
super.paint(g);
if (this.getTextLength() > 0)
FontMetrics metrics = getFontMetrics(getFont());
int strWidth = metrics.stringWidth(getText());
int yoffset = (int)(metrics.getHeight() * 0.95);
g.drawLine(0, yoffset, strWidth, yoffset);
public boolean setProperty(ID pid, Object value)
if(pid.getName().equals("FONT")) this.stdFont = (Font)value;
return super.setProperty(pid, value);
} -
How to add icon to JList? But I need to add icon in spacial way (so common metho of changing of cellRenderer don`t help) I need to add icons at two places, at the beginging of word and at the end of word (aligned to right border).
Also how to change font of one of elements, for example I need to add red bold text.here is an example hope that it helps you...
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.event.*;
*This is a class that can genernate the font dialog and returns the font
*@author David Rubin
*@version 1.2 15 july 2005
public class FontDialog extends JDialog
private static final String FONT_NAMES [] = GraphicsEnvironment.getLocalGraphicsEnvironment ().getAvailableFontFamilyNames ();
private Font returnFont = null;
private DefaultListModel fontModel = new DefaultListModel ();
private JList fontNames;
private SpinnerNumberModel spinModel = new SpinnerNumberModel (12, 1, 150, 1);
private JSpinner fontSizes = new JSpinner (spinModel);
private JCheckBox bold = new JCheckBox ("Bold");
private JCheckBox italic = new JCheckBox ("Italic");
private JTextField canvas = new JTextField ("aB cb gG xX yY zZ the old man");
private int prop = 0;
public FontDialog (JFrame parent)
super (parent, "Font Dialog", true);
((JSpinner.DefaultEditor) fontSizes.getEditor ()).getTextField ()
.addKeyListener (new KeyAdapter ()
public void keyTyped (KeyEvent e)
if (!Character.isDigit (e.getKeyChar ()))
e.consume ();
fontSizes.addChangeListener (new ChangeListener ()
public void stateChanged (ChangeEvent e)
canvas.setFont (new Font ((String) fontNames.getSelectedValue (), prop, ((Integer) fontSizes.getValue ()).intValue ()));
fontNames = new JList (fontModel);
fontNames.addListSelectionListener (new ListSelectionListener ()
public void valueChanged (ListSelectionEvent e)
canvas.setFont (new Font ((String) fontNames.getSelectedValue (), prop, ((Integer) fontSizes.getValue ()).intValue ()));
for (int i = 0 ; i < FONT_NAMES.length ; i++)
fontModel.addElement (FONT_NAMES );
fontNames.setCellRenderer (new MyCellRenderer ());
JScrollPane scrolPane = new JScrollPane (fontNames);
this.getContentPane ().add (scrolPane, BorderLayout.WEST);
ActionListener act = new ActionListener ()
public void actionPerformed (ActionEvent e)
if (e.getSource () == bold)
prop ^= Font.BOLD;
else if (e.getSource () == italic)
prop ^= Font.ITALIC;
canvas.setFont (new Font ((String) fontNames.getSelectedValue (), prop, ((Integer) fontSizes.getValue ()).intValue ()));
ActionListener actList = new ActionListener ()
public void actionPerformed (ActionEvent e)
Font t = canvas.getFont ();
String s;
if (t.isBold () && t.isItalic ())
s = "Font.BOLD|Font.ITALIC";
else if (t.isBold ())
s = "Font.BOLD";
else if (t.isItalic ())
s = "Font.ITALIC";
else
s = "Font.PLAIN";
System.out.println ("Font f=new Font(\"" + t.getFontName () + "\"," + s + "," + t.getSize () + ");");
JPanel pan = new JPanel ();
bold.addActionListener (act);
italic.addActionListener (act);
pan.add (bold);
pan.add (italic);
pan.add (fontSizes);
pan.setBorder (BorderFactory.createTitledBorder ("Options"));
JPanel pan1 = new JPanel ();
pan1.add (pan);
JButton but = new JButton ("Print Font ");
but.addActionListener (actList);
pan1.add (but);
canvas.setMinimumSize (new Dimension (50, 60));
canvas.setPreferredSize (new Dimension (50, 60));
this.getContentPane ().add (pan1, BorderLayout.EAST);
this.getContentPane ().add (canvas, BorderLayout.SOUTH);
pack ();
this.setVisible (true);
class MyCellRenderer extends JLabel implements ListCellRenderer
public Component getListCellRendererComponent (JList list, Object value,
int index, boolean isSelected, boolean cellHasFocus)
String s = value.toString ();
setText (s);
if (isSelected)
this.setBackground (list.getSelectionBackground ());
this.setForeground (list.getSelectionForeground ());
else
this.setBackground (list.getBackground ());
this.setForeground (list.getForeground ());
this.setEnabled (list.isEnabled ());
this.setFont (new Font (s, Font.PLAIN, 13));
setOpaque (true);
return this;
public Font getFont ()
return canvas.getFont ();
public static void main (String [] args)
FontDialog fontdialog = new FontDialog (null); -
I have a question about unicode mixups. I have a lot of old files with old fonts. If I need to upgrade some file, sometimes I need to change a font. Now some fonts will get you the problem that the unicode of the glyphs is not recognised or mixed up. Like when I have the word 'test' in Garamond Expert I want to change that to 'test' in Caslon Expert. It will give me '____'. If I look at the unicodes (easy copy/paste into the search/replace-enige) it does not say 'test' but something like <B776><B7765><B782><B771> (I am making these up) where <B776> stands for 't' etc. Now I do not want to replace each individual glyph nor want to miss out any. But a simple replacing of the font is not possible. Looking at the fonts coding in fontographer one can see that the 't' actually is at unicode <B776> but not at 't' where it should be. It worked in the past tough, so why not now! Strangely enough, if you type new text next to it (so in the same font) like 'test'test, the unicode says its '<B776><B7765><B782><B771>test' and the second part of the text will be converted like I want it. Also I find QuarkXPress has no problem with converting 'test' into Caslon Expert. (Original file was a Quark-document; used file was an update after I changed to InDesign couple of years ago)
Can you repeat your experiment and report the actual numbers you are seeing per character?
I don't think it has to do anything with Unicode. "Expert" fonts used to be notorious, because it assigned non-standard glyphs (characters) to standard codes -- to get an "ffl" ligature, you'd type a tilde. And most "Expert" fonts didn't comply to Adobe's "ExpertEncoding", so switching from one expert font to another wasn't guaranteed to be safe.
If a font is Unicode-compliant, this entire problem disappears, if only for the reason Unicode does *not* assign code points to expert symbols! But Opentype fonts do, and the Opentype code assures ligatures are applied automatically, and are translated back to their constituent characters when you apply another font which doesn't have the ligatures.
Modern fonts with all 'expert' options aren't called "Expert" anymore; look for Opentype Pro fonts. The Garamond Pro that came for free with your InDesign is a good example of a well-behaving, Unicode-compliant, automatically ligating and small-capping expert font.
function(){return A.apply(null,[this].concat($A(arguments)))}
Also I find QuarkXPress has no problem with converting 'test' into Caslon Expert.
I find it hard to believe QXP can translate from one "Expert" set in a font to another one with another encoding. Either the encoding is the same, and then you shouldn't have a problem in ID as well, or it's different. -
Adjust font size for notes?
is it possible to adjust the font size for the .txt file to be read in the 'notes' folder in 'my computer'. i have synced it to my ipod but becuase of is size and the way the info is portrayed the width is too narrow on ipod thus getting a 'spill' onto the next line. is there anyway to save it as it is in its original .txt file. thank you
AlanIn the text note include some html code. html (hypertext markup language) is what is used to display this web page.
You can Google "html font size" to learn more about it.
Create a text note.
The very first line of the text note should be
<font size =-1>
This will make the font 1 size smaller (it's a minus 1). Make it a + (plus) sign to make it larger.
Add the rest of your note.
The last line of your text note should be
</font>
to return everything to normal. -
hi is there a way to make each element in a JList to a different font. i am making a FontDialog and i would like each font name in the list to be the font of that font... like in MS word.
many thanks
DavidUse a customized ListCellRenderer. The following outlines one possible way of doing it:
// Use instances of this class as items in your list:
class FontListItem {
private Font font;
public FontListItem(Font font) {
this.font = font;
public String toString() {
return font.getName();
public Font getFont() {
return font;
// The ListCellRenderer for your JList:
class FontListRenderer extends DefaultListCellRenderer {
public Component getListCellRendererComponent(JList list,
Object value,
int index,
boolean isSelected,
boolean cellHasFocus) {
JLabel renderer = (JLabel)super.getListCellRendererComponent(
list, value, index, isSelected, cellHasFocus);
if( value instanceof FontListItem ) {
renderer.setFont( ((FontListItem)value).getFont() );
return renderer;
// Example of use:
FontListItem[] listItems = ...
JList list = new JList(listItems);
list.setCellRenderer(new FontListRenderer()); -
Creating non-default Fonts in JDK 1.1
Hello,
I need to create an applet that runs on 1.1 and has access to as many fonts as possible. Are there any ways that I can create other Fonts in JDK 1.1 except for the ones returned by Toolkit.getFontList()?
Thanks for your help.Unfortunately I don't - and if you're only building for Netscape pre 4.7 (from the sound of it) it won't help. However it is possible to write the code in such a way that it will fail gracefully and use the limited font set in the older Netscapes. When users are using the Sun VM, the old Font call picks up new fonts automatically.
You can do it by creating a helper class, that does all the work, and then only create an instance of the class once you know it's available. If it's not you just create a standard Font.
The class uses a function to return the Font as the parent doesn't know anything about FontX.
Calling code...
Font f;
if (bMicrosoftVM) //various ways to check for this
f = (new MSTextX("ZapfDingbats", 0, 12).GetFont());
else
f = new Font("ZapfDingbats", 0, 12);MSTextX class code...
import com.ms.awt.FontX;
import java.awt.Font;
public class MSTextX
public MSTextX(String fnt, int iStyle, int iSz)
try
m_fnt = new FontX(fnt, iStyle, iSz);
catch (Exception e) {;}
public Font GetFont()
return(m_fnt);
private Font
m_fnt;
} -
How to get the font name?
Hi i used the following code to find the font in illustrator cs3. but somewhere it exits the loop.
Please some one guide me.
AIArtHandle path=NULL,line;
short artType; AILayerHandle layer;
ADMItemRef ItemRef, FontListRef;
ADMListRef theItemList, FontList;
short ccount;int l, i;
AIErr error;
long count, FontCount;
char buf[250],fonttext[500];
short forfont;
AIFontStyle faceStyle;
AIFontKey fontKey;
int idx;
ADMEntryRef entry;
AIArtHandle textPath=NULL;
AIArtSet artSet;
long numLayers;
unsigned char title[150];
strcpy(ArtAssess.FontList,"\0");
error = sAILayer->CountLayers( &numLayers );
ItemRef = sADMDialog->GetItem(g->qcGuide , lstDifferences);
theItemList = sADMItem->GetList(ItemRef);
FontListRef = sADMDialog->GetItem(g->qcCheckDialog , lst_FontsTo);
FontList = sADMItem->GetList(FontListRef);
//for ( int q = 0; q< numLayers; q++ )
for (int q = numLayers-1;q >= 0; q-- )
error = sAILayer->GetNthLayer( q, &layer ); //extracting layer by layer
sprintf(buf,"%d",q);
MessageBox(NULL,buf,"q",0);
error = sAILayer->GetLayerTitle( layer, title );
if(strstr((char*)title,"SCAN")==0 && strstr((char*)title,"Bounding Box")==0)
error=sAIArtSet->NewArtSet(&artSet);
error=sAIArtSet->LayerArtSet (layer,artSet );
error=sAIArtSet->CountArtSet (artSet, &count );
FontCount = sADMList->NumberOfEntries( FontList );
int fontfound=0;
for(long j=0;j<count;j++)
error=sAIArtSet->IndexArtSet (artSet,j,&path );
error = sAIArt->GetArtType(path,&artType);
if (artType==kTextFrameArt)
//char buf[250];
AIPathStyle style;
AIPathStyleMap styleMap;
long index;
TextRangesRef selRef;
TextRangeRef textRange;
sAITextFrame->GetATETextRange(path,&textRange);
if ( error ) throw( error );
ITextRange itext( textRange );
ICharFeatures features=itext.GetUniqueCharFeatures();
bool isValid = false;
IFont textfont=features.GetFont(&isValid);
FontRef FntRef=textfont.GetRef();
sAIFont->FontKeyFromFont(FntRef,&fontKey);
MessageBox(NULL,"Fonts","2",0);
//sAIFont->GetFullFontName(fontKey,fonttext,forfont);
sAIFont->GetUserFontName(fontKey,fonttext,forfont);
//sAIFont->GetFullFontName(fontKey,fonttext,forfont);
sprintf(buf,"%s",(char*)fonttext);
MessageBox(NULL,buf,"Font Name",0);
bool Exists=CheckIfValueExists(ArtAssess.FontList,buf);
if (Exists==false)
strcat(ArtAssess.FontList,buf);
MessageBox(NULL,ArtAssess.FontList,"Fonts Used",0);
strcat(ArtAssess.FontList,";");
Exists=true;
MessageBox(NULL,"End font","",0);
return kNoErr;When dealing with text frames that contain multiple styles such as different fonts, kerning or point sizes etc. You need to split the text frame into text runs.
Using an ITextRunsIterator you can essentially split the text frame into a list of uniquely-styled text ranges.
AIArtSet artSet;
long artCount = 0L;
AIArtSpec spec = {kTextFrameArt,kArtHidden,0 };
sAIArtSet->NewArtSet(&artSet);
sAIArtSet->MatchingArtSet(&spec, 1, artSet)
sAIArtSet->CountArtSet(artSet,&artCount);
for (int index = 0; index < artCount ++index)
TextRangeRef trRef = NULL;
AIArtHandle art = NULL;
sAIArtSet->IndexArtSet(artSet,index,&art);
sAITextFrame->GetATETextRange(art,&trRef);
ATE::ITextRange textRange(trRef);
ATE::ITextRunsIterator textRunsIterator(textRange.GetTextRunsIterator());
while (textRunsIterator.IsNotDone())
// All of the text in this text range will have the same stylistic attributes
ATE::ITextRange range(textRunsIterator.Item());
// Get your character features etc here.
textRunsIterator.Next(); -
Why doesn't the line break change w/font size??
Hello,
I am trying to print out a simple paragraph (String object) to the printer. I am trying to get the text to wrap properly based on font size. I've search on the posts and can't find the answer.
It looks like the LineBreakMeasurer is only working with default font size? No matter what font I use in the graphics, the string always seems to break in the same column? Any ideas?
Here is a sample of the code I'm using.
Note - the actual printing (draw) is commented out.)
Thanks,
Jim
import java.awt.*;
import java.awt.print.*;
import java.text.*; //for AttributedCharacter
import java.awt.font.*; //for FontRenderContext
public class TestPrint implements Printable {
String textToPrint;
AttributedString as;
AttributedCharacterIterator aci;
//Font font = new Font("TimesRoman", Font.PLAIN, 16);
Font font = new Font("TimesRoman", Font.PLAIN, 8);
public TestPrint(String text) {
//text represents one paragraph of text
textToPrint = text;
as = new AttributedString(textToPrint);
aci = as.getIterator();
PrinterJob job = PrinterJob.getPrinterJob();
job.setPrintable(this);
if (job.printDialog() ) {
try {
job.print();
catch(Exception e) {
e.printStackTrace();
public static void main(String args[]) {
String testMsg = new String("TEST TEST TEST - The quick brown fox jumped over the lazy dogs back. " +
"How now brown cow? This will be a fairly long line so I can see how the text will wrap " +
"around on the printer when it prints. This is the end of the test string.\n");
TestPrint tp = new TestPrint(testMsg);
System.exit(0);
public int print(Graphics g, PageFormat pf, int idx) {
if (idx > 0)
return Printable.NO_SUCH_PAGE;
Graphics2D g2d = (Graphics2D)g;
Font fonta = g2d.getFont();
System.out.println("orig graphics font = " + fonta.getName() + " - " + fonta.getSize() );
g2d.setFont(font);
Font fontb = g2d.getFont();
System.out.println("new graphics font = " + fontb.getName() + " - " + fontb.getSize() );
float xo = (float)pf.getImageableX();
float yo = (float)pf.getImageableY();
int y = font.getSize();
FontRenderContext frc = g2d.getFontRenderContext();
//aci is the AttributedCharacterIterator
LineBreakMeasurer measurer = new LineBreakMeasurer(aci, frc);
float wrappingWidth = (float)pf.getImageableWidth();
System.out.println("wrappingWidth = " + wrappingWidth);
while (measurer.getPosition() < aci.getEndIndex() ) {
System.out.println("measurer position = " + measurer.getPosition() + " next offset = " +
measurer.nextOffset(wrappingWidth) );
String printLine = textToPrint.substring(measurer.getPosition(), measurer.nextOffset(wrappingWidth) );
measurer.setPosition(measurer.nextOffset(wrappingWidth));
System.out.println("printLine = " + printLine);
//g2d.drawString(printLine, xo, y + yo);
y += font.getSize();
//return Printable.PAGE_EXISTS;
return Printable.NO_SUCH_PAGE;
}Just for everyone elses reference, below is the modified code that works for me.
<pre>
import java.awt.*;
import java.awt.print.*;
import java.text.*; //for AttributedCharacter
import java.awt.font.*; //for FontRenderContext
import java.util.*;
import javax.swing.*;
public class PrintTest3 implements Printable {
String textToPrint;
AttributedString as;
AttributedCharacterIterator aci;
Font font = new Font("Arial", Font.PLAIN, 18);
//Font font = new Font("TimesRoman", Font.PLAIN, 8);
public PrintTest3(String text) {
//text represents one paragraph of text
textToPrint = text;
as = new AttributedString(textToPrint);
aci = as.getIterator();
PrinterJob job = PrinterJob.getPrinterJob();
job.setPrintable(this);
if (job.printDialog() ) {
try {
job.print();
catch(Exception e) {
e.printStackTrace();
public static void main(String args[]) {
String testMsg = new String("TEST TEST TEST - The quick brown fox jumped over the lazy dogs back. " +
"How now brown cow? This will be a fairly long line so I can see how the text will wrap " +
"around on the printer when it prints. This is the end of the test string.\n");
PrintTest3 tp = new PrintTest3(testMsg);
System.exit(0);
public int print(Graphics g, PageFormat pf, int idx) {
if (idx > 0){
return Printable.NO_SUCH_PAGE;
Graphics2D g2d = (Graphics2D)g;
g2d.setFont(font);
as.addAttribute(TextAttribute.FONT, font);
float xo = (float)pf.getImageableX();
float yo = (float)pf.getImageableY();
int y = font.getSize();
//aci is the AttributedCharacterIterator
LineBreakMeasurer measurer = new LineBreakMeasurer(aci, g2d.getFontRenderContext());
float wrappingWidth = (float)pf.getImageableWidth();
while (measurer.getPosition() < aci.getEndIndex() ) {
String printLine = textToPrint.substring(measurer.getPosition(), measurer.nextOffset(wrappingWidth) );
measurer.setPosition(measurer.nextOffset(wrappingWidth));
g2d.drawString(printLine, xo, y + yo);
y += font.getSize();
return Printable.PAGE_EXISTS;
</pre> -
[AS][CS5] Find and replace a missing font
I have an overly complex script that compares the document's fonts missing fonts to the system fonts and makes a best guess. It was written to handle conversion of Multi-ad Creator documents to InDesign. It has worked 100% of the time so far. It needs a LOT of cleaning up and tweaking to make effecient, but that is not the point of my question. Everyday I am sent an InDesign file I have to work with and everyday it will has a missing font. Arial (OTF).
I ran my script thinking it would replace it with Arial (TT). No problem...
Ran it... nothing.
When I use the find dialog in Indesign to search based on the applied font it works, the returned properties in AS contain:
return properties of find text preferences
font:"Arial (OTF)"
Ok, fine so I try...
set properties of find change text options to {case sensitive:false, whole word:false, include footnotes:false, include hidden layers:false, include locked layers for find:true, include locked stories for find:true, include master pages:true}
set applied font of find text preferences to "Arial (OTF)"
set applied character style of change text preferences to "Page&Header"
tell document 1
set myFoundItems to change text
end tell
Nothing.
This has pretty much worked on every other font I've tried, so what am I doing wrong here?All right, back at it....
I've run into even more fonts that it is an issue with. My basic thoughts on this are as follows: When bringing a document from Multi-ad Creator to InDesign the fonts are named in a way that InDesign does not recognize them. The thing is those fonts are really fonts that are on my system. It is simply a matter of rearranging the name of the applied font to match what InDesign would recognize. The thing is InDesign will allow me to use Find/Change to modify the fonts in the document.
Now the fonts I've run across that give me an issue are fonts that do not correspond to any font on my system. I do not have any TrueType fonts, this document I opened today did...
tell application "Adobe InDesign CS5.5"
set myDocument to active document
tell myDocument
set myPage to page 1
return properties of every font
end tell
end tell
{{font family:"Helvetica (TT)", PostScript name:"Helvetica-Bold", parent:document id 34 of application "Adobe InDesign CS5.5", index:1, name:"Helvetica (TT) Bold", object reference:font "Helvetica (TT) Bold" of document id 34 of application "Adobe InDesign CS5.5", status:not available}, {font family:"Helvetica (TT)", PostScript name:"Helvetica", parent:document id 34 of application "Adobe InDesign CS5.5", index:0, name:"Helvetica (TT) Regular", object reference:font "Helvetica (TT) Regular" of document id 34 of application "Adobe InDesign CS5.5", status:not available}, {font family:"Times (TT)", PostScript name:"Times-Bold", parent:document id 34 of application "Adobe InDesign CS5.5", index:3, name:"Times (TT) Bold", object reference:font "Times (TT) Bold" of document id 34 of application "Adobe InDesign CS5.5", status:not available}, {font family:"Times (TT)", PostScript name:"Times-Roman", parent:document id 34 of application "Adobe InDesign CS5.5", index:0, name:"Times (TT) Regular", object reference:font "Times (TT) Regular" of document id 34 of application "Adobe InDesign CS5.5", status:not available}}
Ok, so let me try this (commented out are the different ways I've tried):
tell application "Adobe InDesign CS5.5"
set myDocument to active document
tell myDocument
set myPage to page 1
--return properties of "Helvetica (TT)" --"Helvetica (TT) Bold"
return properties of font "Helvetica (TT)" -- "Helvetica (TT) Bold"
set myDocumentFonts to name of every font
end tell
end tell
Adobe InDesign CS5.5 got an error: Unable to retrieve the font's UID from its name.
I was able to get the properties of the font using:
return properties of every font whose PostScript name is "Helvetica-Bold"{font family:"Helvetica (TT)", PostScript name:"Helvetica-Bold", parent:document id 34 of application "Adobe InDesign CS5.5", index:1, name:"Helvetica (TT) Bold", object reference:font "Helvetica (TT) Bold" of document id 34 of application "Adobe InDesign CS5.5", status:not available}
Now I thought of trying the following:
tell application "Adobe InDesign CS5.5"
set find text preferences to nothing
set change text preferences to nothing
--Set the find options.
set properties of find change text options to {case sensitive:false, whole word:false, include footnotes:false, include hidden layers:false, include locked layers for find:true, include locked stories for find:true, include master pages:true}
set applied font of find text preferences to every font whose PostScript name is "Helvetica-Bold"
set applied font of change text preferences to "Helvetica"
tell document 1
set myFoundItems to change text
end tell
end tell
Now this does result in something, the find of the Find/Change dialog is looking for Helvetica + Bold. The only problem with that is it isn't looking for the TT font.
tell application "Adobe InDesign CS5.5"
set myDocument to active document
tell myDocument
set myfind to properties of every font whose PostScript name is "Helvetica-Bold"
end tell
set find text preferences to nothing
set change text preferences to nothing
--Set the find options.
set properties of find change text options to {case sensitive:false, whole word:false, include footnotes:false, include hidden layers:false, include locked layers for find:true, include locked stories for find:true, include master pages:true}
set applied font of find text preferences to name of myfind
set applied font of change text preferences to "Helvetica"
tell document 1
set myFoundItems to change text
end tell
end tell
And nothing happens.. other than it trying to search for Helvetica + Bold
I'll try some other ideas later when I have more time.
Maybe you are looking for
-
I buy AirPort Express Base Station. But it not work. I connect AirPort to my ethernet swith. And after 3 minits status lights flashing amber. I run AirPort Utility. He found Base station 000000. When I press "Continue" I recieve error -6742 (error sc
-
Hello, I am trying to finish a simple form for my company. This form has a few check boxes that I need to be required before submitted through echosign. Although the required field is checked and the boxes appear red when highlited, Echosign still al
-
Safari won't display page after loading
So the latest update of Safari is a few bricks short of a load... On many pages, I get a blank page after Safari finishes loading them in. I thought it was internet problems, but when I resize the window even slightly, the content appears. Obviously
-
Spry Accordion Panel Default State All Closed?
Is it possible to set a group of Spry accordion panels so that all are closed by default?
-
Uncaught Throwable in processSockets
when i used weblogic6.0 with sp1 for linux, i found an Exception like this: ####<Apr 27, 2001 12:34:30 PM EDT> <Error> <Posix Performance Pack> <webserver> <myserver> <ExecuteThread: '12' for queue: 'default' <> <> <000000> <Uncaught Throwable in pro