Click here to Skip to main content
15,890,282 members
Home / Discussions / Java
   

Java

 
Questionveda web services Pin
Member 109188101-Jul-14 23:51
Member 109188101-Jul-14 23:51 
AnswerRe: veda web services Pin
Richard MacCutchan2-Jul-14 5:45
mveRichard MacCutchan2-Jul-14 5:45 
QuestionNeed source code for FRECCA algorithm. Pin
Member 83982281-Jul-14 21:52
Member 83982281-Jul-14 21:52 
QuestionRe: Need source code for FRECCA algorithm. Pin
Richard MacCutchan2-Jul-14 5:44
mveRichard MacCutchan2-Jul-14 5:44 
AnswerRe: Need source code for FRECCA algorithm. Pin
Member 83982282-Jul-14 6:57
Member 83982282-Jul-14 6:57 
Questionhow to define multiple serivice names in single wsdl in jax-ws ri implementation? is it possible? Pin
Member 1091573730-Jun-14 20:49
Member 1091573730-Jun-14 20:49 
AnswerRe: how to define multiple serivice names in single wsdl in jax-ws ri implementation? is it possible? Pin
rajeev12413-Jul-14 20:32
professionalrajeev12413-Jul-14 20:32 
QuestionHow to determine the width for multiple Lines of Text Using TextLayout and LineBreakMeasurer Pin
f2624-Jun-14 22:26
f2624-Jun-14 22:26 
I am writing to a file coordinates of texts using PathIteratorsaved as SVG format i defined the Font attributes using AttributedString and TextLayout. It is saving to the file and working properly, but it is just writing as a single line of text where is my target is multiple lines of text, i began using LineBreakMeasurer, but some text is removed plus i got single line of text only, where i face the problem that , How to determine the width to get multiple lines of text ? i tried to figure out from this example where is drawing multiple lines of text but i am using getBounds().getWidth() of TextLayout object the code i tried
Java
public class writeFontPathsToFileAsSVG {

         private  AttributedString text;
         private LineBreakMeasurer lineMeasurer;
         private int paragraphStart;
         private int paragraphEnd;
         private static final Hashtable map = new Hashtable();

    static {
        map.put(TextAttribute.FAMILY, "Arial");
        map.put(TextAttribute.SIZE, new Float(25.0));
    }  

    public writeFontPathsToFileAsSVG(){
        this.text = new AttributedString( "Salam Marhaba Ahlan Wa Sahlan "
                                            +"Salam Marhaba Ahlan Wa Sahlan"
                                            +"Salam Marhaba Ahlan Wa Sahlan",map);
    }

        public static void main(String[] args) throws Exception {
            writeFontPathsToFileAsSVG getFiel=new writeFontPathsToFileAsSVG();
            getFiel.getFontFileAsSVG(new FileWriter(C:\\saveTo.svg"));
      }

        Shape shape ;
        public void getFontFileAsSVG(FileWriter f) throws IOException{
            AttributedCharacterIterator attributedChar = text.getIterator() ;
            paragraphStart = attributedChar.getBeginIndex();
            paragraphEnd = attributedChar.getEndIndex();
            FontRenderContext fontRenderContext = new FontRenderContext(null, false, false);
            lineMeasurer = new LineBreakMeasurer(attributedChar,fontRenderContext);
           TextLayout layout = new TextLayout(text.getIterator(), fontRenderContext);
                //To get the Text fits the art-board
              double w=layout.getBounds().getWidth(); 
              double h=layout.getBounds().getHeight();
              double x=layout.getBounds().getX();
              double y=layout.getBounds().getY();
                 //To get a specific width to go to next line
                float formatWidth = (float) w + 250 ;
                float drawPosY = 0;
                lineMeasurer.setPosition(paragraphEnd);
                float drawPosX = 0;
                while (lineMeasurer.getPosition() < paragraphEnd) {
                   layout = lineMeasurer.nextLayout((float) w);
                  y += layout.getAscent();
                  if (layout.isLeftToRight()) {
                    x = 0;
                  } else {
                    x = w - layout.getAdvance();
                  }
                  y += layout.getDescent() + layout.getLeading();
                }
            shape = layout.getOutline(null);
            PathIterator pi = shape.getPathIterator(null);
            PrintWriter out = new PrintWriter(f);
                out.println("<?xml version=\"1.0\" standalone=\"no\"?>\n"
                        + "<svg xmlns=\"http://www.w3.org/2000/svg\" preserveAspectRatio=\"none\" " +"\n" 
                        + " width=\""+w+"\" height=\""+h+"\""
                        + " viewBox=\""+x+" "+y+" "+w+" "+h+ "\" >" );
                out.println("<path d=\"");
                String temp=new String();
                while (pi.isDone() == false) {
                     temp+=getCoordinates(pi);
                    pi.next();
                  }
                      out.println(temp);
                    out.format("\"/>"+"\n"+"</svg>");
                     out.close();
                     f.close();
                     System.out.println("Data added to the File successfully");
        }

        public String getCoordinates(PathIterator pi) {
          String temp=new String();
        double[] coor = new double[6];
        int type = pi.currentSegment(coor);
        switch (type) {
        case PathIterator.SEG_MOVETO:
          temp="\n\n"+" M " + coor[0] + ", " + coor[1];
          break;
        case PathIterator.SEG_LINETO:
          temp+="\n\n"+" L " + coor[0] + ", " + coor[1];
          break;
        case PathIterator.SEG_QUADTO:
          temp+=" Q " + coor[0] + ", " + coor[1] + " "
              + coor[2] + ", " + coor[3];
          break;
        case PathIterator.SEG_CUBICTO:
          temp+=" C " + coor[0] + ", " + coor[1] + " "
              + coor[2] + ", " + coor[3] + " " + coor[4] + ", " + coor[5];
          break;
        case PathIterator.SEG_CLOSE:
          temp+=" Z";
          break;
        default:
          break;
        }
        return temp;
      }
    }

Questionretrieving past records in inventory management system Pin
krishna_m23-Jun-14 2:15
professionalkrishna_m23-Jun-14 2:15 
SuggestionRe: retrieving past records in inventory management system Pin
Richard MacCutchan25-Jun-14 15:12
mveRichard MacCutchan25-Jun-14 15:12 
QuestionNeed help on JAVA survey Pin
mohammed shihab19-Jun-14 13:42
mohammed shihab19-Jun-14 13:42 
AnswerRe: Need help on JAVA survey Pin
Richard MacCutchan19-Jun-14 22:57
mveRichard MacCutchan19-Jun-14 22:57 
QuestionRe: Need help on JAVA survey Pin
mohammed shihab20-Jun-14 0:44
mohammed shihab20-Jun-14 0:44 
AnswerRe: Need help on JAVA survey Pin
Richard MacCutchan20-Jun-14 1:25
mveRichard MacCutchan20-Jun-14 1:25 
GeneralRe: Need help on JAVA survey Pin
mohammed shihab20-Jun-14 4:40
mohammed shihab20-Jun-14 4:40 
Questionpeer to peer Pin
Member 1089097217-Jun-14 13:38
Member 1089097217-Jun-14 13:38 
SuggestionRe: peer to peer Pin
Richard MacCutchan17-Jun-14 22:16
mveRichard MacCutchan17-Jun-14 22:16 
AnswerRe: peer to peer Pin
jschell18-Jun-14 11:19
jschell18-Jun-14 11:19 
QuestionJava GUI programming Pin
Francesco Fraccaroli16-Jun-14 1:59
Francesco Fraccaroli16-Jun-14 1:59 
AnswerRe: Java GUI programming Pin
Richard MacCutchan16-Jun-14 3:34
mveRichard MacCutchan16-Jun-14 3:34 
GeneralRe: Java GUI programming Pin
Francesco Fraccaroli16-Jun-14 22:49
Francesco Fraccaroli16-Jun-14 22:49 
GeneralRe: Java GUI programming Pin
Richard MacCutchan16-Jun-14 23:05
mveRichard MacCutchan16-Jun-14 23:05 
QuestionOpening pdf files using Java Pin
Member 1088342114-Jun-14 4:11
Member 1088342114-Jun-14 4:11 
AnswerRe: Opening pdf files using Java Pin
Peter Leow14-Jun-14 4:53
professionalPeter Leow14-Jun-14 4:53 
GeneralRe: Opening pdf files using Java Pin
Member 1089404118-Jun-14 22:50
Member 1089404118-Jun-14 22:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.